def toggleDisplayParameter(param_name): # The Toogle is made on the view that got the focus cam_name = getActiveCamera() if not cam_name: XSIUIToolkit.Msgbox("There is no 'View Manager' in current layout.", c.siMsgExclamation, "Failed") return xsi.ToggleValue("camdisp."+param_name, cam_name) xsi.SetValue(cam_name+".camvis.custominfoproxynames", True, None)
def gear_prefPoseLibProp_setPreferences_OnClicked(): if xsi.Preferences.Categories("gear_prefPoseLib"): xsi.SetValue("preferences.gear_prefPoseLib.global_Repo", PPG.global_Repo.Value, "") xsi.SetValue("preferences.gear_prefPoseLib.list_Size", PPG.list_Size.Value, "") xsi.SetValue("preferences.gear_prefPoseLib.control_groups_list", PPG.control_groups_list.Value, "") else: prop = xsi.ActiveSceneRoot.AddProperty("CustomProperty", False, "gear_prefPoseLib") prop.AddParameter3("global_Repo", c.siString, 0, 0, None, False, False) prop.AddParameter3("list_Size", c.siInt4, 500, 1, None, False, False) prop.AddParameter3("control_groups_list", c.siString, 0, 0, None, False, False) prop.global_Repo.Value = PPG.global_Repo.Value prop.list_Size.Value = PPG.list_Size.Value prop.control_groups_list.Value = PPG.control_groups_list.Value xsi.InstallCustomPreferences (prop, "gear_prefPoseLib") PPG.Close() if xsi.ActiveSceneRoot.Properties("gear_prefPoseLibProp"): xsi.DeleteObj(xsi.ActiveSceneRoot.Properties("gear_prefPoseLibProp"))
def copyEnvelopeWithGator(mesh, source_meshes): # Set the log display to False because Gator Op display a lot of messages b = xsi.Preferences.Categories("scripting").Parameters("msglog").Value xsi.Preferences.Categories("scripting").Parameters("msglog").Value = False if mesh.Type not in ["polymsh"]: gear.log("Invalid selection", gear.sev_error) return # Apply a Gator Op gator_op = xsi.ApplyGenOp("Gator", "", mesh.FullName + ";" + source_meshes.GetAsText(), 3, c.siPersistentOperation, c.siKeepGenOpInputs, None) xsi.CopyAnimationAcrossGenerator(gator_op, 2, 1) # I wasn't able to use the FullName Property for gator_op xsi.SetValue(str(gator_op) + ".inputreadregion", 0, None) xsi.FreezeModeling(mesh) # Set the log back to its original value xsi.Preferences.Categories("scripting").Parameters("msglog").Value = b
def gear_newPoseProp_saveNewPose_OnClicked(): #Check if the name is valid oName = PPG.parPoseName.Value if not oName.isalnum(): lm("The name is not valid, use alphanumeric characters only ", 2) else: #Check is something is selected oSel = xsi.Selection if oSel.Count: #Construt the path userName = os.environ.get( "USERNAME" ) #Global Path if PPG.parRepo.Value == "Global": if xsi.Preferences.Categories("gear_prefPoseLib"): globalPath = Application.GetValue("preferences.gear_prefPoseLib.global_Repo") else: globalPath = "Ops! you forget to set the preferences" userPath = False if os.path.isdir(globalPath): userPath = os.path.join(globalPath, userName) if not os.path.isdir(userPath): os.makedirs(userPath) else: lm("Global Path preferences are not set correctly. Looks like the folder: " + globalPath +" Doesn't exist.", 4 ) #Current DB user path else: currentProject = xsi.ActiveProject2.Path currentPosePath = os.path.join(currentProject, "PoseLib") if not os.path.isdir(currentPosePath): os.makedirs(currentPosePath) lm("New folder for poses in the current datebase (DB) was created: " + currentPosePath ) userPath = os.path.join(currentPosePath, userName) if not os.path.isdir(userPath): os.makedirs(userPath) if userPath: oModel = oSel(0).Model modName = oModel.Name.split("_")[0] #Check if the pose exist and ask for overwrite oReturn = 6 # is the return value fo "yes" in the msgBox. We use it as default. if os.path.isdir(os.path.join(userPath, modName + "_" + oName)): oReturn = XSIUIToolkit.MsgBox( "The pose exist!!. Do you want to overwrite it?", c.siMsgYesNo ) else: #Create folders if doesn't exist os.makedirs(os.path.join(userPath, modName + "_" + oName)) if oReturn == 6: #Create xml pose oModel = oSel(0).Model root = xml.Element(oModel.Name) # Function indentation =============================== def indent(elem, level=0): i = "\n" + level*" " if len(elem): if not elem.text or not elem.text.strip(): elem.text = i + " " if not elem.tail or not elem.tail.strip(): elem.tail = i for elem in elem: indent(elem, level+1) if not elem.tail or not elem.tail.strip(): elem.tail = i else: if level and (not elem.tail or not elem.tail.strip()): elem.tail = i # =========================================== for oItem in oSel: collection = XSIFactory.CreateActiveXObject( "XSI.Collection" ) collection.AddItems( oItem ) oKeyable = collection.FindObjectsByMarkingAndCapabilities( None, c.siKeyable ) child = xml.Element(oItem.Name) root.append(child) for oParam in oKeyable: childParam = xml.Element(".".join(oParam.FullName.split(".")[2:])) childParam.attrib["Value"] = str(oParam.Value) #childParam.attrib["scriptName"] = str(oParam.ScriptName) child.append(childParam) indent(root) posePath = os.path.join(userPath, modName + "_" + oName, oName + ".xml") file = open(posePath, "w") xml.ElementTree(root).write(file) file.close() #Capture the image currFrame = xsi.ActiveProject.Properties("Play Control").Parameters("Current").Value oViewportCapture = xsi.Dictionary.GetObject("ViewportCapture") xsi.SetValue("Views.view*.*Camera.camvis.gridaxisvis", False, "") xsi.SetValue("Views.view*.*Camera.camvis.constructionlevel", False, "") xsi.SetValue("*Camera.camvis.gridaxisvis", False, "") xsi.SetValue("*Camera.camvis.constructionlevel", False, "") oViewportCapture.NestedObjects[0].PutValue2(None, os.path.join(userPath, modName + "_" + oName, oName + ".jpg")) # path FileName oViewportCapture.NestedObjects[1].PutValue2(None, "(fn)(ext)") # frame Padding oViewportCapture.NestedObjects[2].PutValue2(None, "75") # Width oViewportCapture.NestedObjects[3].PutValue2(None, "75") # Height oViewportCapture.NestedObjects[4].PutValue2(None, "1") # Scale Factor oViewportCapture.NestedObjects[5].PutValue2(None, "True") # user pixel ratio oViewportCapture.NestedObjects[6].PutValue2(None, "1.0") # pixel ratio oViewportCapture.NestedObjects[10].PutValue2(None, currFrame) # Start Frame oViewportCapture.NestedObjects[11].PutValue2(None, currFrame) # End Frame oViewportCapture.NestedObjects[12].PutValue2(None, "False") # Launch Flipbook xsi.CaptureViewport( -1, False ) xsi.SetValue("Views.view*.*Camera.camvis.gridaxisvis", True, "") xsi.SetValue("Views.view*.*Camera.camvis.constructionlevel", True, "") xsi.SetValue("*Camera.camvis.gridaxisvis", True, "") xsi.SetValue("*Camera.camvis.constructionlevel", True, "") #Create the miniSynoptic imageName = oName +".jpg" oDate = strftime("%a, %d %b %Y %H:%M:%S") synCretor(posePath, imageName, oName, userName, oDate, oModel.Name) else: lm("Creation cancelled", 2) else: lm("Set preferences before save poses in the global repo", 2) else: lm("Nothing selected, Pose can not be stored", 2) PPG.Close() if xsi.ActiveSceneRoot.Properties("gear_newPoseProp"): xsi.DeleteObj(xsi.ActiveSceneRoot.Properties("gear_newPoseProp"))