def highlight(obj, branch=True): # save selection in order to retrieve it at the end selection = XSIFactory.CreateObject("XSI.Collection") selection.AddItems(xsi.Selection) pref = xsi.Dictionary.GetObject("Preferences") scene_color = dynDispatch(pref.NestedObjects("Scene Colors")) sel_color = scene_color.Parameters("selcol") inh_color = scene_color.Parameters("inhcol") selColor_value = sel_color.Value inhColor_value = inh_color.Value sel_color.Value = 16712703 inh_color.Value = 16712703 if branch: mode = "BRANCH" else: mode = "ASITIS" xsi.SelectObj(obj, mode) xsi.Refresh() time.sleep(.2) sel_color.Value = selColor_value inh_color.Value = inhColor_value # Retrieve selection xsi.SelectObj(selection)
def selectMulti(in_mousebutton, in_keymodifier, object_names, exclude=[]): # Right click - Do nothing if in_mousebutton == 2: return model = getModel() controlers = XSIFactory.CreateObject("XSI.Collection") # Get objects for name in object_names: children = model.FindChildren(name) if children.Count: controlers.AddItems(children) # Remove objects # As we can yuse symbol such as '*' in the name list we might need to filter the result for name in exclude: if model.Name + "." + name in controlers.GetAsText().split(","): controlers.RemoveItems(model.Name + "." + name) if not controlers.Count: gear.log("Can't Find Controlers : " + ",".join(object_names), sn.sev_siError) return # Key pressed ======================================= if in_keymodifier == 0: # No Key or No Valid Key xsi.SelectObj(controlers) elif in_keymodifier == 1: # Shift check the object isn't already selected try: xsi.AddToSelection(controlers) except: return elif in_keymodifier == 2: # Ctrl xsi.ToggleSelection(controlers) elif in_keymodifier == 3: # Shift+Ctrl xsi.RemoveFromSelection(controlers) elif in_keymodifier == 4: # Alt xsi.SelectObj(controlers, "BRANCH", True) elif in_keymodifier == 5: # Alt+Shift check the object isn't already selected try: xsi.AddToSelection(controlers, "BRANCH", True) except: return elif in_keymodifier == 6: # Alt+Ctrl xsi.ToggleSelection(controlers, "BRANCH", True) elif in_keymodifier == 7: # Alt+Shift+Ctrl xsi.RemoveFromSelection(controlers)
def gear_GuideToolsUI_duplicateSym_OnClicked(): if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return selection = XSIFactory.CreateObject("XSI.Collection") selection.AddItems(xsi.Selection) rtn = XSIFactory.CreateObject("XSI.Collection") for sel in selection: if sel.IsClassOf(c.siX3DObjectID) and sel.Properties("settings"): rg = RigGuide() root = rg.duplicate(sel, True) if root: rtn.Add(root) else: gear.log("This object was skipped : " + sel.FullName, gear.sev_warning) if rtn.Count: xsi.SelectObj(rtn) return
def quickSel(in_mousebutton, in_keymodifier, port="A"): synoptic_prop = getSynoptic() quickSel_param = synoptic_prop.Parameters(QUICKSEL_PARAM_PREFIX + port) # Left click - Call selection if in_mousebutton == 0: if quickSel_param.Value == "": xsi.DeselectAll() else: model = getModel() selection = [ model.FindChild(name) for name in quickSel_param.Value.split(",") if model.FindChild(name) ] xsi.SelectObj(selection) # Middle click - Save selection elif in_mousebutton == 1: selection = [obj.name for obj in xsi.Selection] quickSel_param.Value = ",".join(selection) # Right click - Do nothing elif in_mousebutton == 2: return
def gear_createIcon_Execute(iconPreset): reload(gear.xsi.icon) funcDic = {"cube":icon.cube, "pyramid":icon.pyramid, "square":icon.square, "flower":icon.flower, "circle":icon.circle, "cylinder":icon.cylinder, "compas":icon.compas, "foil":icon.foil, "diamond":icon.diamond, "leash":icon.leash, "cubewithpeak":icon.cubewithpeak, "sphere":icon.sphere, "arrow":icon.arrow, "crossarrow":icon.crossarrow, "bendedarrow":icon.bendedarrow, "bendedarrow2":icon.bendedarrow2, "cross":icon.cross, "glasses":icon.glasses, "lookat":icon.lookat, "eyearrow":icon.eyearrow, "anglesurvey":icon.anglesurvey, "eyeball":icon.eyeball, "rectanglecube":icon.rectanglecube, "man":icon.man, "null":icon.null, "boomerang":icon.boomerang} if xsi.Selection.Count: XSIDial = XSIFactory.CreateObject( "XSIDial.XSIDialog") items = ["Only in Place", "Make it Parent", "Make it Child"] out = XSIDial.Combo("Creating Controls on Selected Objects", items) if out == -1: lm("Controls creation cancelled") return for obj in xsi.Selection: crv = funcDic[iconPreset]() source_object = obj tra.matchGlobalTransform( crv, source_object) if out == 1: oParent = obj.Parent #check if 2 objects have the same parent. if oParent.Name != crv.Parent.Name: xsi.ParentObj(oParent, crv) xsi.ParentObj(crv, obj) elif out == 2: xsi.ParentObj(obj, crv) crv.Name = obj.Name + "_" + iconPreset else: crv = funcDic[iconPreset]() xsi.SelectObj(crv) return crv
def selectAll(in_mousebutton, in_keymodifier): controlers = getAllControlers() if not controlers.Count: gear.log("Nothing to select", gear.sev_warning) return # Left and Middle click if in_mousebutton in [0, 1]: xsi.SelectObj(controlers) # Right click - Do nothing elif in_mousebutton == 2: return
def importFromXml(self, path): if not self.setFromFile(path): return if not self.valid: uit.msgBox("Imported guide is not up to date, Check log for missing element") self.draw() self.model.Name = os.path.basename(path).split(".")[0] xsi.SelectObj(self.model) return self.model
def duplicate(self, root, symmetrize=False): if not root or (root.Type != "#model" and not root.Properties("settings")): gear.log("Select a root to duplicate", gear.sev_error) return self.setFromHierarchy(root) for name in self.componentsIndex: comp_guide = self.components[name] if symmetrize: if not comp_guide.symmetrize(): return # Draw if root.Type == "#model": self.draw() else: for name in self.componentsIndex: comp_guide = self.components[name] if comp_guide.parentComponent is None: if symmetrize: parent = self.model.FindChild( uti.convertRLName(comp_guide.root.Name)) if parent is None: parent = comp_guide.root.Parent else: parent = comp_guide.root.Parent else: parent = self.model.FindChild( comp_guide.parentComponent.getName( comp_guide.parentLocalName)) if not parent: gear.log("Unable to find parent (%s.%s) for guide %s" % (comp_guide.parentComponent.getFullName, comp_guide.parentLocalName, comp_guide.getFullName)) parent = self.model comp_guide.root = None # Reset the root so we force the draw to duplicate comp_guide.setIndex(self.model) comp_guide.draw(parent) xsi.SelectObj(self.components[self.componentsIndex[0]].root)
def drawNewComponent(self, parent, comp_type): comp_guide = self.getComponentGuide(comp_type) if not comp_guide: return if parent is None: self.initialHierarchy() parent = self.model elif not parent.IsClassOf(c.siX3DObjectID): gear.log("Invalid Parent Selected", gear.sev_error) return else: parent_root = parent while True: if parent_root.Type == "#model": break # Setting some default value according to the parent (side, connector and uihost) if parent_root.Properties("settings"): parent_type = parent_root.Properties( "settings").Parameters("comp_type").Value parent_side = parent_root.Properties( "settings").Parameters("comp_side").Value parent_uihost = parent_root.Properties( "settings").Parameters("uiHost").Value if parent_type in comp_guide.connectors: comp_guide.setParamDefValue("connector", parent_type) comp_guide.setParamDefValue("comp_side", parent_side) comp_guide.setParamDefValue("uiHost", parent_uihost) break parent_root = parent_root.Parent3DObject if not self.isValidModel(parent.Model): return if comp_guide.drawFromUI(parent): xsi.SelectObj(comp_guide.root) xsi.InspectObj(comp_guide.settings)
def gear_DrawCube_Execute(): crv = icon.cube() xsi.SelectObj(crv) return crv
def gear_DrawNull_Execute(): crv = icon.null() xsi.SelectObj(crv) return crv
def gear_DrawMan_Execute(): crv = icon.man() xsi.SelectObj(crv) return crv
def gear_DrawRectangleCube_Execute(): crv = icon.rectanglecube() xsi.SelectObj(crv) return crv
def gear_DrawCubeWithPeak_Execute(): crv = icon.cubewithpeak() xsi.SelectObj(crv) return crv
def gear_DrawFoil_Execute(): crv = icon.foil() xsi.SelectObj(crv) return crv
def gear_DrawDiamond_Execute(): crv = icon.diamond() xsi.SelectObj(crv) return crv
def gear_DrawGlasses_Execute(): crv = icon.glasses() xsi.SelectObj(crv) return crv
def gear_DrawCross_Execute(): crv = icon.cross() xsi.SelectObj(crv) return crv
def gear_DrawBendedArrow2_Execute(): crv = icon.bendedarrow2() xsi.SelectObj(crv) return crv
def gear_DrawCrossArrow_Execute(): crv = icon.crossarrow() xsi.SelectObj(crv) return crv
def gear_DrawSphere_Execute(): crv = icon.sphere() xsi.SelectObj(crv) return crv
def gear_DrawPyramid_Execute(): crv = icon.pyramid() xsi.SelectObj(crv) return crv
def selectRoots(model): roots = model.FindChildren("*_root") if roots.Count: xsi.SelectObj(roots)
def gear_DrawAngleSurvey_Execute(): crv = icon.anglesurvey() xsi.SelectObj(crv) return crv
def gear_DrawCompas_Execute(): crv = icon.compas() xsi.SelectObj(crv) return crv
def gear_DrawEyeBall_Execute(): crv = icon.eyeball() xsi.SelectObj(crv) return crv
def gear_DrawLookAt_Execute(): crv = icon.lookat() xsi.SelectObj(crv) return crv
def gear_DrawLeash_Execute(): crv = icon.leash() xsi.SelectObj(crv) return crv
def select(in_mousebutton, in_keymodifier, name=None): model = getModel() if name is None: ctl = model else: ctl = model.FindChild(name) # Check if the object exists if not ctl: gear.log("Can't Find object : " + name, gear.sev_warning) return # Create Collection for different selection mode controlers = XSIFactory.CreateObject("XSI.Collection") # Mouse button ====================================== # Left Clic - Simple select if in_mousebutton == 0: controlers.Add(ctl) # Middle Clic - Select in 'branch' elif in_mousebutton == 1: controlers.Add(ctl) # Get all controlers of the model controlers_filtered = [] for group in getControlersGroups(): controlers_filtered.extend(group.Members.GetAsText().split(",")) # First Method, Try to find controlers of the same 'kind' # Find controler index has_index = False sIndex = re.search("[0-9]+_ctl$", ctl.Name) if sIndex: index = int(sIndex.group(0)[:-4]) has_index = True # Try to find child of the same 'type' if has_index and controlers_filtered: while True: index += 1 next_name = re.sub("[0-9]+_ctl$", str(index) + "_ctl", ctl.Name) if model.Name + "." + next_name not in controlers_filtered: break controlers.Add(model.FindChild(next_name)) # Second Method if no child found # we get all controlers children of selected one if controlers.Count == 1 and controlers_filtered: for child in ctl.FindChildren(): if child.FullName in controlers_filtered: controlers.Add(child) # Right Clic - Do nothing elif in_mousebutton == 2: return # Key pressed ======================================= if in_keymodifier == 0: # No Key or No Valid Key xsi.SelectObj(controlers) elif in_keymodifier == 1: # Shift check the object isn't already selected try: xsi.AddToSelection(controlers) except: return elif in_keymodifier == 2: # Ctrl xsi.ToggleSelection(controlers) elif in_keymodifier == 3: # Shift+Ctrl xsi.RemoveFromSelection(controlers) elif in_keymodifier == 4: # Alt xsi.SelectObj(controlers, "BRANCH", True) elif in_keymodifier == 5: # Alt+Shift check the object isn't already selected try: xsi.AddToSelection(controlers, "BRANCH", True) except: return elif in_keymodifier == 6: # Alt+Ctrl xsi.ToggleSelection(controlers, "BRANCH", True) elif in_keymodifier == 7: # Alt+Shift+Ctrl xsi.RemoveFromSelection(controlers)
def gear_DrawEyeArrow_Execute(): crv = icon.eyearrow() xsi.SelectObj(crv) return crv