Python example constraining nulls to components


Just a little example that uses the Object Model to create a null and a ObjectToCluster constraint for each selected component (point, edge, polygon, …).
Note line 13. I can use CollectionItem.SubElements to get the indices of the selected components.

from win32com.client import constants as C
si = Application
log = si.LogMessage


if si.Selection.Count > 0 and si.ClassName(si.Selection(0)) == 'CollectionItem' and si.Selection(0).SubComponent is not None:

	# pnt, poly, edge, ...
	clusterType = si.Selection(0).Type.replace( 'SubComponent','' )
	o = si.Selection(0).SubComponent.Parent3DObject
	
	for i in si.Selection(0).SubElements:
		c = o.ActivePrimitive.Geometry.AddCluster( clusterType, "", [i] )
		n = si.ActiveSceneRoot.AddNull()
		n.Kinematics.AddConstraint( "ObjectToCluster", c )