ScriptSpot

Forum topic · Scripts Wanted

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

By DotScott1 · 2015-03-05

Description

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 (4)

barigazy · 2015-03-05

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_"

DotScott1 · 2015-03-05

: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 · 2015-03-05

;)

You're welcome
Enjoy

DotScott1 · 2015-03-05

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
)

)