Script to Auto-Organize Objects into Layers by Poly Count.

Hello,

So... I'm trying to figure out the best way to organize objects in a scene into layers by their poly counts and then name those layers according to their poly counts.

So all objects that have 10 polygons would go into a layer called "PolyCount_010", objects that have 592 polygons would go into a layer called "PolyCount_592", etc.

Does anyone know of a script that can do this? Or at least maybe the best way to go about it?

Any help would be GREATLY appreciated!

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
barigazy's picture

...

Is this fn that you looking for?

fn organizeObjs objs layerName: =
(
	local getLayByName = LayerManager.getLayerFromName
	local newLayByName = LayerManager.newLayerFromName
	for o in objs where canconvertto o Editable_mesh do
	(
		name = layerName + formattedPrint (getPolygonCount o)[1] format:"0.3d"
		layer = if (lay = getLayByName name) != undefined then lay else newLayByName name
		layer.addnode o
	)
)
organizeObjs objects layerName:"PolyCount_"

barigazy

DotScott1's picture

:o .... You're a Script-God

:o .... You're a Script-God among men. This is _exactly_ what I was looking for. A thousand thank you's, barigazy. This is amazing.

barigazy's picture

...

;)

You're welcome
Enjoy

barigazy

DotScott1's picture

Here are some useful bits of script

Here are some useful bits of script that I have found so far (that other users have put together) to select objects with certain vert counts:

By User: Anubis
To select objects with more then 32000 vertices:

select (for o in geometry where \
(getPolygonCount o)[2] >= 32000 collect o)

By User: miauu
To select objects with more then 32000 vertices:

select (for o in geometry where ( o.numverts >= 32000) collect o)

By jkwiatkowski
To select objects with poly count lower than...:

fn selectByPolygonCount arrayOfNodes numFaceFrom numFaceTo = (

--clear selection
clearSelection()

--loop through array of nodes
for obj in arrayOfNodes do
(
tmpArr = getPolygonCount obj
numFaces = tmpArr[1]
if numFaces >= numFaceFrom and numFaces <= numFaceTo do selectMore obj
)

)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.