Inside Sabertooth
Learn how Sabertooth uses 3ds Max to create 3D interactive projects, including HBO Go’s Game of Thrones interactive experience
  • 1/3
You are here: Forum Home / Autodesk® Softimage® / XSI SDK / toggle parents
  RSS 2.0 ATOM  

toggle parents
Rate this thread
 
30104
 
Permlink of this thread  
avatar
  • Total Posts: 70
  • Joined: 08 April 2008 10:04 AM

trying to script a way to toggle between 2 parents,

3 nulls, one is called child , the other 2 are parent a and parent b

i would like to toggle parent between the two,
so
===Jscript===

if(parent a) {
make parent b
}
if(parent b) {
make parent a
}
but this logic wont work because of th obvious.

can anyone point me in the right direction, how to set up a logic that toggles without contradicting itself



Replies: 0
avatar
  • Daysgone
  • Posted: 17 September 2008 07:01 AM

The easiest way to do this is make your child null, pose constrain it to both of the objects you want to use as parents(with cns compensation on) then just animate the constraints on and off. You can make it more complicated by finding the offset between the child and the new parent so it doesnt jump when switched.



Replies: 0
avatar

thats exactly what im trying to avoid. using pose constrains.

i got it t owork that way, but some implications forcing me to use simple parenting instead.



Replies: 0
avatar

Maybe a “switch” instead of a “if statment” would do.



Replies: 0
avatar

Can you use X3DObject.RemoveChild and X3DObject.AddChild ?



Replies: 0
avatar

hmm, the switch statement isnt going to work either it seems.

i can use the aad and remove child commands.
the idea is to create a simple toggle between the two parent.

if a is parent the make b the parent and vice versa.



Replies: 0
avatar

Here is a quick script that you can pull apart. make sure you make 3 objects, one named ParentOne, one named ParentTwo, and one named Child.

#imports
import win32com.client
from win32com
.client import constants
   
#globals
xsi win32com.client.Dispatch"XSI.Application" ).Application
log 
xsi.LogMessage
root 
xsi.ActiveSceneRoot

oParentOne 
xsi.dictionary.getobject("ParentOne")
oParentTwo xsi.dictionary.getobject("ParentTwo")
oChild xsi.dictionary.getobject("Child")

def toggleParent(oSource):
    if 
str(oSource.Parent) == str(oParentOne.Name):
        
oParentOne.RemoveChild(oChild)
        
log('Removed child from Parent One')
        
        
oParentTwo.AddChild(oChild)
        
log('Added child to ParentTwo')
        
    
elif str(oSource.Parent) == str(oParentTwo.Name):
        
oParentTwo.RemoveChild(oChild)
        
log('Removed child from Parent Two')
        
        
oParentOne.AddChild(oChild)
        
log('Added child to ParentOne')

toggleParent(oChild)

This works, but why do you have to str() the .Parent??? why can’t it be oSource.Parent == oParentOne.Name?



Replies: 0
avatar

thanks for the script Eric.

you dont have to str() parent name in js it seems.

var oRoot ActiveSceneRoot
var oChild oRoot.FindChild("child")
var 
par_a oRoot.FindChild("parent_a")
var 
par_b oRoot.FindChild("parent_b")

 function 
toggleParent(In_Child){
if (In_Child.Parent == par_a.Name ){
ParentObj
par_b  In_Child )

///do more code here

}
else
if(
In_Child.Parent == par_b.Name ){
ParentObj
(par_a In_Child)

//do more code here
}
/// add more parents if needed 


toggleParent
(oChild)


more code is where i calculate offsets if any…
allowing for switching parents on the fly.
probably a switch is better than if statements here. case a is parent, make b parent, case b, make c etc.. to N number of parents… or even better a custom prop that allows to choose what you want to make the parent.
----------------
but i think this simple parent switching is good enough for my character rig.  im just trying to make a dynamic parenting switch between only head controller and clavicle controller for hands.  i dont even need any offsets it seems… my keyframes work fine.



Replies: 0
avatar

Switching parents is a BAD design idea for rigging! Avoid at all cost!
For one you can’t key the switch. You can’t really make it dynamic because SCOPs try to lock easy access to hierarchy for a reason.

Do what Brian suggested instead and use constraints.



Replies: 0
avatar

ok. ill use pose constrains and calculate offsets .

thanks for advice.



Replies: 0