Getting access to a variable inside a class method from another class

Hello everyone.

I am currently writting an Auto-rig tool and I am facing some issues.

I splitted my code in differnet part (ex : Module_Arms, Module_Joints, Module_UI, etc…)

Then sometimes I need to have access to variables created in one module, and use these variables within another module.

Here is an example to make it clear :


import sys

import maya.cmds as mc

class Class_Joints:

    # Creating arm Jnts and the list of it
    def gen_arms_joints(self):

        # Create Joints
        self.shoulderJnt = mc.joint(absolute=True, position=[5,8,0], n='L_Shoulder_Jnt')
        self.elbowJnt = mc.joint(absolute=True, position=[10,8,-1.5], n='L_Elbow_Jnt')
        self.wristJnt = mc.joint(absolute=True, position=[15,8,0], n='L_Wrist_Jnt')
        self.handcupJnt = mc.joint(absolute=True, position=[18,8,0], n='L_HandCup_Jnt')

        # Create list
        self.armsJntList =, self.elbowJnt, self.wristJnt, self.handcupJnt)

Here is the Module_Joints that will create every Joints needed in the scene.

The goal here for example is to create controllers for each Arm_Joints.

Then , here is the seconde Module :


import sys

import Module_Joints

import maya.cmds as mc    

class Class_Fingers(object):
    # Initializing global variables
    def __init__(self):
        # Getting acces to the different modules
        self.Joints = Module_Joints.Class_Joints()       

    # Rig Method
    def arms_rig_method(self):
        # Creating FK Controlers
        for finger_joint in self.Joints.armsJntList:
  [1, 0, 0])

I import the modules needed (here Module_Joints), then I initialize it within the __init__(self) method.

I thought that writting something like self.Joints.armsJntList would do the trick. But no.

I do miss some knowledge on python class and I hope that you would be able to help me there.

Thank you for your time.

Cordially, Luca.

The only way for one object to know about another is for you to pass the data somehow. It’s the same idea as from the other thread. If you’re making a hand that attaches to the end of an arm, then you have to pass the arm object instance as an argument to a function on a hand instance.

For now, think about your classes like maya nodes in the node editor. (In reality, there’s a lot more to it, but this is a good starting point). The node can have properties and connections that you can set. Right now you’re asking how to get data from one node in another. The answer is to make plugs and connect the nodes. In this analogy the self.something variables are like maya node attributes and plugs.

If you were to make editor nodes for each part of your rig, think about all the steps you would have to go through to make them and the connections. You’d have to create all your nodes: For instance A COM, a spine, two legs, two arms, two hands, a neck. Then you’d have to make connections. Like the top of the spine to the neck and arms. Then the end of each arm to the corresponding hand. And same kind of process to the legs.

You will have to go through much the same steps in your auto rigger.

Okay, I was thinking about this kind of solution.
But it means that I would need to create a bunch of new method and new arguments, it would be a mess.

Or am I building my auto-rig wrong ?
Should I gen the bones within the Module_Arm for example ?

If I understand what you wrote, it means that for every joints or list of joints I need, I need to pass it as an argument of a method ?

Thank you for your respons by the way, always instructives !

Yes you would. Auto-riggers are complicated by nature. Heck, just my blendshape setup non-UI classes average around 12 methods apiece with as many as 50 in one of them.
But a mess? No. Big, but not a mess.

Yes… ish. You don’t need to pass the joints themselves, you just need to pass something that will let you figure out what the joints are.

In our autorigger, some objects are defined to be “connection nodes”, and that’s where other systems can get hooked onto that system. For instance, the arm would have connection node names like clavicle, shoulder, elbow, and wrist. Then, when you created a Hand, you would pass the Arm instance, along with a connection node name like "wrist". So that way the hand would know to connect to the wrist of that arm, but without having to know the exact name of the wrist object created by that arm.