Objects and default properties


Here’s a scripting question from the mailing list:

Why do I get “None” when I print ChainRoot.Children and
ChainRoot.Bones?

si = Application
chainRoot = si.Create2DSkeleton(0, 0, 0, 10, 0, 0, -90, 0, 0, 4)

print chainRoot
print chainRoot.Children # Not working
print chainRoot.Bones # Not working
print chainRoot.Effector

# root1
# None
# None
# eff1

The answer is that ChainRoot.Children and ChainRoot.Bones are objects that don’t have a default property, so (in Python) you get the string representation of those objects, which is “None”.

ChainRoot and ChainRoot.Effector, being types of SIObject, and they do have a default property: the Name property.

ChainRoot.Children is an X3DObjectCollection, and ChainRoot.Bones is a ChainBoneCollection, and for whatever reason, those two collections don’t have Item as their default property (for some collections, like ISIVTCollection and LinktabRuleCollection, the Item property is the default property).

So the above Python is equivalent to this:

si = Application
chainRoot = si.Create2DSkeleton(0, 0, 0, 10, 0, 0, -90, 0, 0, 4)

print chainRoot.Name
print str( chainRoot.Children )
print chainRoot.Bones.__str__()
print chainRoot.Effector.Name

# root1
# None
# None
# eff1

Note that in JScript and VBScript, you’d get a “Type mismatch” error instead of the string “None” (in the original snippet).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s