Results 1 to 10 of 10

Thread: There's got to be an easy answer for this, right?

  1. #1

    There's got to be an easy answer for this, right?

    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) :"
    Code:
    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"
    Code:
            (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

  2. #2
    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.
    My opinions and comments do not represent those of my employer.
    www.ernestpchan.com
    www.zazzle.com/gopuggo

  3. #3

  4. #4
    Quote Originally Posted by short223 View Post
    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?
    My opinions and comments do not represent those of my employer.
    www.ernestpchan.com
    www.zazzle.com/gopuggo

  5. #5
    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.

  6. #6
    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...

  7. #7
    I think I found part of my answer on the LW Python wiki.

    Code:
    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...

  8. #8
    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.

  9. #9
    Quote Originally Posted by short223 View Post
    I think I found part of my answer on the LW Python wiki.

    Code:
    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.
    Code:
    xVal = parm[0]
    yVal = parm[1]
    zVal = parm[2]
    My opinions and comments do not represent those of my employer.
    www.ernestpchan.com
    www.zazzle.com/gopuggo

  10. #10
    Yep. That's what I did.
    Thanks!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •