save position before Freeze

Discussions concerning programming of SOFTIMAGE©
ionside
Posts: 16
Joined: 22 Dec 2011, 05:13
Location: Australia

save position before Freeze

Post by ionside » 16 Sep 2012, 03:48

I have two Nulls positioned on a mesh using an ICE compound which is in the mesh's ICE tree. I want to save the position of the Nulls and then freeze or delete the compound from the mesh, then envelope the mesh to one of the nulls.

The problem I'm having is even when I set a key on the position of the nulls, they pop back to zero after the mesh has been frozen or compound is deleted.

Manually it works fine, but not in script. Should I be getting and setting the null positions instead?

Code: Select all


# Freeze mesh and skin mesh to _Socket Null
def SkinMesh():
	meshName = si.GetValue(mesh.Name)
	firstNull = (str(meshName) + '_Socket')
	secondNull = (str(meshName) + '_Ball')
	
	si.SaveKey("%s.%s.kine.local.posx,%s.%s.kine.local.posy,%s.%s.kine.local.posz" % (meshName, firstNull, meshName, firstNull, meshName, firstNull))
	si.SaveKey("%s.%s.kine.local.posx,%s.%s.kine.local.posy,%s.%s.kine.local.posz" % (meshName, secondNull, meshName, secondNull, meshName, secondNull))
	si.DeleteObj("%s.%s.polymsh.MeshAttachers" % (meshName, meshName))
	
	si.ApplyFlexEnv('%s.%s;%s.%s' % (meshName, meshName, meshName, firstNull), '', 2)
Sorry for making you read my torturous code.

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 13:31
Skype: csaezmargotta
Location: Sydney, Australia

Re: save position before Freeze

Post by csaez » 16 Sep 2012, 18:12

Maybe forcing a refresh so the ICETree is evaluated at least once, try with a Refresh() command before the line where you delete/freeze the ICETree.

Cheers!

ionside
Posts: 16
Joined: 22 Dec 2011, 05:13
Location: Australia

Re: save position before Freeze

Post by ionside » 17 Sep 2012, 06:39

Thanks, csaez. Gave it a shot and although it's cool watching the commands play through in the viewport, the nulls still end up back at origin. Unless I've done that incorrectly.

User avatar
csaez
Posts: 253
Joined: 09 Jul 2012, 13:31
Skype: csaezmargotta
Location: Sydney, Australia

Re: save position before Freeze

Post by csaez » 17 Sep 2012, 07:47

Oops :(

Plan B: Maybe you can store the global transform in some variables and restore them later, something like this...

Code: Select all

# Freeze mesh and skin mesh to _Socket Null
def SkinMesh():
   meshName = si.GetValue(mesh.Name)
   firstNull = (str(meshName) + '_Socket')
   secondNull = (str(meshName) + '_Ball')

   TM1 = firstNull.Kinematics.Global.Transform
   TM2 = secondNull.Kinematics.Global.Transform

   si.DeleteObj("%s.%s.polymsh.MeshAttachers" % (meshName, meshName))
   
   firstNull.Kinematics.Global.Transform = TM1
   secondNull.Kinematics.Global.Transform = TM2
   
   si.ApplyFlexEnv('%s.%s;%s.%s' % (meshName, meshName, meshName, firstNull), '', 2)
Hope this make the trick :)
Cheers!

ionside
Posts: 16
Joined: 22 Dec 2011, 05:13
Location: Australia

Re: save position before Freeze

Post by ionside » 17 Sep 2012, 11:09

That worked, you're a genius!

I did it like this:

Code: Select all

# Freeze mesh and skin mesh to _Socket Null
def SkinMesh():
	meshName = si.GetValue(mesh.Name)
	firstNull = (str(meshName) + '_Socket')
	secondNull = (str(meshName) + '_Ball')
	
	TM1 = si.GetValue('%s.%s.kine.posz' % (meshName, firstNull))
	TM2 = si.GetValue('%s.%s.kine.posz' % (meshName, secondNull))
	
	si.FreezeObj("%s.%s.polymsh.MeshAttachers" % (meshName, meshName))

	si.SetValue('%s.%s.kine.posz' % (meshName, firstNull), TM1)
	si.SetValue('%s.%s.kine.posz' % (meshName, secondNull), TM2)
	
	si.ApplyFlexEnv('%s.%s;%s.%s' % (meshName, meshName, meshName, firstNull), '', 2)