Issues concerning rigging & Face Robot...
-
gustavoeb
- Moderator
- Posts: 587
- Joined: 21 Jul 2010, 00:33
- Skype: gustavoboehs
Post
by gustavoeb » 14 Jun 2013, 22:24
Hi guys, I'm trying to use python to access the object model and do something I thought should be simple. I want to get the global transform and use that in my static kine state, efectivelly resetting it.
I arrived to this code. It does not return an error, but is also not doing what I expected... any ideas of what am i doing wrong?
Code: Select all
xsi = Application
log = xsi.LogMessage
for i in range(0,xsi.Selection.Count):
obj = xsi.Selection(i)
obj_kine = obj.Kinematics.Global.GetTransform2(None)
obj_static_kine = obj.GetStaticKinematicState().GetTransform2(None)
m1 = XSIMath.CreateMatrix4()
obj_kine.GetMatrix4(m1)
obj_static_kine.SetMatrix4(m1)
-
xsisupport
- Posts: 713
- Joined: 09 Jun 2009, 11:02
- Location: Montreal Canada
-
Contact:
Post
by xsisupport » 14 Jun 2013, 22:36
Yes, I'm pretty sure the GetTransform page has the answer.
Warning: The returned SITransformation object contains a copy of the transformation values, so modifying its state will have no effect on the original object. To change the object's kinematic state you must set KinematicState.PutTransform2 with the modified SITransformation object, as shown in the example below.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs:
Arnold |
Softimage
-
gustavoeb
- Moderator
- Posts: 587
- Joined: 21 Jul 2010, 00:33
- Skype: gustavoboehs
Post
by gustavoeb » 15 Jun 2013, 02:22
Doh, that explains why nothing changes... ok changing my code here but I stumble upon yet another problem...
Do "static_kinematicstates" have this method (PutTransform2), or only "kinematicstates"?
Im getting this:
Code: Select all
# AttributeError: '<win32com.gen_py.Softimage|XSI Object Model Library v1.5.StaticKinematicState instance at 0x571553928>' object has no attribute 'PutTransform2'
when running this code:
Code: Select all
for i in range(0,xsi.Selection.Count):
obj = xsi.Selection(i)
obj_kine = obj.Kinematics
obj_statickine = obj.GetStaticKinematicState()
global_transform = obj_kine.Global.GetTransform2(None)
static_transform = obj_statickine.GetTransform2(None)
m1 = XSIMath.CreateMatrix4()
global_transform.GetMatrix4(m1)
static_transform.SetMatrix4(m1)
obj_statickine.PutTransform2(None, static_transform)
ps: thanks for helping out ;)
-
xsisupport
- Posts: 713
- Joined: 09 Jun 2009, 11:02
- Location: Montreal Canada
-
Contact:
Post
by xsisupport » 15 Jun 2013, 13:00
I don't see PutTransform for StaticKinematicState in the
docs, so you may need to resort to JScript (or VBScript) to set the transform.
// Steve Blair
// "You're not a runner, you're just a guy who runs" -- my wife
//
// My Blogs:
Arnold |
Softimage
-
gustavoeb
- Moderator
- Posts: 587
- Joined: 21 Jul 2010, 00:33
- Skype: gustavoboehs
Post
by gustavoeb » 15 Jun 2013, 15:21
Will try that. Thanks again Mr. Blair!
-
EricTRocks
- Moderator
- Posts: 754
- Joined: 25 Nov 2009, 01:41
-
Contact:
Post
by EricTRocks » 16 Jun 2013, 16:29
I know for a fact you can set the static_kinestate property without having to resort to jscript or vbscript. I think you can just use the .Transform to set it using a transform created from XSIMath.CreateTransform() that is filled by the GetTransform2() from your object. I just did this last week. Unfortunately I'm away from that code this weekend. Can post some on Tuesday if you haven't figured it out by then.
pseudo code:
myObjXform = myObj.Kinematics.Global.GetTransform2(None)
xform = XSIMath.CreateTransform()
xform.PutTransform2(None, myObjXform) # might need to use another method? Maybe .Copy() instead.
staticKine.Transform = xform
-
gustavoeb
- Moderator
- Posts: 587
- Joined: 21 Jul 2010, 00:33
- Skype: gustavoboehs
Post
by gustavoeb » 16 Jun 2013, 17:57
works a treat using Copy method Eric!
here is the working code:
Code: Select all
for i in range(0,xsi.Selection.Count):
obj = xsi.Selection(i)
if obj.HasStaticKinematicState():
#get kinematic and static kinematic states
obj_kine = obj.Kinematics
obj_statickine = obj.GetStaticKinematicState()
#get a copy (not actual transform) from global transforms
global_transform = obj_kine.Global.GetTransform2(None)
#copies global transform values to a newly created sitransform object
t1 = XSIMath.CreateTransform()
t1.Copy(global_transform)
#sets transform attribute
obj_statickine.Transform = t1
else: log(str(obj) + ' has no static kinematic state.')
Users browsing this forum: No registered users and 12 guests