Notifications
Clear all

[Closed] Write Slate Material Editor

 MZ1

I just want to save all material nodes and links to xml file. Would you please show me where I should start? any samples? built-in function ? any tip and tricks would be apperciated. Thanks.

2 Replies

there’s the dotnet xml handling

it works ok pretty easy to use via mxs or native c#

w3schools is pretty good for tutorials

do a google search for “Element vs Attribute” it’ll give you a heads up on the best formatting for your data, half the battle is creating the structure though one of the nice things about xml is it’s tolerance to data changes/additions.

I use xml for most things it, great for preferences, build style files and quick and dirty file formats.

I have my own tool for generating a visual studio project for all version of max going back to 2010, the setup xml file looks like…

  <?xml version="1.0" encoding="utf-8"?>
<max_plugin_project>

	<name>unplug</name>
	<path>D:\Development\3dsMax\plugins\</path>
	<type quitmax="true">gup</type>
	<vsversion year="2019">16.0</vsversion>
	<winver>10.0.16299.0</winver>
	<propsheetspath>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\</propsheetspath>
	<createsourcefiles>false</createsourcefiles>

<!-- project folder structure -->

	<folders>
		<folder name="source"   type="srce"/>
		<folder name="include"  type="incl"/>
		<folder name="resource" type="rsrc"/>	
		<folder name=""         type="vstv"/>
		<folder name="project"  type="proj"/>
		<folder name="props"    type="prps"/>
	</folders>		

<!-- definition file and dll main function list-->
	
	<def>
		<export ordinal="@1">LibVersion</export>
		<export ordinal="@2">LibDescription</export>
		<export ordinal="@3">LibNumberClasses</export>
		<export ordinal="@4">LibClassDesc</export>
<!--	<export ordinal="@5">LibInitialize</export>-->
<!--	<export ordinal="@6">LibShutdown</export>-->
<!--	<export ordinal="@7">CanAutoDefer</export>-->
	</def>	

<!-- additional project property sheets -->

	<prop_sheets>

			<prop_sheet>D:\Development\3dsMax\plugins\include\includedir.props</prop_sheet>
			<prop_sheet>D:\Development\3dsMax\plugins\common\commondir.props</prop_sheet>
<!--		<prop_sheet>D:\Development\tinyxml\prop_sheets\tinyXML.props</prop_sheet>-->

	</prop_sheets>	

<!-- max version builds -->

	<platforms>
		<platform name="x64" > 
			<build_types>
				<build_type name="release">
					<build version="12">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>
						</prop_sheets>	
					</build> 		
					<build version="14"/>
					<build version="15"/>
					<build version="17">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>	
						</prop_sheets>
					</build> 	
					<build version="19"/>
					<build version="20"/>
					<build version="21"/>
					<build version="22">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>	
						</prop_sheets>
					</build> 	
					<build version="24"/>
					<build version="25"/>
				</build_type>	
				<build_type name="hybrid" >
					<build version="12">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\debug_target.props</prop_sheet>
						</prop_sheets>
					</build> 
					<build version="17">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\debug_target.props</prop_sheet>
						</prop_sheets>
					</build> 	
					<build version="22">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\debug_target.props</prop_sheet>
						</prop_sheets>
					</build> 	
				</build_type>	
			</build_types>		
		</platform>	
		<platform name="Win32"> 
			<build_types>
				<build_type name="release">
					<build version="12">
						<prop_sheets>
							<prop_sheet>D:\Development\3dsMax\plugins\propsheets\vs_project_builder\postbuild_update.props</prop_sheet>
						</prop_sheets>	
					</build> 		
				</build_type>
			</build_types>			
		</platform>		
	</platforms>

</max_plugin_project>

probably worth mentioning that i use tinyxml c++

 MZ1

Thank you for your response, actually my challange is undrstading of shader nodes in Max, how to iterate over nodes, inputs, outputs and links. something like this:

	fn ExportData data_filename =
	(
		xml_doc = dotNetObject "System.xml.xmlDocument"
		xml_root = xml_doc.createElement "root"
		xml_doc.appendChild xml_root
		xml_mats = xml_doc.createElement "materials"
		xml_root.appendChild xml_mats
		
		all_materials = #()
		
		for o in objects where isValidNode o do
		(
			mat = o.material
			if mat != undefined do
			(
				if classof mat == Multimaterial then
				(
					for i = 1 to mat.count do
					(
						appendIfUnique all_materials mat[i]
					)
				)
				else
				(
					appendIfUnique all_materials mat
				)
			)
		)
		
		if all_materials.count > 0 do
		(
			sme.Open()
			for i = 1 to sme.GetNumViews() do sme.DeleteView i false
			for mat in all_materials do
			(
				xml_mat = xml_doc.createElement "material"
				xml_mats.appendChild xml_mat
				xml_mat.setattribute "name" mat.name
				
				sme_view_name = "sme_view_name"
				sme_view = sme.GetView (sme.CreateView sme_view_name)
				sme_view.createNode mat [0,0]
				sme_view_subanim = trackViewNodes[#sme][sme_view_name]
				
				for i = 1 to sme_view_subanim.numsubs do
				(
					shader_node = sme_view_subanim[i].reference
					xml_node = xml_doc.createElement "node"
					xml_mat.appendChild xml_node
					xml_node.setattribute "name" shader_node.name
					xml_node.setattribute "class" ((classof shader_node) as string)
					xml_node.setattribute "handle" ((getHandleByAnim shader_node) as string)
				)
				sme.DeleteView 1 false
			)
			SME.close()
		)
		
		xml_doc.save data_filename
	)
	
	ExportData @"D:\WIP\Test_117_ExportMaterialData\test.xml"