Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Pass a value?

Pass a value?

Anonymous
Not applicable
317 Views
2 Replies
Message 1 of 3

Pass a value?

Anonymous
Not applicable
Lads,

If I select a cube, how do I then feed that cubes name into my Python script for processing? (I have to perform numerous repetitive functions on 50 cubes). I'd like to be able to select a cube, hit my Python button, and move onto selecting the next cube.

Thanks,

S
0 Likes
318 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
You don't even need to select the next cube. You could select all the cubes and run your script once.

I use pymel, but you could easily replace my "pm." with "cmds." if you prefer


# Gather the list of what is selected.
# This doesn't check to verify your selection type,
# so the script will probably error if you have nothing
# or the wrong things selected.

mySelection = pm.ls(sl=True)

for s in mySelection:
# insert the code you'd like to run here.
# Example is to change the scaleX to 2:
pm.setAttr( (s + '.scaleX'), 2 )



Alternatively, you could put all your code into another function:



def myCubeFunction(selectedCube):
# This is where your code goes.
# The variable "selectedCube" is being sent from the
# "for" loop below, so every time your loop reaches the
# next item in the list, it runs the function on that cube.
# Example is to change the scaleX to 2:
pm.setAttr( (selectedCube + '.scaleX'), 2 )

mySelection = pm.ls(sl=True)

for s in mySelection:
myCubeFunction(s)
0 Likes
Message 3 of 3

Anonymous
Not applicable
You don't even need to select the next cube. You could select all the cubes and run your script once.

I use pymel, but you could easily replace my "pm." with "cmds." if you prefer


# Gather the list of what is selected.
# This doesn't check to verify your selection type,
# so the script will probably error if you have nothing
# or the wrong things selected.

mySelection = pm.ls(sl=True)

for s in mySelection:
# insert the code you'd like to run here.
# Example is to change the scaleX to 2:
pm.setAttr( (s + '.scaleX'), 2 )



Alternatively, you could put all your code into another function:



def myCubeFunction(selectedCube):
# This is where your code goes.
# The variable "selectedCube" is being sent from the
# "for" loop below, so every time your loop reaches the
# next item in the list, it runs the function on that cube.
# Example is to change the scaleX to 2:
pm.setAttr( (selectedCube + '.scaleX'), 2 )

mySelection = pm.ls(sl=True)

for s in mySelection:
myCubeFunction(s)

0 Likes