FAQ Database Discussion Community


python execute list and list of functions [duplicate]

python,string,function,python-2.7,maya
This question already has an answer here: How can I iterate through two lists in parallel in Python? [duplicate] 4 answers I'm utilizing Python 2.7 with Autodesk Maya. Here's an example of my issue: import maya.cmds as m def a(passedString): print('this'+passedString) def b(passedString): print('that'+passedString) def c(passedString): print('notThis'+passedString) def d(passedString):...

Python String Templating with Case Sensitivity

python,python-2.7,maya
This is a naming script that i use to name nodes in Autodesk Maya. This particular script however doesnt use anything maya specific. I had asked a while ago how I would go about doing something like this, where a variable convention could be used, and templating came up. So...

How to get Node class instance from MObject in Maya API

c++,plugins,nodes,maya
In a cpp plugin I am developing in Maya API, I register a custom MPxTransform Node in the initializePlugin function: status=pluginFn.registerTransform("mympxtransform", myMPxTransformClass::id, &myMPxTransformClass::creator, &myMPxTransformClass::initialize, &myMPxTransformMatrixClass::creator, myMPxTransformMatrixClass::id); And then create the node programmatically: MDagModifier mdagmod; MObject MyMObject; MyMObject=mdagmod.createNode("mympxtransform",MObject::kNullObj,&status); I can see the node properly created in the...

Querying a shading node Maya Python

python,maya
I am currently having a problem where i want to query the 'inputX' of a multiplyDivide Node in maya and put the queried number into the 'inputX' of another multiplyDivide node. The script currently makes an stretchy IK set up for an arm. Using a distanceBetween the shoulder and the...

Opening a commandPort in standalone maya for unit testing

python,maya
I am writing unit tests for a script that sends python code to Autodesk Maya trough the commandPort. The script works; it sends code fine to Maya which executes it. For testing purposes however, I want to write a unit test that in its setUp() opens a standalone (commandline) Maya...

Auto-completing “Create Polygon Tool” Maya

python,python-2.7,polygon,maya,pymel
I'm trying to figure out a way to create an auto-completing "Create Polygon Tool" in Maya, in Python. It's so when you build geometry, it will select the previous geometry, and the current one you made, and run a line of commands. I've run into a snag, though, in which...

Maya Python - Connecting UI to functions

python,function,user-interface,maya
I am working on creating a little Bullet Spray Generator to be run in maya using Python and I'm stuck on how to take the values inputted by the user in the UI and use them in functions. The bulletSpread function needs to take the value from createGunUI, specifically the...

Maya Adding Numerical Compound attribute (non-API)

python,nodes,maya,mel,addattribute
I've been looking around the internet for a solution but to no avail. I am currently trying to add a compound attribute that is index based (i.e. "object.attribute[0], object.attribute[1], object.attribute[2], etc...) similar to how vertex and uv attributes are used. Looking through the documentation it seems that there is no...

Maya MEL variables declaration and initialization

variables,maya,mel
Is it obligatory in MEL to initialize variables and especially strings when you declare them? I know that it is not necessary to initialize string arrays: string $buffer[]; $buffer[0] = "abc"; But what about strings and other variable types? Is it acceptably: string $str; $str = "abc"; Or should always...

Maya Python: How do i call on and edit attributes of an object in one function when that object was created in another function?

python,maya
The Plan: I've been working on a script for measuring the distance between 2 vertices that the user selects and scaling up or down that the object based on a desired length between those vertices. The Problem: Error states that it cannot locate the textFieldButtonGrp object that I create in...

maya python subprocess error

python-2.7,subprocess,stdout,maya
in python 2.7 i try this code to get data from Deadline software. Its return some data from server... import subprocess path = 'C:/Program Files/Thinkbox/Deadline7/bin/' p1 = subprocess.Popen([path + 'deadlinecommand.exe', 'pools'], stdout=subprocess.PIPE) p1.communicate() and see result: ('none\r\npool_01\r\npool_02\r\npool_03\r\npool_04\r\npool_05\r\npoolhalf\r\n', None) but when i copy that code to python in maya 2014 i...

