same height obj to each layer

hello
always thank you for helping ~

pls can you help me again

there is objs

i would like to send layer with there height

if objs have 100 cm height -> i would like to send objs to 100cm layer
if objs have 200 cm height -> i would like to send objs to 200cm layer

....
...
...

new layer creation by each obj height

is that possible ?

Comments

Comment viewing options

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

.

a little bit more universal version

(
	STEP = 10 -- units of object height
 
	/* example test scene */
	delete objects
	for i=1 to 100 do box pos:(random [-100,-100,0] [100,100,0]) height:((random 1 5)*STEP) width:5 length:5
	for o in objects do o.height += random -0.1 0.1
	/* example test scene end */
 
 
	-- 1. Collect objects by height
	layers = #()
	for obj in objects do (
 
		index = floor (abs ((obj.max-obj.min)[3] / STEP ) + 0.5)
 
		if layers[ index ] == undefined then layers[ index ] = #( obj ) else append layers[ index ] obj
 
	)
 
	-- 2. Put them to according layers
	for i=1 to layers.count where iskindof layers[i] array do (
 
		layer_name = (((int i)*STEP) as string + " cm")
 
		layer = LayerManager.getLayerFromName layer_name
		if layer == undefined do layer = LayerManager.newLayerFromName layer_name
 
		for obj in layers[i] do layer.addNode obj
 
	)
 
)
dussla's picture

perpect ~

that is code wanted
perpect ~~ perpect~~~

miauu's picture

.

To works properly the Display Unit Scale and System Unit Scale must be set to Centimeters.

(
	layer100cm = layerManager.getLayerFromName "100 cm"
	if layer100cm == undefined do layerManager.newLayerFromName "100 cm"
 
	layer200cm = layerManager.getLayerFromName "200 cm"
	if layer200cm == undefined do layerManager.newLayerFromName "200 cm"
 
	for o in objects do
	(
		oHeight = (o.max.z - o.min.z)
 
		if oHeight > 99.99 and oHeight < 100.01 do
		(
			layer100cm.addNode o
		)
		if oHeight > 199.99 and oHeight < 200.01 do
		(
			layer200cm.addNode o
		)
	)
)
dussla's picture

really thank you

that is good code also

really really thank you ~~~

Comment viewing options

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