Notifications
Clear all

[Closed] Get layer list to txt file

Hello

I need to get a list of the layer names in a txt file so i can rename my render outputs.

My workflow, to whom is concerned, is to render multiple objects or sets.
For that, i have placed each set in different layer and i have animated them to get in front of the camera in one frame and leave again in another.
That way, i render an animated sequence, each frame for a set.
In the project i work at the moment, i have 38 set (76 frames…) and i’m not going to rename each one manually…
I found a way to rename multiple files through excel and cmd.
The only problem now is to get a list of layer names in txt file…

Any help will be appreciated!

9 Replies
(
	TF = @"C:\myLayers.txt"
	(dotNetClass "System.IO.File").WriteAllLines (TF) (for i = 0 to layerManager.count-1 collect (layerManager.getLayer i).name)
)

bro, you make it look like the easiest thing on earth…
it didn t work though :shrug:

i got

– Error occurred in anonymous codeblock; filename: ; position: 156; line: 4
– Syntax error: at ), expected <factor>
– In line: )

It’s working at me in max 2012 and 2014.
just copy, paste and press ctrl+E

well… you are right…
i just needed to run max as administrator

Thank you a lot!

Hello

Thanks to the code it works like a charm
If we reverse this code means, can we do the same layer importing?

If you want to import i.e. merge specific layer it is impossible to do in an easy way
You’ll have to provide all nodes names of that specific layer to mergeMAXFile function to merge it

Check out this tool as its might be what you need
https://cganimator.com/csmergeby-powered-by-3dsmax-2019-custom-scene-file-data-stream/

Hello Serejah,
thank you for script link it is very useful but i do not want to merge objects
and i do not want to merge specific layer.

actually i want to load my layers list witch layers name is saved in text file
i was try “try2script” code and it export all my layers in text

why i want this script because mostly i received model in sketchup file or cad file
and they are not working in layers so when i sort the model and put in layer
but every time create same layers in max file is very difficult.

thanks

this is how I would do it… to paraphrase precision transmission “xml is your friend”

macroScript Export_XML_Layers
   category:"Utils"
   buttontext:	"Export Layers"
   tooltip:"Export XML Layesr"
   Icon:	#("LayerToolbar", 4)
(	
	
	fn add_child_element doc parent element_name element_value =
	(
		element = doc.createElement element_name;
		element.InnerText = element_value;
		parent.appendChild element;	
		element;
	)	
	
	fn export_xml_layers file_name =
	(
		dotNet.loadAssembly "system.xml"
		xmlDoc = dotNetObject "system.xml.xmlDocument";
		xmlDoc.appendChild ( xmlDoc.CreateXmlDeclaration "1.0" "UTF-8" "yes")
		
		layers_e = xmlDoc.createElement "Layers";
		layers_e.setAttribute "version" "1.0";
		numlayers = LayerManager.count;
		layers_e.setAttribute "count" (numlayers as string);
		xmlDoc.appendChild layers_e;
		
		for l = 0 to numlayers - 1 do
		(	
			layer = layerManager.getLayer l;
			layer_e = xmlDoc.createElement "Layer";
			layers_e.appendChild layer_e;
			
			add_child_element xmlDoc layer_e "Name" layer.name;
			add_child_element xmlDoc layer_e "On" (layer.on as string);
			add_child_element xmlDoc layer_e "Lock" (layer.lock as string);
			--add_child_element xmlDoc layer_e "Current" (layer.current as string); -- can only be set to true
			add_child_element xmlDoc layer_e "WireColor" (layer.wirecolor as string);
			--...... add/delete elements as required
		)
		xmlDoc.save file_name; 
	)

	fn do_the_export =
	(	
		local file_name = getsavefilename types:"XML Files (*.xml)|*.xml|"
		if file_name != undefined do export_xml_layers  file_name;	
	)
	
	on execute do do_the_export();
)	
	

macroScript Import_XML_Layers
   category:"Utils"
   buttontext:	"Import Layers"
   tooltip:"Import XML Layers"
   Icon:	#("LayerToolbar", 6)
(
	fn get_boolean_prop parent prop_name def =
	(
		element = parent.item[prop_name];
		if element == undefined then def else  element.InnerText as BooleanClass;
	)		
	
	fn get_color_prop parent prop_name def =
	(
		element = parent.item[prop_name];
		if element == undefined then def else  execute element.InnerText;
	)	
	
	fn get_layer layer_e =
	(
		name_e = layer_e.item["Name"];
		if name_e != undefined then
		(
			layer_name = name_e.InnerText;
			layer = LayerManager.getLayerFromName layer_name;
			if layer == undefined then -- layer doesn't already exist so add it
			(
				layer = LayerManager.newLayerFromName layer_name;
				
				layer.on = get_boolean_prop layer_e "On" true;
				layer.lock  = get_boolean_prop layer_e "Lock" false;
				--layer.current  = get_boolean_prop layer_e "Current" false; -- can only be set to true :/
				layer.wireColor = get_color_prop layer_e "WireColor" (color 128 128 128);
				--...... add/delete elements as required
			)
		)		
	)	
	
	
	fn import_xml_layers file_name =
	(	
		dotNet.loadAssembly "system.xml"
		xmlDoc = dotNetObject "system.xml.xmlDocument";
		try
			xmlDoc.load file_name;
		catch
			return false;
		
		root_e = xmlDoc.DocumentElement;
		if root_e.name == "Layers" and root_e.getAttribute "version" == "1.0" then
		(
			num_layers = root_e.getAttribute "count" as Integer;
			for l = 0 to num_layers - 1 do get_layer (root_e.ChildNodes.item l);
		)		
	)
	fn do_the_import =
	(	
		file_name = getopenfilename caption:"Import XML Layers" types:"XML Files (*.xml)|*.xml|"
		if file_name != undefined then		
			import_xml_layers file_name;
	)
	on execute do do_the_import();
	
)

Hello Klvnk,

WOW . . . . .
its working thanks you so much

It is very handy and save my time to create many layers same name
i loved your script because i like script features it export turn on/off , frozen/lock , wireColor

really Thank you . . . . . .