
Create controls in bounding box
Frequently I’m using the “Create Cluster with Center” command to create control objects. After a while I found myself tagging components and running this command, just to get a null in the bounding box center. What’s annoying about that is, it creates also the “cluster center” operator and an cluster on the mesh. Unfortunately this is not my original intention. I just want centered nulls for rigging.
So I made small python function that reads the bounding box information of the tagged components (points, edges or polygons) creates a reset-null plus a control-null and set them to the coordinates of the bounding box.
This makes it super fast to create controls – for example in the middle of lips.
from win32com.client import constants as c xsi = Application log = Application.LogMessage collSel = xsi.Selection # Find the BBox Center and Create an Ctrl Object def createCtrlInBBox(): oSelChecker = False if collSel(0): #Get Selection Center list = xsi.GetValue( "SelectionList" ) #Set Checker for reselection oSelChecker = True #Get BBox of the Selection oBB = xsi.GetBBox(list, False) #Get Coordiates xmin = oBB.Value( "LowerBoundX" ) ymin = oBB.Value( "LowerBoundY" ) zmin = oBB.Value( "LowerBoundZ" ) xmax = oBB.Value( "UpperBoundX" ) ymax = oBB.Value( "UpperBoundY" ) zmax = oBB.Value( "UpperBoundZ" ) #Calculate the center postion xcenter = (xmax + xmin) / 2 ycenter = (ymax + ymin) / 2 zcenter = (zmax + zmin) / 2 else: #Set Coordiates xcenter = 0 ycenter = 0 zcenter = 0 #UserFeedback log("debug: world center of selection: x:" + str(xcenter) + " y: " + str(y center) + " z: " + str(zcenter)) #Tansform Grp & CtrlObj xsi.DeselectAll() oTransGrp = xsi.GetPrim("Null", "CenterPNT_REST_1","") oCtrlNull = xsi.GetPrim("Null", "CenterPnt_CON_1", "", "") xsi.CopyPaste(oCtrlNull, "", oTransGrp, 1) #Look xsi.SetValue(str(oTransGrp.Name) + ".null.primary_icon", 1, "") xsi.SetValue(str(oCtrlNull.Name) + ".null.primary_icon", 0, "") xsi.SetValue(str(oCtrlNull.Name) + ".null.shadow_icon", 2, "") xsi.SetValue(str(oCtrlNull.Name) + ".null.shadow_colour_custom", True, "") xsi.SetValue(str(oCtrlNull.Name) + ".null.R", 0.998, "") xsi.SetValue(str(oCtrlNull.Name) + ".null.G", 1, "") xsi.SetValue(str(oCtrlNull.Name) + ".null.B", 0, "") #Translate xsi.SetValue(str(oTransGrp.Name) + ".kine.local.posx", xcenter, "") xsi.SetValue(str(oTransGrp.Name) + ".kine.local.posy", ycenter, "") xsi.SetValue(str(oTransGrp.Name) + ".kine.local.posz", zcenter, "") #RestoreSelection if available if oSelChecker == True: xsi.SelectObj(list, "", True) createCtrlInBBox()