PYTHON in MAYA: get all attributes

python,maya
I would like to know if there is a way to get the list of attributes that we can get with pymel.core.getAttr() (or maya.cmds.getAttr() for cmds users). __dict__ doesn't give that list. import pymel.core as pmc myCubeTrans, myCubeShape = pmc.polyCube() >>> print myCubeTrans.__dict__ {'__apiobjects__': {'MDagPath': <maya.OpenMaya.MDagPath; proxy of <Swig Object...

Maya Python: Check to see if the attribute has any keyframes

python,graphics,3d,maya,maya-api
I am trying to write a python script for Maya that will copy keyframes from one rig to another. I have found objects and matched them up. What I am trying to do now is copy the keys from the original objects if the original objects have keys to be...

Maya Python… workaround for arbitrary precision when coding with maya.cmds

python,decimal,scale,maya,arbitrary-precision
Maya commands library seems to dislike working with the built in decimal module in python. I am trying to scale an object by an arbitrarily large float for precision. As far as understanding that you can't scale by a decimal 'object' is clear. ive been trouble shooting the math and...

Python + Maya - How to change a float into a time value

python,maya
So I'm basically trying to create a textField in which users type in a startFrame and endFrame and it scales it by the value in the slider. So, I have this, for the floatFields. cmds.text( label='Start Frame' ) startFrame = cmds.floatField() cmds.text( label='End Frame' ) endFrame = cmds.floatField() So, from...

Mel Expression Syntax error

syntax-error,maya,mel
i don't normally script in mel as my knowledge on it is very limited. I have made a expression however it keeps coming back with // Error: Line 7.1: Syntax error // Here is the expression: if (global_IkFk_Ctr.L_Arm == 0){ l_Bn_ShoulderJnt_01.scaleX == l_Ik_ShoulderJnt_01.scaleX; l_Bn_ElbowJnt_01.scaleX == l_Ik_ElbowJnt_01.scaleX; } else (global_IkFk_Ctr.L_Arm ==...

Maya Orthographic Projection Matrix

python,opengl,maya,orthographic
I'm attempting to calculate maya's orthographic projection matrix. Is anyone familiar with how to calculate it? I am not interested in perspective, just orthographic camera views. import math import maya.cmds as cmds import maya.OpenMaya as OpenMaya import maya.OpenMayaUI as OpenMayaUI # Get view matrix. view = OpenMayaUI.M3dView.active3dView() mayaProjMatrix = OpenMaya.MMatrix()...

Maya Python object assigned as a listType, but won't convert to string?

python,string,list,unicode,maya
I'm starting to use objects a bit more to store Maya commands in Python. This is super useful! But I've run into a problem. Sometimes objects get commands that return Unicode lists rather than a string. Even using str() doesn't work. Code: cubeParent = cmds.polyCube(sx=10, sy=15, sz=5, h=20) print cubeParent...

PYTHON IN MAYA : get theline with warning

python,maya
I would like to know how I can get the line of the warning when I use pymel.core.warning() (or maya.cmds.warning()). I try to add the argument showLineNumber = True but nothing changed. I only have got this warning : # Warning: The 'showLineNumbers' flag is obsolete and will be removed...

replace text in textField with object name - Pymel

python-2.7,textfield,maya,pymel
I've realized that there were similar questions located here: textfield query and prefix replacing and here: Python - Change the textField after browsing - MAYA However, these do not address the issue if you have two definitions and need the text in the textField to be queried (actually CHANGE the...

How to check if instance exists if variable not existing?

python,maya,mel
I have a button which imports a module with a class. The class (varClass) creates a window. If i click the button once again, i try this: if var: var.toggleUI() else : var = varClass() But var doesn' exist the first time you create the window after opening Maya. How...

How do you get Maya to communicate through the localhost IP?

maya,autodesk
What I have been researching with no luck, is how to get Autodesk Maya to communicate though the web on the localhost ip (preferably TCP). My goal is to control maya with a quick java application I wrote to manipulate curve selecting and such. If there is a way to...

