PDA

View Full Version : Getting info on bone properties?



Ryan Roye
07-21-2014, 07:17 PM
Ok, so I'm finally starting to do some python scripting to address some long standing issues with some of my animation workflows. Quick question:

Anyone have any clue as to how one can use boneinfo to get bone rest length in python?

I got as far as lwsdk.LWBoneInfo in the docs... just can't figure out how to gain access to bone properties and I can't find any examples of these properties being used in scripting even in the LWSDK docs. I just want to grab the bone's rest length value so that I can use it to make changes to other items in the scene.

ernpchan
07-21-2014, 07:30 PM
You're in the right area.

Per the python docs:

restLength(LWItemID bone) → double
Returns the rest length of bone.

Ryan Roye
07-21-2014, 07:53 PM
it's just not sinking in, i've been at this for hours.

#get selected items
items = lwsdk.LWInterfaceInfo().selected_items()
print items

#Go through each item
for item in lwsdk.LWInterfaceInfo().selected_items():
lwsdk.command("SelectItem " + lwsdk.itemid_to_str(item)) #Select items 1 by 1
restLength(LWItemID bone) ???
lwsdk.command("ItemColor 11")

How do I go from having the itemID to using that itemID to extract bone info? Everything i've thrown at this thing has returned syntax errors.

ernpchan
07-21-2014, 08:20 PM
Don't know the syntax off hand....

Have you looked on justaddmilk.org? That site is a good resource.

When I'm in front of my workstation tomorrow I'll look at me scripts, unless someone beats me to it.

Ryan Roye
07-21-2014, 08:56 PM
Have you looked on justaddmilk.org? That site is a good resource.

Yup! And i've pooled a bunch of other resources as well. FYI I'm working on the following tools for Lightwave:

- Layout Symmetry Editing tool (completed)
- Layout Bone pinning (completed)
- Bone rest length symmetry (what I'm working on)
- Simple Auto-Retargeting w/ UI
- Relative motion auto-prep
- Various keyframing tools, keyframe thinning, GE functions in keypresses, etc

As I'm still learning I can't guarantee they'll work for everyone, but I'm posting all my scripts here (http://www.liberty3d.com/citizens/ryan-roye/ryan-royes-free-plugins/) as they are completed and updated.

ernpchan
07-21-2014, 09:03 PM
Dam! I'm suprised you're stuck. It sounds like you already know what you're doing.
:D

ernpchan
07-21-2014, 11:08 PM
Well it turns out lwsdk.LWBoneInfo isn't what you want unless you want to query for the value. You'd think LWBoneInfo would be what you want but python scripting in LW is a mix of accessing the C sdk and commands that you have to look up through the lscript docs.

Turns out assigning a bone's rest length is a Layout command. This is it in lscript. (Shout out to Dodgy's site http://www.mikegreen.name/Lscript/Lscript%20Index.html)

BoneRestLength("length");

This would be the python code. In the example below I'm setting the rest length to 5.


import lwsdk

#get selected items
items = lwsdk.LWInterfaceInfo().selected_items()
print items

#Go through each item
for item in lwsdk.LWInterfaceInfo().selected_items():
lwsdk.command("SelectItem " + lwsdk.itemid_to_str(item)) #Select items 1 by 1
lwsdk.command("BoneRestLength " + str(5))
lwsdk.command("ItemColor 11")

Be aware that changing the rest length of a parent bone won't automatically change the Z position of the child bone to be at the tip.

Ryan Roye
07-22-2014, 04:35 AM
Well it turns out lwsdk.LWBoneInfo isn't what you want unless you want to query for the value.

Querying the value is exactly what I want. The idea is that I read the rest length value of all the bones on the left side of the character, and use those values to adjust the rest length of the bones on the right side. Setting the bone length is easy... getting the bone length seems to be making me want to pull my hair out.

EDIT: I managed to get help with the answer, here it is:

items = lwsdk.LWInterfaceInfo().selected_items()
print lwsdk.LWBoneInfo().restLength(items[0])

I'll need to see if I can ask what the hell the logic is in this though... because what I read in the docs does not match or make sense with these two lines of script. I get the itemID part... I don't get what the "[0]" part is all about. In any case, thanks for your help!

It would be nice if the SDK docs could include simple lines like this so the the would-be programmer knows how the function is meant to be used at its most basic level.

Sensei
07-22-2014, 04:59 AM
lwsdk.command("SelectItem " + lwsdk.itemid_to_str(item)) #Select items 1 by 1


You don't need to extract name...

f.e.
SelectItem 0x10000000
will for example select item with such ItemID..

Although
SelectItem 10000000
also works.

But I am using with "0x"


I don't get what the "[0]" part is all about

selected items is array of ItemID... Not single value. It's multi selection friendly.

Indexes in arrays start from 0.

Ryan Roye
07-22-2014, 06:36 AM
selected items is array of ItemID... Not single value. It's multi selection friendly.

Indexes in arrays start from 0.

Thanks, that info will come in handy when I figure out how indexes work in Python, for now I'm just being inefficient and using the selection method.

The bone symmetry script (http://www.liberty3d.com/citizens/ryan-roye/ryan-royes-free-plugins/) is done, yay!