1

I' m fairly new to programming and lack the knowledge to solve the following task.

global proc assign() 
{
     select -hierarchy; //select all objects in hierarchy
     string $jointsHirearchy[]=`ls -sl`; //save objects to array
         for ($each in $jointsHirearchy) // check all objects in hierarchy
            {
                string $type =`nodeType $each`;// check the type of the object
                    if ($type != "joint")  // if it's not a joint...
                    {
                        select -tgl $each; // ...deselect it
                    }
                    if ($type == "joint")  // Problematic part: parent mesh to each joint and bind it's length to joint size
                    {
                        select $each;
                        polyCube;
                        ParentConstraint $each pCube1;
                    }   
                
            }
}

I need to assign a box to each joint so that the size of the box matches the length of the joint.

joanis
  • 10,635
  • 14
  • 30
  • 40
Andrii
  • 19
  • 2
  • 9

1 Answers1

1

enter image description hereYou can simplify your first part getting the joints by simply listing them directly, rather than toggling selections. This will give you just the joints under your original selection as an array:

string $joints[] = `ls -sl -dag -type "joint"`;

Next conceptually, I would create a master cube and a dimension node. Using the 2 locators of the dimension, you can have your cube position constrained to the first locator, and aim constrained to the second. Now, when the 2nd is moved, the dimension between the 2 will give you the scale value you need for your cube. Connecting this to the cube's scaleX would get the size and orientation where you need it. Looping through your joints, positioning the 2 locators on the joints in the hierarchy, then duplicating the cube will leave the cube you want behind as the master cube then goes to the next joint.

I started writing the MEL code to do all of this, but it's not there yet. But hopefully this is helpful.