Python Name Abreviation finding

python,maya
I get info that reads like this xy123, xy0123, xyz_123, and xy01 XYZ being different letters and 123 being different numbers. For example QWA_0230. I get letters and numbers any amount seperated by a _ sometimes. I'm interested in a line of code that will find the letters at the...

Maya, Python, How do i get the name of an object based on vertex selection?

python,list,indexing,maya,vertices
I got the code working like this until i realized that the vertex index changes for geometry with over 100 vertices... I assumed i could just split the string and everything would be dandy import maya.cmds as mc selPoints = mc.ls(sl = True) # list of names of selected vertices...

Map values from an UI into QTreeWidget Column

python,maya,qtreewidget
sorry if my following question sounds stupid but I am pretty much in a lost, big way! I have created 2 UIs using the Qt-Designer. Main UI (anmgToolUI) - http://pastebin.com/raw.php?i=eXVWj99Q Sub UI (publishInfoUI) - http://pastebin.com/raw.php?i=KsnJC8wR And the following is the main code: Main Code - http://pastebin.com/mbg2fuvh And I am using...

Maya, PYTHON: how do i select all but one in a list?

python,list,maya,deselect
how do i deselect all objects except for my last selection? When I'm working with 2 objects there's no problem because all i have to do is toggle list[0] which would be first object that i selected (this is how i have it working below). import maya.cmds as mc sel_objs...

Get a mesh node from a transform node in Maya C++ API

c++,plugins,mesh,maya
I want to get a shape/mesh object under a transform node active in Maya. If I select and object (e.g. a poly sphere) in Maya, when calling getActiveSelectionList method, it returns a transform node, not a shape/mesh one. I'm getting crazy reading the API classes (MDagPath, MSelectionList, MFnDependencyNode) and methods...

How to find separate objects in a list of 3D coordinates

python,maya,pymel
I started giving a basic voxel type script a shot, where it'll look in the 6 directions adjancent to a point n draw a plane across any side that doesn't have anything next to it. Then I can combine the planes and it'll make an object. This works nicely when...

Python for Maya: “Object's name is not unique.” when calling object from class to build UI

python,user-interface,maya
The Problem: I don't get any syntax errors when i run the script up until i try to build the UI. Everything seems fine until i run the last 2 lines of code. I get the following error : Error: RuntimeError: file line 41: Object's name 'mst_txtfld_x_value' is not unique....

How to see all attributes of a node in Maya?

