ScriptSpot

Forum topic · Scripts Wanted

Material Library to XML file

By obaida · 2016-10-12

Description

I have a material library files (mat) and want to export all materials names in this library to a xml file in this form:

where "ABC" is the material name in this library.
so how to do that or is there any script can do this task?
Thanks in Advanced.

Comments (6)

obaida · 2017-03-29

Thank you very much i will try it

Thanks

obaida · 2016-10-18

Thank you "pixamoon" for your help and info , i will check it and inform you.

`

pixamoon · 2016-10-14

Hi

There is a nice XML structure you can take a look:
http://www.scriptspot.com/forums/3ds-max/general-scripting/dotnet-xml-us…

and here is a sample how to read all materials names from mat files:



dir = "C:\\FolderName"

for f in getfiles (dir + "\\*mat") do (
	
	print ("------" + getfilenamefile f + "------")
	ml = loadTempMaterialLibrary f
	
	for m in ml do (
		print m.name
		---add to your XML here
    )
)

Can you tell me more how this xml should look like for multiple files and multiple maretials array? I can add this option to Library Track/Relink as export .mat info to XML:
http://www.scriptspot.com/3ds-max/scripts/library-track-relink

Cheers,
Pixamoon

`

pixamoon · 2016-10-15

Here is a simple/quick version.

If will find all .mat files in specified folder and create XML file for each of .mat file


dir = "C:\Path"

for f in getfiles (dir + "\\*mat") do (
	
	xmlFile = getFilenamepath f + "\\" + getFilenamefile f + ".xml"
	
	xmlDoc = dotNetObject "System.Xml.XmlDocument"
	NotesElement = xmlDoc.CreateElement "Notes"
	xmlDoc.AppendChild NotesElement
	
	n1Element = xmlDoc.CreateElement "CategoryNotes"
	NotesElement.AppendChild n1Element
	
	childElement = xmlDoc.CreateElement "CatyNotes"
	n1Element.AppendChild childElement

	ml = loadTempMaterialLibrary f
	
	for m in ml do (
		MatElement = xmlDoc.CreateElement "MaterialNotes"
		MatElement.SetAttribute "MatName" m.name
		NotesElement.AppendChild MatElement
    )
	
	-- quick save without XML header
	xmlDoc.Save xmlFile
	
	-- or save with XML header
	writer = dotNetClass "System.Xml.XmlTextWriter"
	wSettings = dotNetObject "System.Xml.XmlWriterSettings"
	wSettings.indent = True
	w = writer.create xmlFile wSettings

	xmlDoc.writeContentTo w
	w.close()
)

Hope this helps

obaida · 2019-12-11

It working very will Thanks,
i just replaced the first line with

dir = getSavePath caption:"Choose .mat Directory"

swatchmate · 2020-04-17

Great example pixamoon
Is it possible to use matelement.innertext = and extract only the prefix or suffix of m.name with maxscript?
Lets say I have a material called Wood.Oakfloor.Dark and I want to output it like this


<category>wood</category>
<name>oakfloor dark</name>