Maya & Python Scripting / Maya / Python
Connect Two Objects using Python in Maya!
Written guide

Playing loads YouTube content. YouTube processes data after activation.
Watch on YouTubeIf the player is blocked or unavailable, use Watch on YouTube.
A connection line can make a rig relationship visible without becoming another control the animator must manipulate. This lesson creates a straight curve between two selected objects, attaches each endpoint through a cluster handle, and hides the helper handles while templating the line.
The recording demonstrates the result with locators and then boxes. It also promotes the creator’s own TD Superheroes curve tool, which includes a related utility; that promotion is distinct from the workflow explained here. The exact Maya release is unidentified, and the example does not establish correct behavior for arbitrary transformed parent hierarchies.
Require exactly two selected objects
At 00:00–05:02, the script captures the selection with mc.ls(sl=True) inside a function. Printing the result shows an empty list when nothing is selected and two names when the test locators are selected.
The function then checks len(sel) == 2. Although the narration briefly says “at least two,” the implemented condition accepts exactly two. That is the appropriate scope for a line with one endpoint assigned to each selected item.
The lesson tests an incorrect selection count as well as the valid case and prints a message when the requirement is not met. Perform those checks before indexing the list. An empty selection has no item zero, and an extra item has no defined role in this two-endpoint operation.
The guard checks count, not node type or naming suitability. Component selections, duplicate short names, namespaces, and more complex inputs are not validated in the demonstrated function.
Create a degree-one curve with two controlled endpoints
During 05:02–08:01, the function creates a degree-one curve with two points initially at the origin. Degree one gives the intended straight segment. At creation time the points overlap, so the useful line appears only after its endpoints are positioned.
The returned curve name is stored and printed. The lesson then incorporates both selected object names into a descriptive connection-line name, making its intended relationship easier to identify in the scene.
A missing parenthesis and an omitted point-argument keyword are corrected during this stage. These syntax errors are independent of the later deformation setup. Establish that one curve with two CVs exists before adding clusters and parenting.
The two CVs are addressed by index zero and one. Those indices come from the deliberately two-point construction; they should not be assumed to describe arbitrary curves created elsewhere.
Use cluster handles to control the curve’s CVs
At 08:01–11:00, the script selects the first CV and creates a cluster, then repeats the operation for the second CV. The cluster return value is inspected and shown to contain the deformer name and its handle name.
The handle is the transform that the following positioning and parenting operations need. In the demonstrated return list it is the second item, accessed with index one. Confusing that handle with the deformer node would send transform operations to the wrong part of the setup.
The source also catches an unquoted name being interpreted as a variable. A literal node name belongs in a string; a Python variable can hold a name once it has actually been assigned. That distinction is particularly important when the same word is used informally for both a scene node and a variable in the script.
Check that each cluster affects only its intended CV before attaching the handles to other objects. Two clusters that both affect the same endpoint would still exist in the Outliner, but would not describe the required two-ended relationship.
Position each handle before adding the live relationship
During 11:00–14:01, the function reads the selected objects’ tx, ty, and tz values and assigns them to the corresponding cluster handles. The first handle uses selection item zero, and the second uses item one. In the demonstrated unparented test setup, this places the curve endpoints at the selected objects.
These are translation-channel values, not a general world-space transform query. If a source object sits beneath a translated, rotated, or scaled parent, copying its local channels into a differently parented handle may not place the endpoint at the same world position. The article retains this limitation rather than repeating the closing claim that the script works with any scene object without qualification.
At this point the line is only positioned. Moving an endpoint object does not yet update the line, because copying values once has not created an ongoing relationship. The recording explicitly tests and observes that distinction before adding parenting.
Hide helpers, template the line, and parent the handles
At 14:01–17:28, both cluster handles have visibility turned off so they do not clutter the viewport. The curve is templated so it acts as a visual guide. Those display changes do not make it follow the objects; the live behavior comes from parenting each handle beneath its corresponding selected object.
The final test moves each locator independently and sees the line remain connected. The operation is then demonstrated with two boxes. The implementation therefore has a clear division of responsibility: CV clusters control the endpoints, initial channel values place them in this setup, and handle parenting supplies the subsequent follow behavior.
Verify both ends separately. Move the first source, then the second, and confirm that each affects the matching endpoint while the line remains a straight segment. Check that the hidden handles still exist under the intended parents and that the guide curve is not accidentally selected during normal interaction.
The lesson does not implement cleanup for repeated runs, robust world-space placement, or collision-safe naming. Those remain extensions if the utility is adapted beyond its simple recorded examples. The completed demonstration is a useful visual connection with an explicit, inspectable hierarchy.