PDA

View Full Version : There's got to be an easy answer for this, right?



short223
01-04-2016, 09:27 AM
I've been scouring the post and available docs and can't seem to solve this:

I've been able to successfully write a script to read in position and rotation information and apply it to my camera.

Now I need to do the opposite, which is read the current x y z position & h p b rotation and assign each value to a variable before I write it out to a .txt file.

For the life of me I can't find the commands or method that reads or gets the current objects information.

I have seen this post which seemed to have potential as it read the channels but it didn't seem to do anything or I just didn't know how to use it.

"FYO, in order to read the position and rotation of a given object at a given time (which may or not be a frame) :"

def getPositionAndRotation(self, object, cur_time):
# Note : this returns degrees - hence the "* 57.2957795"
groupID = lwsdk.LWItemInfo().chanGroup( object )
chanID = lwsdk.LWChannelInfo().nextChannel(groupID, None)
(x,y,z,h,p,b) = (0.0,0.0,0.0,0.0,0.0,0.0)
while chanID:
channelName = lwsdk.LWChannelInfo().channelName(chanID)
if channelName == "Position.X":
x = lwsdk.LWChannelInfo().channelEvaluate(chanID, cur_time)
elif channelName == "Position.Y":
y = lwsdk.LWChannelInfo().channelEvaluate(chanID, cur_time)
elif channelName == "Position.Z":
z = lwsdk.LWChannelInfo().channelEvaluate(chanID, cur_time)
elif channelName == "Rotation.H":
h = lwsdk.LWChannelInfo().channelEvaluate(chanID, cur_time) * 57.2957795
elif channelName == "Rotation.P":
p = lwsdk.LWChannelInfo().channelEvaluate(chanID, cur_time) * 57.2957795
elif channelName == "Rotation.B":
b = lwsdk.LWChannelInfo().channelEvaluate(chanID, cur_time) * 57.2957795
# else - we don't care !
chanID = lwsdk.LWChannelInfo().nextChannel(groupID, chanID)
return (x,y,z,h,p,b)

I tried to print what x y z or h p b but it just gives me errors such as those variables are not defined.

Then the author of the code mentions this to "Use it"

(fb_x,fb_y,fb_z,fb_h,fb_p,fb_b) = self.getPositionAndRotation(temp_obj,startTime)

All this seems complicated just to GET basic Position and Rotation and assign a variable for each that I can export.
ANY help would be appreciated!
Thanks!
Chris

ernpchan
01-04-2016, 09:50 AM
Where is this source script? If it's saying those variables aren't defined, that means it's not getting to the part where it actually assigns that value.

short223
01-04-2016, 10:50 AM
http://forums.newtek.com/showthread.php?127883-Code-Snippets-(aka-quot-How-to-quot-)

At the bottom....

ernpchan
01-04-2016, 10:54 AM
http://forums.newtek.com/showthread.php?127883-Code-Snippets-(aka-quot-How-to-quot-)

At the bottom....

Ohok...so you don't have a working version of an actual script...just a snippet. You trying to get the data on every frame or just where there are actual keyframes?

short223
01-04-2016, 10:58 AM
Just the selected item at that current frame/time. The idea is what ever is selected, record the x y z & h p b of that object and write it to a text file.

short223
01-04-2016, 11:01 AM
something like Get Item Position or Get Item Rotation command that splits up the three values for each so I can assign a variable to...

short223
01-04-2016, 11:16 AM
I think I found part of my answer on the LW Python wiki.


import lwsdk

curTime = lwsdk.LWInterfaceInfo().curTime

for item in lwsdk.LWInterfaceInfo().selected_items():
name = lwsdk.LWItemInfo().name(item)
print name
parm = lwsdk.LWItemInfo().param(item, lwsdk.LWIP_W_POSITION, curTime)
print " World Coordinate XYZ values are X: %g Y: %g Z: %s" % ( parm[0], parm[1], parm[2] )

I still have to decipher this but it does give me the X Y and Z values correctly.

Now to experiment with Rotation...

short223
01-04-2016, 11:25 AM
Now I was able to get both position and rotation using lwsdk.LWIP_W_POSITION and lwsdk.LWIP_ROTATION. The rotation comes in as radians which is what I needed anyways. I just have to figure out how to assign each to a individual variable.

ernpchan
01-04-2016, 11:48 AM
I think I found part of my answer on the LW Python wiki.


import lwsdk

curTime = lwsdk.LWInterfaceInfo().curTime

for item in lwsdk.LWInterfaceInfo().selected_items():
name = lwsdk.LWItemInfo().name(item)
print name
parm = lwsdk.LWItemInfo().param(item, lwsdk.LWIP_W_POSITION, curTime)
print " World Coordinate XYZ values are X: %g Y: %g Z: %s" % ( parm[0], parm[1], parm[2] )

I still have to decipher this but it does give me the X Y and Z values correctly.

Now to experiment with Rotation...

parm is a list, so just assign each index to it's own variable.

xVal = parm[0]
yVal = parm[1]
zVal = parm[2]

short223
01-04-2016, 12:06 PM
Yep. That's what I did.
Thanks!