I'm a bit new in scripting and french so exuse me if my explanations are not perfectly clear.
I'm trying to make a script in Maya to manage easily the keys value for animation.
So I created a window reproducing Maya's ChannelBox with another organisation.
And now I'm trying to get the attribute values of a selected object inside the different textField (transX, Y, Z, rotX..).
Here is what I have for now :
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("%s.translateX" %selected) )
But when I select my cube for tests and launch my script this error appears:
TypeError: Object [u'pCube1'].translateX is invalid
So I tried something like this to see if the problem is coming from my formulation:
transX_value = cmds.textField( w=100 , h=22 , tx= cmds.getAttr("pCube1.translateX") )
It worked and printed the good value inside the textField.
How can I call the attribute of any selected object? I just discovered the %s command, so I'm sure that I'm not using it right.
That's a very common mistake. Your 'selected' variable holds a list, not a string. You should get the first list value instead, so just change your code like that:
transX_value = cmds.textField(w=100, h=22, tx=cmds.getAttr("%s.translateX" % selected[0]))
Related
enter image description here
In the case of the pycharm, it doesn't show any output.
I used "print()" already. But, Pycharm is showing the <numpy.vectorize object at 0x0000022CF6EDDFA0>.
"aa" in your code is a vectorized function object.
Like any other function or object, when you do print(aa), you aren't calling it. Similarly, if you write print(len), you get basic description of the function len: <built-in function len>. In order to actually call it, it needs to be followed by brackets. For example: print(len('hello'))
In your code, you probably need print( aa([1,2,3,4], 2) )
I am trying create a node and set a value using this function:
def createTextureNode(textureNode):
keyword = textureNode
for fname in os.listdir(assetFilePath):
if keyword in fname:
texFilename = fname + ".tex"
newTexNode = NodegraphAPI.CreateNode("PrmanShadingNode", rootNode)
newTexNode.getParameter('name').setValue(assetCode + '_' + textureNode, 0)
newTexNode.getParameter('nodeType').setValue("PxrTexture", 0)
newTexNode = NodegraphAPI.GetNode(assetCode + '_' + textureNode)
if textureNode == "Albedo":
newTexNode.getParameter("parameters.linearize.enable").setValue(True,0)
newTexNode.getParameter("parameters.linearize.value").setValue(True,0)
Its pretty simple, if a particular file exists it will create a node for it. However, I am unable to set the "linearize" value (or any other value under the "parameters" group)
If I manually create a node and manually set it to be a PxrTexture and use this code:
node = NodegraphAPI.GetNode("PrmanShadingNode")
node.getParameter("parameters.linearize.enable").setValue(1,0)
node.getParameter("parameters.linearize.value").setValue(1,0)
Then it works, the check box turns on, but if I set the nodeType via script then it fails. But if I run it a second time it works! The error I keep getting is:
AttributeError: 'NoneType' object has no attribute 'setValue'
I know this means that its returning "None" but the tool tip in Katana says that its "parameters.linearize" and the first two parameters were able to be set... but these are under a Group, I think?
Since it works with the manual create, it must be something I am missing in my script, but I can not figure it out. I have also tried using finalizeValue after setting my nodeType but his has no affect
I am using this as my reference:
Getting and Setting Parameters
GOT IT!
When setting a Dynamic Parameter Pragmatically, you have to run checkDynamicParameters() after you set the value that makes the new parameters appear
This updates the UI Loop and makes the new parameters available. When doing this via the UI, it happens on the fly, and thats why it works when doing it manually
ANSWER REFERENCE
Whenever I try this:
x = input(foo)
showstat(x)
def showstat(y):
print(y.thing)
It comes back as an error
'str' object has no attribute 'thing'
but I don't know how to change it's data type in order to make it function properly.
I just need to figure out how to make it read as:
print(foo.thing)
rather than the error:
print("foo".thing)
It sounds like you are trying to evaluate the input as a python expression so you can retrieve the variable with the name entered. Is this correct?
If so you can use
eval(x)
though safer would be something like
locals()[x]
I would personally do this to your input, not as part of the function, but it depends on exactly what else you're trying to do.
I am attempting to use a module called interface.py which defines a list of conditions and a few functions to check arguments against those conditions. There are many thousands of conditions however, and so I want to use a dictionary instead of a list to prevent needing to look at all of them. To do this I'm using the following code:
def listToDictionary(list):
"""This function takes a list of conditions and converts it to a dictionary
that uses the name of the condition as a key."""
d = {}
for condition in list:
if condition.name.lower() not in d:
d[condition.name.lower()] = []
d[condition.name.lower()].append(condition)
return d
conditionList = listToDictionary(conditions.list) #the condition list comes from another module
Further into the file are the actual interface functions that take arguments to compare with the list of conditions - these functions are written assuming that conditionList will be a dictionary.
Unfortunately this isn't working. Giving error details is difficult because this code is being imported by a django page and I am trying to avoid talking about django so this question stays uncomplicated. Essentially the pages including this code will not load, and if I change it back to just using a list everything works fine.
My suspicion is that the problem has to do with how Python treats import statements. I need the listToDictionary conversion to run as soon as interface.py is imported, otherwise the interface functions will expect a dictionary and get a list instead. Is there any way to ensure that this is happening?
An educated guess: the list in conditions.list is not yet fully constructed when your module is being imported. As a result, you get a dictionary that is missing some entries or even empty, which is causing problems later. Try deferring the construction of the dict, like this:
conditionTable = None # shouldn't call it list if it's a dict
def get_cond_table():
global conditionTable
if conditionTable is None:
conditionTable = listToDictionary(conditions.list)
return conditionTable
Instead of referring to conditionList in your functions, refer to get_cond_table().
Alright, I found out that the problem was in another function that was still expecting the dictionary to be a list. The reason I couldn't see it right away is that Django left a very cryptic error message. I was able to get a better one using python manage.py shell and importing the module manually.
Thanks for your help everyone.
So I'm learning python, and I seem to be having a consistent problem with calling setText() methods on Text objects. The process works fine when I'm in the interactive IDLE GUI, but when I save modules and then try to run them, I get:
nonetype object has no attribute setText
Do I need to assign some sort of return type to the text assignment? Why would there be different behavior from IDLE to saved modules? I've searched the site and Python documentation and was unable to turn up anything. Any help would be much appreciated.
message1 = Text(Point(50,50), "Click).draw(win)
message1.setText("")
Edited to add…
Thanks Geo, your suggestion fixed things.
Now my question is, what's the difference between...
message = Text(Point(50,50), "Click").draw(win)
… and …
message = Text(Point(50,50), "Click")
message.draw(win)
… with regards to returning something, or ensuring that the message object has a type that supports certain functions?
Perhaps the draw method is not returning anything. Try changing your code to this:
message1 = Text(Point(50,50), "Click")
message1.draw(win)
message1.setText("")
I'm not sure how to answer your second question properly..so I'll just do it as an answer here.
The reason the first does not work is because you are assigning the return value of Text.draw to message. Since it returns nothing, then message is None.
In the working code, you assign message with the type Text and initialize the object. You then call the draw method of this object, and the setText method.
In the non-working code, you are calling the draw method on a new Text object, then assigning the return of that - that is, NoneType - to message. And since None has no setText method, you get an error.
(Sorry if I have mixed up NoneType and None there)