Material Library to XML file

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
obaida's picture

Thanks

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

pixamoon's picture

`

Hi

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

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's picture

`

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.