[Python]Select objects/group change render stats

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…

here are my tries… any1 any 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,primaryVisibility), 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),primaryVisibility, 0)