Hey guys, I'm working on creating generic functions that are flexible and can
be called from my other scripts. However, I feel like I use a lot more code
that necessary, I have 12 if-conditions just in this little script that I've
attached.
The attached script is a function that reads all the objects I define as
inputs, then checks if they match the specified objectType, and then returns
the objects that match the objectType specified.
I was hoping someone could take a quick look and see if things could be done in
a better way :)
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
#FUNCTION: GET SELECTION OF SPECIFIED TYPE
def getObjType(objects=[], objType='', returnType=1, selection=0, checkShape=1):
#--DESCRIPTION-----------------------------------------------------------------------------------
# Return the selected/passed in objects of the specified type. If
returnType is set to 0 it will
# return the transform of the objects, if it's set to 1 the shape will be
returned.
#--EXAMPLES--------------------------------------------------------------------------------------
# utilities.getObjType(objType='nurbsCurve', returnType=1, selection=1,
checkShape=1)
#------------------------------------------------------------------------------------------------
try:
#If selection was enabled
if selection == 1:
#Get the selected objects
objects = pm.selected()
#If selection was disabled
if selection == 0:
#Add a PyNode to the input objects
objects = map((lambda x: pm.PyNode(x)), objects)
#Create a variable for the resulting objects of the specified type
results = []
#For each object
for obj in objects:
#If it should search the shapes of the input-objects also
if checkShape == 1:
#If the objType matches the shape or the selection
if objType in obj.type() or objType in obj.getShape().type():
#If the returnType is set to return the transform-node
if returnType == 0:
#If the current input object is a shape
if objType in obj.type():
#Append the transform of the shape to the result
results.append(obj.getParent())
#If the current input object is a transform
if objType in obj.getShape().type():
#Append the current element to the result
results.append(obj)
#If the returnType is set to return the shape-node
if returnType == 1:
#If the current input object is a shape
if objType in obj.type():
#Append the current element to the result
results.append(obj)
#If the current input object is a transform
if objType in obj.getShape().type():
#Append the shape of the current element to the
result
results.append(obj.getShape())
#If checkShape is False
if checkShape == 0:
#If the objType matches the selection
if objType in obj.type():
#Append the object to the result
results.append(obj.getShape())
#Return the result
return results
except:
pass