ScriptSpot home

Forum topic · Scripts Wanted

request for script to create layer from object name.

By damien11235 · 2013-06-27

Description

hi,

would love to have a script to create a layer from object name.
would be usefull for scenes linked to 3dsmax from revit.

Comments (12)
Tom

Awesome :)

Thax miauu!!!
Ive searched for this everywhere and here you are with the perfect solution :)
You just saved me a ton of time trying to redistribute hundreds of objects to individual layers :)

Is it possible to get this function to work for groups as well? I tried but Im a no-good scripter so it failed.

Wilalbert Gomez

Very appreciated!

It's fenomenal to see how much interest on the people involved on programming stuff!. Nice scripts miauu!. Keep going!

miauu

As is written in the script body - uncommend 2 lines




(
	if selection.count != 0 do
	(
		for o in selection do
		(
			objName = o.name
			if (objLayer = LayerManager.getLayerFromName objName) == undefined then
			(
				objLayer = Layermanager.newLayerFromName objName
	 			objLayer.addNode o
			)
			else
			(
				objLayer.addNode o
			)
		)
	)
)
damien11235

hi thanks a lot,

i need the script to create the layer from the object name and put the object in that layer too. :)

miauu

It is easy to works for multiple objects, but what do you want the script to do - only to create empty layers with the same name as the object's name, or th crete layers and to put the objects in its layer?
Anyway:



(
	if selection.count != 0 do
	(
		for o in selection do
		(
			objName = o.name
			if (objLayer = LayerManager.getLayerFromName objName) == undefined then
			(
				objLayer = Layermanager.newLayerFromName objName
				--	uncomment the line below to add object to the layer
	-- 			objLayer.addNode o
			)
			else
			(
				--	uncomment the line below to add object to the layer
	-- 			objLayer.addNode o
			)
		)
	)
)
damien11235

hi,

thanks a lot for the same. is it possible to have the script take multiple objects and do the same instead of one at a time.

there is another script which does it for materials

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

would be great to have something which is automated like the one above.

thanks a ton in advance.

miauu

;)


(
	if selection.count == 1 do
	(
		objName = selection[1].name
		if (objLayer = LayerManager.getLayerFromName objName) == undefined then
		(
			objLayer = Layermanager.newLayerFromName objName
			--	uncomment the line below to add object to the layer
-- 			objLayer.addNode selection[1]
		)
		else
		(
			--	uncomment the line below to add object to the layer
-- 			objLayer.addNode selection[1]
		)
	)
)
Reply to miauu
Invite

Not working for Max 2019

I'm getting an error when using the script in Max 2019

-- Error occurred in anonymous codeblock; filename: ; position: 421; line: 17
-- Syntax error: at ), expected
-- In line: )

Anyone have a solution for this?

Reply to Invite
miauu

.

Can you post the code that not works for you?

I have tested this code in 3ds max 2019 and there are no errors at all.



(
	if selection.count == 1 do
	(
		objName = selection[1].name
		if (objLayer = LayerManager.getLayerFromName objName) == undefined then
		(
			objLayer = Layermanager.newLayerFromName objName
			--	uncomment the line below to add object to the layer
			objLayer.addNode selection[1]
		)
		else
		(
			--	uncomment the line below to add object to the layer
			objLayer.addNode selection[1]
		)
	)
)
Reply to miauu
Invite

The error seems to occur when I've selected multiple objects. With a single object selected it works fine.

Reply to Invite
miauu

.

This should work with selection of objects:




(	
	if selection.count != 0 do
	(
		for o in selection do
		(
			objName = o.name
			if (objLayer = LayerManager.getLayerFromName objName) == undefined then
			(
				objLayer = Layermanager.newLayerFromName objName
				--	uncomment the line below to add object to the layer
				objLayer.addNode o
			)
			else
			(
				--	uncomment the line below to add object to the layer
				objLayer.addNode o
			)
		)
	)
)
Reply to miauu
Invite

Yes, it works perfect now! Thanks for fixing the script!