PDA

View Full Version : [Python]Select objects/group change render stats


Darius1989
07-28-2012, 02:02 PM
Heya

Simple issue. I create render layer make it active add objects - all work fine - and want to change primary visibility of all or selected objects - and other options later - and I cant get it to work with groups... - not get the rename function to work :/

here are my tries.... any1 can help please?

cmds.select(all=True,hierarchy=True)
meshShape = cmds.ls(selection=True)
for i,shape in enumerate(meshShape):
if not cmds.nodeType(shape) =='transform':
objectTransform = cmds.listRelatives(shape, p=True)
else:
objectTransform = shape
if objectTransform:
cmds.setAttr('%s.%s'%(objectTransform,primaryVisib ility), 0)


#test 2

cmds.select(all=True,hierarchy=True)
meshShape = cmds.ls(selection=True)
for i,shape in enumerate(meshShape):
if not cmds.nodeType(shape) =='transform':
objectTransform = cmds.listRelatives(shape, p=True)
else:
objectTransform = shape
if objectTransform:
cmds.setAttr('%s.'%(objectTransform),primaryVisibi lity, 0)

I'm trying to get the name of object and .primaryVisibility it but cant get it to work either way :/

DrWeeny
07-29-2012, 12:31 AM
Hi,

Maybe you can try this :

import maya.cmds as cmds

myGroupSel = cmds.ls(sl=True, dag=True, s=True)

for invisible in myGroupSel:
cmds.select(invisible, r=True)
cmds.setAttr(".primaryVisibility", 0)

Hope it will help.

djx
07-29-2012, 07:02 AM
I'd prefer to do it without having to select each object.

objs = cmds.ls(sl=True, dag=True, shapes=True)
for o in objs:
t = cmds.listRelatives(o, parent=True)
cmds.setAttr(t[0] + '.v', 0)


And I'd probably use pymel instead
objs = pm.selected(dag=True, shapes=True)
for o in objs:
o.getParent().v.set(0)

David

DrWeeny
07-29-2012, 12:52 PM
I would use this.
In case you don't select a group.

--- EDIT ---
I switch
objs = cmds.ls(sl=True, dag=True, s=True)
by
objs = cmds.ls(sl=True, dag=True, g=True)
in case you have lights or something without .primaryVisibility attribute in your group


import maya.cmds as cmds
objs = cmds.ls(sl=True, dag=True, g=True)

for invisible in objs:
t = cmds.ls(invisible)
cmds.setAttr(t[0] + '.vis', 0)

Hope it will suit more to master DJX ^^

djx
07-29-2012, 01:04 PM
I'm not sure what you mean. In my (and your) example objs will be a list of just shapeNodes, whether you select a group, a transform or a shapeNode.

In your example the line "t = cmds.ls(invisible)" is redundant. If you want to set the visibility attribute ('.v', or '.visibility', not '.vis') on the shapeNode (I wouldnt normally do it that way, but you may want to for some things), then your code could just be

for invisible in objs:
cmds.setAttr(invisible + '.v', 1)

Maybe I misunderstood what you were suggesting though.

David

edit: ah, you changed it. :) ok. That assignment to t is still not needed though.

DrWeeny
07-29-2012, 01:20 PM
I'm trying to get the name of object and .primaryVisibility it but cant get it to work either way :/

I think he is seeking to turn .primaryVisibility off
".v" is short name for ".visibility", isn't it ?

(I wouldnt normally do it that way, but you may want to for some things), then your code could just be

for invisible in objs:
cmds.setAttr(invisible + '.v', 1)

It appears to me too but I tried your solution and it return me an error :/
So I used instead the "t = cmds.ls(invisible)"

Have a nice week-end.
Alexis

Darius1989
07-29-2012, 02:16 PM
Heya

Aww thanks every1 for such great help !!!

And aww again for making my approach over complicated lol... I thought I had to select all objects like in spread sheet and then I can edit render stats bah... clever me for going nuts...

DrWeeny - on quick test scene this seem to work I gotta work around it just to be sure it works in my set up - thanks !!!

djx - you never stop on amazing me, now I gotta scratch my head and understand what you write here hehehe ^^ good times.

I'm trying to access render stast, will be changing shadows, reflection and other parametrs too !


Will work on it and let you know later on progress :)

CGTalk Moderation
07-29-2012, 02:16 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.