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_Select6MoreBranchesStars_Execute(): if not xsi.Selection.Count: gear.log("No selection", gear.sev_error) return objects = [obj for obj in xsi.Selection if obj.Type in ["polymsh"]] if not objects: gear.log("Invalid Selection", gear.sev_error) return xsi.DeselectAll() for obj in objects: stars = geo.getStars(obj, 6, True) if stars: gear.log("There is " + str(len(stars)) + " stars with 6 branches or more on " + obj.FullName) xsi.AddToSelection(obj.FullName + ".pnt" + str(stars), "", True) else: gear.log("There is no stars with 6 branches or more on " + obj.FullName)
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)