Go to: Synopsis. Return value. Related. Flags. Python examples.

Synopsis

connectDynamic( [objects] , [addScriptHandler=script], [collisions=string], [delete=boolean], [emitters=string], [fields=string], [removeScriptHandler=int])

Note: Strings representing object names and arguments must be separated by commas. This is not depicted in the synopsis.

connectDynamic is undoable, NOT queryable, and NOT editable.

Dynamic connection specifies that the force fields, emitters, or collisions of an object affect another dynamic object. The dynamic object that is connected to a field, emitter, or collision object is influenced by those fields, emitters and collision objects.

Connections are made to individual fields, emitters, collisions. So, if an object owns several fields, if the user wants some of the fields to affect an object, s/he can specify each field with a "-f" flag; but if the user wants to connect all the fields owned by an object, s/he can specify the object name with the "-f" flag. The same is true for emitters and collisions. Different connection types (i.e., for fields vs. emitters) between the same pair of objects are logically independent. In other words, an object can be influenced by another object's fields without being influenced by its emitters or collisions.

Each connected object must be a dynamic object. The object connected to can be any object that owns fields, emitters, etc.; it need not be dynamic. Objects that can own influences are particles, geometry objects (nurbs and polys) and lattices. You can specify either the shape name or the transform name of the object to be influenced.

Return value

string

Related

air, drag, emitter, gravity, newton, particle, radial

Flags

addScriptHandler, collisions, delete, emitters, fields, removeScriptHandler
Long name (short name) Argument types Properties
addScriptHandler(ash) script create
Registers a script that will be given a chance to handle calls to the dynamicConnect command. This flag allows other dynamics systems to override the behaviour of the connectDynamic command. You must pass a Python function as the argument for this flag, and that function must take the following keyword arguments: fields, emitters, collisionObjects and objects. The python function must return True if it has handled the call to connectDynamic. In the case that the script returns true, the connectDynamic command will not do anything as it assumes that the work was handled by the script. If all of the callbacks return false, the connectDynamic command will proceed as normal. The addScriptHandler flag may not be used with any other flags. When the flag is used, the command will return a numerical id that can be used to deregister the callback later (see the removeScriptHandler flag)
collisions(c) string createmultiuse
Connects each object to the collision models of the given object.
delete(d) boolean create
Deletes existing connections.
emitters(em) string createmultiuse
Connects each object to the emitters of the given object.
fields(f) string createmultiuse
Connects each object to the fields of the given object.
removeScriptHandler(rsh) int create
This flag is used to remove a callback that was previously registered with the addScriptHandler flag. The argument to this flag is the numerical id returned by dynamicConnect when the addScriptHandler flag was used. If this flag is called with an invalid id, then the command will do nothing. This flag may not be used with any other flag.

Flag can appear in Create mode of command Flag can appear in Edit mode of command
Flag can appear in Query mode of command Flag can have multiple arguments, passed either as a tuple or a list.

Python examples

import maya.cmds as cmds

cmds.connectDynamic( 'Book', c='Floor' )
# Connects the dynamic object "Book" to the collision model of the
# "Floor". This means that the book will collide with and bounce off of
# the floor.

cmds.connectDynamic( 'Moon', 'Spaceship', f='Moon' )
# Connects dynamic object "Spaceship" to the all fields and emitters
# owned by "Moon".

cmds.connectDynamic( 'Spaceship', f='newtonField1' )
# Connects dynamic object "Spaceship" to "newtonField1" owned by "Moon".

cmds.connectDynamic( 'Moon', f='newtonField1' )
# If the selection list consists of "Spaceship", connects dynamic object
# "Spaceship" to "newtonField1" and all emitters owned by "Moon".

cmds.connectDynamic( 'Spaceship', d=True, f='Moon' )
# Deletes the field connection between all the fields owned by "Moon" and
# "Spaceship". Note that the command establishing the connection need not
# be in the undo queue.

cmds.connectDynamic( 'Spaceship', d=True, f='newtonField1' )
# Deletes the field connection between "newtonField1" owned by "Moon" and
# "Spaceship".

def callback(fields, emitters, collisionObjects, objects):
	'''
	Test callback for intercepting calls to the connectDynamic command
	'''
    print 'Fields: %s' % str(fields)
    print 'Emitters: %s' % str(emitters)
    print 'Collision Objects: %s' % str(collisionObjects)
    print 'Objects: %s' % str(objects)

    # Let connectDynamic handle the connection
    return False

handler_id = cmds.connectDynamic(addScriptHandler=callback)
# Installs the above handler to intercept calls to the connectDynamic command

cmds.connectDynamic(removeScriptHandler=handler_id)
# Remove the above script handler