python,nodes,maya
I'm trying to update some attribute values in Maya via code and I'm having a really tough time accessing them. I need the attributes displayed name, (I'm pretty sure this is supposed to be their 'Nice Name'), but I can't seem to get them in any way. Using listAttr or...

Creating a video game in Maya for android

maya
I recently installed Maya for creating video games, and was wondering something. Can I create games in Maya, and run it on mobile devices?

Event in Maya Api to capture currentTime / frame change

c++,events,callback,message,maya
I am currently developing a Maya plugin. How can I set-up a callback that gets fired each time the frame number / current time is changed in the scene ? I had a look at the MSceneMessage Class, but it doesn't seem to contain what I am looking for....

Using keyframe() to display nested dictionary info using Python in Maya

python,animation,scripting,maya,keyframe
I need help doing the following: Using the keyframe method (and flags) to extract information from a selected set of keys to store them in a nested dictionary. These keyframes correspond to an animation that has the all the keyframes copied for pasting onto other joints as needed. I've been...

Delete all expressions in Expression editor

python,expression,maya
In this maya scene file of mine, when scrubbing through the time slider, I keep getting the following error: // Error: An execution error occured in the expression stabilizator_expression_mom_bq01_v2_original_2Shape6. // Upon opening the editor, this is the full error: # Error: line 0: No module named mmTools.v1_0.ford_stabilizerStereo # Traceback (most...

Maya Film Roll Matrix

python,matrix,maya
Does anyone know how to calculate maya's roll matrix with pivot (post projection matrix)? The best I can get at the moment is this: import math import maya.cmds as cmds import maya.OpenMaya as OpenMaya import maya.OpenMayaUI as OpenMayaUI # Get active view. view = OpenMayaUI.M3dView.active3dView() # Get camera MFnDagPath. dagCam...

how to save multi images by MEL command

python,maya,mel
I'm new to MEL script and working on dealing with batch render of massive files(over 10000) with MAYA, the basic prototype is like this: import maya.mel as mel import maya.cmds as mc mc.file("D:/render/abc.mb",i=True) mel.eval('RenderIntoNewWindow;') mc.renderWindowEditor('renderView' , e=True , wi='D:/render/abc') This is a simple script which contains three commands: import, render,...

When to use static and class methods

python,python-2.7,methods,maya
I know there is a lot of topics on this subject, and I've looked at many. However it is still confusing to me when its appropriate to use static and class methods in place of an instance method. In my example, I'm making a script for the autodesk program maya....

importing and renaming multiple objects in maya with python

python,maya
I am trying to import multiple object files in maya using python and use the file name as object name in maya. I have managed to import the objects, but I have only been able to use the file name as a namespace and not as a object name. import...

RuntimeError: deleteUI: Object 'Animation_Copy_Tool' not found

python,user-interface,runtime-error,maya
Getting this error when pressing the "Close Window" button in my UI. This button should delete the UI window but isn't. Full traceback: Error: deleteUI: Object 'Animation_Copy_Tool' not found. Traceback (most recent call last): File "", line 36, in closeBtnCmd RuntimeError: deleteUI: Object 'Animation_Copy_Tool' not found. # # Animation Copy...

IOError: [Errno 22] PyMel/ Python

python-2.7,maya,xlrd,xlwt,pymel
Good evening SE'ers, I've got a question that has been bugging me for the last twenty-four hours. I've read up on the issue and my issue seems to be just plain stupid. So, I must be doing something wrong. FIRST I'm using xlrd, xlwt and xlutils to create an excel...

Same python code works differently on differently Maya (2012 - 2015)

python,maya,maya-api
this simple code import maya.cmds as cmd circle1 = cmd.circle(nr=(0, 0, 1), c=(0, -1.1, 0), ch=1) circle2 = cmd.duplicate(circle1[0], ic=1) circle3 = cmd.duplicate(circle1[0], ic=1) cmd.setAttr(circle2[0] + '.rotateZ', 120) cmd.setAttr(circle3[0] + '.rotateZ', -120) allCurves = circle1[0], circle2[0], circle3[0] cmd.select(allCurves) cmd.makeIdentity(apply=True, t=1, r=1, s=1, n=0) works perfectly in Maya 2012, giving me...

python problems with super

python-2.7,pyside,maya,super
Ok so I'm having a bit of a problem with the code below. It works as is but if I try to change the part with the comment about me not being able to get super to work correctly to. pipeline_class_call = super(Error_Popup,self) broken_file_w_whats_wrong = pipeline_class_call.whats_wrong_with_file() or to broken_file_w_whats_wrong =...

Error: AttributeError: file line 65: 'OptionsWindow' object has no attribute 'int_offset' #

python,maya,attributeerror
I'm getting this error for line 65 of my Python code in Maya within the pasteTheseKeys method: self.offsetVal = mc.intFieldGrp(self.int_offset, q=True, value1=True) pasteTheseKeys is called when the "Paste Keys" button is pressed. That relationship is defined in the commonButtons method. The complete code: # Animation Copy Tool # Bakari Holmes...

Incremental Saves

python,save,maya
I am trying to write up a script on incremental saves but there are a few hiccups that I am running into. If the file name is "aaa.ma", I will get the following error - ValueError: invalid literal for int() with base 10: 'aaa' # and it does not happens...

Maya PySide: Maya crashes when I try to connect custom signal to slot

qt,signals,pyside,maya,slot
I'm about 2 weeks into PySide and I'm loving it, but I'm having trouble understanding some of the more intermediate concepts. Any help would be greatly appreciated. I'm trying to get a few custom QEvents working in PySide with QLineEdit and QCompleter. I'm using the old style for signal/slot connections...