def create_ob(nameid, classType='geo', *args, **kws): class_dict = { 'geo': GeneratePlugins(mp.SuperClassIds.GeomObject, mp.GeomObject), 'shape': GeneratePlugins(mp.SuperClassIds.Shape, mp.ShapeObject), 'cam': GeneratePlugins(mp.SuperClassIds.Camera, mp.CameraObject), 'light': GeneratePlugins(mp.SuperClassIds.Light, mp.LightObject), } search_class = list(class_dict[classType]) if isinstance(nameid, int): try: search_object = search_class[nameid] except IndexError: log.error("Maximum Index is %s"%(len(search_class)-1)) return else: search_object = [ob for ob in search_class if nameid.lower() in ob.GetObjectName().lower()] search_object = search_object[0] if search_object else None log.debug(search_object) log.debug([cl.GetObjectName() for cl in search_class]) if search_object: log.info(search_object) log.debug(dir(search_object)) log.debug(search_object.GetClassName()) for kw, value in kws.items(): for param in search_object.ParameterBlock: if kw.lower() in param.Name.lower(): try: param.Value = value except: log.warning("Cannot set %s for %s"%(value, param.Name)) # raise node = mp.Factory.CreateNode(search_object) log.info(node.Name) log.debug(dir(node)) for kw, value in kws.items(): # Set Node Name if kw.lower() in 'name': node.SetName(mp.Names.MakeNodeNameUnique(value)) # Set Postion if kw.lower() in "position": try: node.Position = mp.Point3(*value) except TypeError: node.Delete() raise # Set Rotation if kw.lower() in "rotate": try: matrix = mp.Matrix3() matrix.SetToRotation(*value) log.debug(matrix) node.Rotate(matrix.GetRotation()) except TypeError: node.Delete() raise # Set Scale return (node,search_object) else: log.error("Cannot find %s, Creatable Objects:\n%s"%( nameid, str([cl.GetObjectName() for cl in search_class])))
def RotatePivot(): root = MaxPlus.Core.GetRootNode() allnodes = Descendants(root) for node in allnodes: node.SetPivotMode(1) node.Rotate(MaxPlus.Quat(-1, 0, 0, 1), 0, MaxPlus.Matrix3(1), False, False, 1)
def PreservePosition(pos, matrix): tm = MaxPlus.Matrix3(*matrix) tm.SetTranslation(pos) return tm
def inverseMatrix(matrix): # return the inverse matrix tm = MaxPlus.Matrix3(*matrix) tm.Invert() return tm
sys.path.append("F:/FBX/2016.1/lib/Python27_x64/") import FbxCommon # Get Node by Name the_node = MaxPlus.INode.GetINodeByName("Point001") # Invert matrix method for Matrix3 class the_node = MaxPlus.INode.GetINodeByName("Point001") tm = the_node.GetWorldTM() inverse_tm = MaxPlus.Matrix3(*tm) print tm print inverse_tm inverse_tm.Invert() print inverse_tm # Change max modes hack though maxscript MaxPlus.Core.EvalMAXScript("max create mode") # Disable / Enable some redraws and viewports stuff MaxPlus.Core.EvalMAXScript("timeSlider.setVisible true") MaxPlus.Core.EvalMAXScript("trackbar.visible = true")
def ApplyOffset(new_pos, matrix): tm = MaxPlus.Matrix3(*matrix) pos = tm.GetTranslation() tm.SetTranslation(pos - new_pos) return tm