Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Creating sublayers from a string of text?

Creating sublayers from a string of text?

roger.olofsson
Enthusiast Enthusiast
1,989 Views
4 Replies
Message 1 of 5

Creating sublayers from a string of text?

roger.olofsson
Enthusiast
Enthusiast

Hi,

 

How are sublayers done with script?

 

If I have string "House_FirstFloor" I want to create a layer called FirstFloor as a sublayer of layer "House".

 

If I have string "House_FirstFloor_Doors" I want to create a layer called Doors as a sublayer of layer "FirstFloor".

 

and so on....

 

Can't find information on creating sublayers.

 

Roger,

0 Likes
Accepted solutions (1)
1,990 Views
4 Replies
Replies (4)
Message 2 of 5

kevinvandecar
Community Manager
Community Manager

Hi,

 

I do not think you can create layers, but I am not a strong MAXScript user. I see that the Layers are managed by the Scene Explorer - Layer Explorer. Scene explorers are accessible through the SceneExplorerManager. Here you can get the layer explorer like:

SceneExplorerManager.GetExplorer "Layer Explorer", but the returned interface seems to only manage UI aspects.

 

Other than that, I do not find any other connection in MAXScript to layers per the docs. Did you manage to be able to create layers in general? that might give me additional clues to finding more. 🙂

 

Anyone else out there have any thoughts?

 

thanks,

kevin

 

 


Kevin Vandecar
Developer Technical Services
Autodesk Developer Network



Message 3 of 5

Swordslayer
Advisor
Advisor
Accepted solution

Here you go, supposing the Doors layer doesn't exist yet:

 

fn createLayerFromString layerName objs =
(
	local tokens = filterString layerName "_"
	local layer = layerManager.newLayerFromName tokens[tokens.count]
	for obj in objs do layer.addNode obj

	while (deleteItem tokens tokens.count).count > 0 do
	(
		local parentName = tokens[tokens.count]
		local parent = layerManager.getLayerFromName parentName
		if parent == undefined do parent = layerManager.newLayerFromName parentName

		layer.setParent parent
		layer = parent
	)
)

 

Example usage:

 

createLayerFromString "House_FirstFloor_Doors" (getCurrentSelection())

Note that you actually cannot have House_SecondFloor_Doors in addition to this, as all the layer names have to be unique - the layer system is still flat as it used to be, it's only the way of displaying it and setting additional properties to the layers themselves (what layer is their parent layer) that's different. So if you'd have for example House1_FirstFloor_Doors, for another house the to parts following the house identifier would have to be changed, so for example House2_FirstFloor-2ndHouse_Doors-2ndHouse-1stFloor or just House2_FirstFloor-2_Doors-2-1.

Message 4 of 5

kevinvandecar
Community Manager
Community Manager

Great! Thanks Vojtech. I did not find the Layer Manager easily... looks like docs indexes it pretty deep when searching. Anyway, it appears to work well for me.

 

FYI, the docs are here in case there is more info needed. It uses a parent/child system to organize the layers as sub-layers.

 

http://help.autodesk.com/view/3DSMAX/2017/ENU/index.html?guid=__files_GUID_78B79975_7BA5_4A03_8FEF_2...

 

thanks,

kevin

 


Kevin Vandecar
Developer Technical Services
Autodesk Developer Network



0 Likes
Message 5 of 5

roger.olofsson
Enthusiast
Enthusiast

Hi, Vojtech

 

Thank you so much, that saved me lots of trial and error.

Also about the layer names, I have noticed that when I have reated layers manualy but I am sure I would have missed it here.

 

Do you know how this would work when Xrefing in files. If the layer doors exist in two files that are xrefed in to one scene? I will give that a try and see how it works.

 

Thanks again,

Roger

0 Likes