Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
256 views
in Technique[技术] by (71.8m points)

list - setAttr Visibility of several Shapes leads to an error only for Circle Shapes

I am currently working on an automated rig script and I faced an issue I cannot understand. Here is the simplified part of the code I'm looking a solution for :

import pymel.core as pm

ik_box = pm.curve(n='ik_arm_box_curve', d=1, p=[(1, 1, 1),(1, 1, -1),(-1, 1, -1),(-1, 1, 1),(1, 1, 1),(1, -1, 1),(1, -1, -1),(1, 1, -1),(-1, 1, -1),(-1, -1, -1),(1, -1, -1),(-1, -1, -1),(-1, -1, 1),(-1, 1, 1),(-1, -1, 1),(1, -1, 1)], k=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])
pm.setAttr(ik_box + 'Shape.v', 0)

ik_circle = pm.circle(n='ik_arm_circle_curve', c=(0,0,0), nr=(1,0,0), r=2)
pm.setAttr(ik_circle + 'Shape.v', 0)

The thing I cannot understand here is that the setAttr works properly with my ik_box but with the circle it gaves me this error :

TypeError: can only concatenate list (not "str") to list

? So why is it working with my ik_box and then it considers my ik_circle as a list ?

Knowing that I'm making my own script based on this very useful tutorial : https://youtu.be/zA9lz8-1uQ4?t=526

(You can pause immediatly and see in the bottom of the code that he creates the shapes and then edit their visibility the way I did, and everything works fine for him)

? So then I tried to print these ik_circle elements to see what it means:

ik_circle = pm.circle(n='ik_arm_circle_curve', c=(0,0,0), nr=(1,0,0), r=2)    
print(ik_circle[0])
print(ik_circle[1])

And it gaves me ik_arm_circle_curve and makeNurbCircle2.

? From there, I found out the "constructionHistory(ch)" flag and applied it:

ik_circle = pm.circle(n='ik_arm_circle_curve', c=(0,0,0), nr=(1,0,0), r=2, ch=0)    
print(ik_circle[1])

? Fine, it's out of range, there's no more list.

ik_circle = pm.circle(n='ik_arm_circle_curve', c=(0,0,0), nr=(1,0,0), r=2, ch=0)
pm.setAttr(ik_circle + 'Shape.v', 0)

TypeError: can only concatenate list (not "str") to list

? Here we go again.. A list with only one element inside of it.

I am fairly new to python, I probably miss some fundamentals, but if you have any advice or explanation I would appreciate.

question from:https://stackoverflow.com/questions/65845605/setattr-visibility-of-several-shapes-leads-to-an-error-only-for-circle-shapes

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...