cmds to pymel

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

 
Thread Tools Search this Thread Display Modes
  08 August 2014
cmds to pymel

Select objects, select shading groups, run.
This code is working:

import random as rand
import maya.cmds as cmds
geometry = cmds.ls(dag = 1, objectsOnly = 1, shapes = 1, selection = 1)
shaders =  cmds.ls(sl = 1, type='shadingEngine')

for i in geometry:
    rnd = rand.randint(0,(len(shaders)-1))
    cmds.sets(i, e = 1, forceElement = shaders[rnd] )


This dont:

import pymel.core as pm
import random as rand

geometry = pm.ls(dag = 1, objectsOnly = 1, shapes = 1, selection = 1)
shaders =  pm.ls(sl = 1, type='shadingEngine')

for i in geometry:
    rnd = rand.randint(0,(len(shaders)-1))
    pm.sets(i, e = 1, forceElement = shaders[rnd] )

Why?
__________________
3D animation blog

Last edited by kiryha : 08 August 2014 at 04:51 PM.
 
  08 August 2014
try this

import pymel.core as pm
import random

geo = pm.ls(sl=True, dag=True, objectsOnly=True, shapes=True)
shaders = pm.ls(sl=True, type='shadingEngine')

for i in geo:
	rnd = random.randint(0, len(shaders) - 1)
	print type(shaders[rnd])
	pm.sets(shaders[rnd], e=True, forceElement=i)
__________________
Twitter - GitHub
------------------
My Scripts - Maya tools and workflow scripts
psLink - Maya PhotoShop intergration.
 
  08 August 2014
Oh, thanks!
__________________
3D animation blog
 
  08 August 2014
Yeah, pymel way is more logical to me. And you dont need the e=True in most pymel methods since it is implied. So this will also work...

pm.sets(shaders[rnd], forceElement=i)

David
__________________
http://www.djx.com.au
 
reply share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:27 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.