request for script to create layer from object name.

hi, is it possible to have a script which creates a layer from an object name.

there is a script here which creates a layer from material name.i cannot find it on the site any more so i am attaching the script below

for m in scenematerials do
if LayerManager.getLayerFromName == undefined
then NewLayer = LayerManager.newLayerFromName
else NewLayer = LayerManager.getLayerFromName
for obj in objects do if == do NewLayer.addNode obj
saveMaxFile (getfilenamefile (maxfilename) + "_for_Revit.max") useNewFile: true

Thanks in advance to anyone who can help me.

material2layer.ms369 bytes


ricozone's picture

Object to Layer

I needed it too. I made one with few options.

- For each object put it on a layer with the object's name.
- Works on selection or on all scene objects.
- Objects are filtered by "Geometry" class (only primitive, mesh, poly).
- Groups are processed as an object (layer name = group name), put all group's children in this layer.

Hope this helps

obj_arr = #()
-- collect object(s) to process
if selection.count == 0 then obj_arr = for o in geometry collect o	-- on all scene objs (only geometry obj, no shape, cam, light, dummy ...)
if selection.count != 0 then for o in selection do append obj_arr o	-- on obj(s) selection
if obj_arr.count != 0 then (
	for o in obj_arr do
		n =
		-- objects in group
		if (isGroupMember o AND classof o != Dummy) then (		-- if current obj is in a group AND is not a parent group (groupHead)
			n =	-- then get his parent name as layer name
			appendIfUnique obj_arr o.parent	-- add parent group to layer
		)--end if
		if LayerManager.getLayerFromName n == undefined			-- IF layer's name does not already exist
			then NewLayer = LayerManager.newLayerFromName n	-- THEN create a new layer with the object's name
		else NewLayer = LayerManager.getLayerFromName n			-- ELSE get the layer already named with object's name			
		NewLayer.addNode o
	)-- end loop
)else( messagebox ("no object to process !") )--end if