THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED
On 02/03/2012 at 09:51, xxxxxxxx wrote:
Hi all.
This is my first post here. I've tried on and off again to begin coding, never being able to get over that first major hump. I've finally been able to put together some code well enough that I can start to ask advice without feeling like I'm goin' "deeerp, how you do code?!?!"
Now, This code is from a R12 python node in XPresso. It is functional, but probably pretty damn ugly. It would be great if someone could look it over and say "This huge chunk could have been this one line dummy!" Or "Why would you even DO that?"
Its function is to take an input 'link' and return the total poly count of the objects entire hierarchy, be they prim, generated, or whatever.
import c4d
#Welcome to the world of Pythondef polyCheck(op) : # successfully gets polys from poly prims, and polygon objects. Ignores splines and nulls. probably pretty clunky
if c4d.C4DAtom.GetType(op) == 5100:
print op.GetName() + " Poly"
return op.GetPolygonCount()
elif op.GetCache() != None and (op.GetRealSpline()) == None:
print op.GetName() + " non-poly poly"
return op.GetCache().GetPolygonCount()
elif op.GetCache() != None and (op.GetRealSpline()) != None:
print op.GetName() + " spline"
return 0
else:
print "none"
return 0def addition(tempCount,op,placement) :
print "#" + str(op.GetName()) + " polycount of " + str(tempCount) + " runs at " + str(placement)def count(op,base,tempCount) : #Runs through hierarchy, real ugly I bet.
print "-----New 'def count'-----"while (op.GetDown() != None) and (op != base) :
tempCount = tempCount + polyCheck(op)
addition(tempCount,op,1)
op = op.GetDown()
if op.GetDown() == None and (op != base) and op.GetNext() == None:
tempCount = tempCount + polyCheck(op)
addition(tempCount,op,2)
if op.GetNext() != None and (op != base) :
tempCount = tempCount + polyCheck(op)
addition(tempCount,op,3)
op = op.GetNext()
if op.GetNext() == None and (op != base) and op.GetDown() == None:
tempCount = tempCount + polyCheck(op)
addition(tempCount,op,4)
tempCount = count(op,base,tempCount)else:
if op.GetNext() == None and op.GetDown() == None and op.GetPred() == None and op.GetUp() == base:
tempCount = tempCount + polyCheck(op)while op.GetNext() == None and (op != base) :
op = op.GetUp()if op.GetNext() != None and (op != base) :
op = op.GetNext()
if op.GetNext() == None and op.GetDown() == None:
tempCount = tempCount + polyCheck(op)
tempCount = count(op,base,tempCount)
else:
tempCount = count(op,base,tempCount)print str(tempCount) + " COUNT5"
return tempCountdef main() :
global PolyCount #for Output
tempCount = 0
PolyCount = 0 #from inputif ConnectObject.GetDown() == None:
PolyCount = PolyCount + polyCheck(ConnectObject)
else:
PolyCount = count(ConnectObject.GetDown(),ConnectObject,tempCount)
PolyCount = PolyCount + polyCheck(ConnectObject)
print PolyCount
print "--Done--"
Thanks in advance for any advice on cleaning this up. I'm excited to finally be able to post something!
Chris Schmidt