<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: material editor node parent and children in 3ds Max Programming Forum</title>
    <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002562#M10513</link>
    <description>&lt;P&gt;I tested the refs.dependencylooptest way but the problem seem to be that it doesn't stop at the immediate child or parent, but crawl all the way up or down the shading tree and that the node is a child and parent of itself (at least in my findings).&lt;/P&gt;&lt;P&gt;In the following example there is from down to up the tree:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bitmap &amp;gt; color map &amp;gt; color correct &amp;gt; standard material&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this code:&lt;/P&gt;&lt;PRE&gt;fn delete_and_relink =
(
	local mk_scene_nodes_all = join mk_scene_nodes mk_scene_nodes_unsupported
	local child_node  = undefined
	local middle_node = undefined
	local parent_node = undefined
	&lt;BR /&gt;        -- here I loop in my unsupported nodes array
	for i in mk_scene_nodes_unsupported do
	(
		middle_node = i
		&lt;BR /&gt;                -- here I check against all nodes, supported or not for child
		for j in mk_scene_nodes_all do
		(
			if ( refs.dependencyLoopTest middle_node j ) then
			(
				child_node = j
				print ( middle_node as string + " CHILD is: " + child_node as string )
			)
			if ( refs.dependencyLoopTest j middle_node ) then
			(
				parent_node = j
				print ( middle_node as string + " PARENT is: " + parent_node as string )
			)
			else ()
		)
	)
)
on testbtn pressed do ( delete_and_relink() )&lt;/PRE&gt;&lt;P&gt;For now this function does not delete and relink but that's its goal.&lt;/P&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"Material #25:Standard CHILD is: Material #25:Standard"
"Material #25:Standard PARENT is: Material #25:Standard"
"Material #25:Standard CHILD is: Map #4:Bitmap"
"Material #25:Standard CHILD is: Map #2:Color Correction"
"Material #25:Standard CHILD is: Map #3:Color Map"
"Map #4:Bitmap PARENT is: Material #25:Standard"
"Map #4:Bitmap CHILD is: Map #4:Bitmap"
"Map #4:Bitmap PARENT is: Map #4:Bitmap"
"Map #4:Bitmap PARENT is: Map #2:Color Correction"
"Map #4:Bitmap PARENT is: Map #3:Color Map"
"Map #2:Color Correction PARENT is: Material #25:Standard"
"Map #2:Color Correction CHILD is: Map #4:Bitmap"
"Map #2:Color Correction CHILD is: Map #2:Color Correction"
"Map #2:Color Correction PARENT is: Map #2:Color Correction"
"Map #2:Color Correction CHILD is: Map #3:Color Map"
"Map #3:Color Map PARENT is: Material #25:Standard"
"Map #3:Color Map CHILD is: Map #4:Bitmap"
"Map #3:Color Map PARENT is: Map #2:Color Correction"
"Map #3:Color Map CHILD is: Map #3:Color Map"
"Map #3:Color Map PARENT is: Map #3:Color Map"&lt;/PRE&gt;&lt;P&gt;as you can see this is not exactly what I'm after. Each node is a parent/child of itself and a given node will have as parent and children ALL the nodes up or down the tree.&lt;BR /&gt;Although if I could stop at the immediate parent and child, the problem of deleting the 'middle' node so it's parent and child have a direction connection is still open.&lt;/P&gt;</description>
    <pubDate>Tue, 15 May 2018 10:29:05 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2018-05-15T10:29:05Z</dc:date>
    <item>
      <title>material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8000753#M10509</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Is there an "easy" way to do the following:&lt;/P&gt;&lt;P&gt;- get the parent and child of a given material editor name. Say you have bitmap&amp;gt;somenode&amp;gt;someothernode&amp;gt;material&lt;/P&gt;&lt;P&gt;you work on 'somenode' and you really need to know what is the child and what is the parent.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This task is driving me crazy... The farest I managed to get was to assume starting from the material and slowly going node by node down the tree, collecting prop names and executing convoluted strings to check which slot(s) is/are in use... And this is only going to get messier.&lt;/P&gt;&lt;P&gt;I couldn't find anything either in the docs or using google for that matter (nothing useful at least, always examples assuming nodes are of a known type and there is no more than one child or parent).&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 16:15:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8000753#M10509</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-14T16:15:23Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8001835#M10510</link>
      <description>&lt;P&gt;I do not fully understand exactly what you're trying to achieve however the following script includes two functions which return all the children of the specified parent name and returns all the parents which have a material with the specified child name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;(
	fn find_parent child = (
		local parents = #()
		for mat in sceneMaterials where classOf mat == multimaterial do (
			for sub in mat.material where sub.name == child do (
				append parents ("Parents: " + mat.name)
			)
		)
		return(parents)
	)
	
	fn find_children parent = (
		local children = #()
		for mat in sceneMaterials where classOf mat == multimaterial and mat.name == parent do (
			for sub in mat.material do (
				append children ("Children: " + sub.name)
			)
		)
		return(children)
	)
	
	print (find_parent "material_child") -- lists all parent materials which has a child material with this name
	print (find_children "material_parent") -- lists all child materials of the specified parent material
)&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 May 2018 03:23:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8001835#M10510</guid>
      <dc:creator>blakestone</dc:creator>
      <dc:date>2018-05-15T03:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002018#M10511</link>
      <description>&lt;P&gt;as i could understand you well you want to know a relation between two materials: how is "parent" and who is "child".&lt;/P&gt;&lt;P&gt;right?&lt;/P&gt;&lt;P&gt;there is no such thing for materials like parent-child dependency. But there is dependency itself. So you can check how two nodes depend to each other.&amp;nbsp;&lt;/P&gt;&lt;P&gt;you show use : &lt;STRONG&gt;refs.dependencylo&lt;/STRONG&gt;&lt;/P&gt;&lt;PRE&gt;refs.dependencylooptest mat_A mat_B

-- if you get TRUE it means A depends on B (B is a "child" of A)
-- if you get FALSE it means that A doesn't depend on B. B might be a parent of A or might not have any dependency with A

-- if you want to check is B a "parent" of A do:

refs.dependencylooptest mat_B mat_A&lt;/PRE&gt;&lt;P&gt;see also refs.Dependents and refs.DependsON&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 06:35:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002018#M10511</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2018-05-15T06:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002435#M10512</link>
      <description>&lt;P&gt;Hello DenisT and thank you for your answer.&lt;/P&gt;&lt;P&gt;I'll try to be a bit more specific about what I'm trying to achieve.&lt;/P&gt;&lt;P&gt;I'm currently working on a converter and although converting nodes that I actually can has been pretty straightforward, now is the time to 'cleanup' nodes I cannot support. But I need to retain proper texture&amp;lt;&amp;gt;texture, texture&amp;lt;&amp;gt;material, material&amp;lt;&amp;gt;material connections.&lt;/P&gt;&lt;P&gt;This is where I fail. No matter which direction I crawl the shading tree (left&amp;gt;right or right&amp;gt;left, at some point I'm stuck as I cannot get the outut_socket in any way so far so I need to check 2 nodes down or 2 nodes up, which happens to be a lot of code an quite slow using the only way I managed to get this to work so far (basically listing node's input slots, checking for them to be undefined or not, picking the first NOT undefined and so on).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think if I could get your functions to get parents and children to adapt to my script, that might work. I'm still trying tho &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I've been learning maxscript for the first time in a crash-course during the last month and a half only so pardon my ignorance if I'm missing something way easier than I thought!&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 09:28:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002435#M10512</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-15T09:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002562#M10513</link>
      <description>&lt;P&gt;I tested the refs.dependencylooptest way but the problem seem to be that it doesn't stop at the immediate child or parent, but crawl all the way up or down the shading tree and that the node is a child and parent of itself (at least in my findings).&lt;/P&gt;&lt;P&gt;In the following example there is from down to up the tree:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bitmap &amp;gt; color map &amp;gt; color correct &amp;gt; standard material&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using this code:&lt;/P&gt;&lt;PRE&gt;fn delete_and_relink =
(
	local mk_scene_nodes_all = join mk_scene_nodes mk_scene_nodes_unsupported
	local child_node  = undefined
	local middle_node = undefined
	local parent_node = undefined
	&lt;BR /&gt;        -- here I loop in my unsupported nodes array
	for i in mk_scene_nodes_unsupported do
	(
		middle_node = i
		&lt;BR /&gt;                -- here I check against all nodes, supported or not for child
		for j in mk_scene_nodes_all do
		(
			if ( refs.dependencyLoopTest middle_node j ) then
			(
				child_node = j
				print ( middle_node as string + " CHILD is: " + child_node as string )
			)
			if ( refs.dependencyLoopTest j middle_node ) then
			(
				parent_node = j
				print ( middle_node as string + " PARENT is: " + parent_node as string )
			)
			else ()
		)
	)
)
on testbtn pressed do ( delete_and_relink() )&lt;/PRE&gt;&lt;P&gt;For now this function does not delete and relink but that's its goal.&lt;/P&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"Material #25:Standard CHILD is: Material #25:Standard"
"Material #25:Standard PARENT is: Material #25:Standard"
"Material #25:Standard CHILD is: Map #4:Bitmap"
"Material #25:Standard CHILD is: Map #2:Color Correction"
"Material #25:Standard CHILD is: Map #3:Color Map"
"Map #4:Bitmap PARENT is: Material #25:Standard"
"Map #4:Bitmap CHILD is: Map #4:Bitmap"
"Map #4:Bitmap PARENT is: Map #4:Bitmap"
"Map #4:Bitmap PARENT is: Map #2:Color Correction"
"Map #4:Bitmap PARENT is: Map #3:Color Map"
"Map #2:Color Correction PARENT is: Material #25:Standard"
"Map #2:Color Correction CHILD is: Map #4:Bitmap"
"Map #2:Color Correction CHILD is: Map #2:Color Correction"
"Map #2:Color Correction PARENT is: Map #2:Color Correction"
"Map #2:Color Correction CHILD is: Map #3:Color Map"
"Map #3:Color Map PARENT is: Material #25:Standard"
"Map #3:Color Map CHILD is: Map #4:Bitmap"
"Map #3:Color Map PARENT is: Map #2:Color Correction"
"Map #3:Color Map CHILD is: Map #3:Color Map"
"Map #3:Color Map PARENT is: Map #3:Color Map"&lt;/PRE&gt;&lt;P&gt;as you can see this is not exactly what I'm after. Each node is a parent/child of itself and a given node will have as parent and children ALL the nodes up or down the tree.&lt;BR /&gt;Although if I could stop at the immediate parent and child, the problem of deleting the 'middle' node so it's parent and child have a direction connection is still open.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 10:29:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8002562#M10513</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-15T10:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8003245#M10514</link>
      <description>&lt;P&gt;i probably understand what you are looking for... you want to know where (which client has this node)&amp;nbsp; a node used.&lt;/P&gt;&lt;P&gt;if it's material - what slot of sub-material, if it's texture - what bitmaptexture node and where is in the material... right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ok... in this case your friend is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;getclassinstances &lt;/STRONG&gt;with&lt;STRONG&gt; astrackviewpick &lt;/STRONG&gt;option (see details in the mxs help, and search this or CGTalk forum for examples).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;brief example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;mat = multimaterial numsubs:2
m = mat[1] = standard()
ii = getclassinstances (classof m) astrackviewpick:on
for i in ii do format "parent:% anim:% subnum:% subanim:%\n" i.client i.anim i.subnum i.client[i.subnum]&lt;/PRE&gt;&lt;P&gt;same idea for bitmaptrxtures... but you have to search but name and bitmap texture filename after that. that's the best way via MXS&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 14:44:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8003245#M10514</guid>
      <dc:creator>denisT.MaxDoctor</dc:creator>
      <dc:date>2018-05-15T14:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8005915#M10515</link>
      <description>&lt;P&gt;Awesome Denis.T, it looks like I'm going to be able to work my way from there. Many thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 13:35:30 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8005915#M10515</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-16T13:35:30Z</dc:date>
    </item>
    <item>
      <title>Re: material editor node parent and children</title>
      <link>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8008999#M10516</link>
      <description>&lt;P&gt;Well if someone is interested in doing such thing, here my working code. It only considers the first valid input_socket, doing otherwise would mean knowing what each child and parent node is capable of. Possible but not the goal here. If your "middle" node has just one input socket anyway, works like a charm.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;fn get_parent x =
(
	getParents = getClassInstances ( classof x ) asTrackViewPick:on
	
	for i in getParents do
	(
		if ( superClassOf i.client == textureMap ) or ( superClassOf i.client == material ) then
		(
			if ( i.client != undefined ) then
			(
				parent = i.client
				return parent
			)
			else
			(
				return undefined
			)
		)
	)
)
	
fn get_child x =
(
	free submaps_count
	free submaps_names
	gc
	
	submaps_count = getNumSubTexmaps x
	
	submaps_names = #()

	for i = 1 to submaps_count do
	(
		if ( ( getSubTexmap x i ) != undefined ) then
		(
			append submaps_names ( getSubTexmap x i )
		)
	)
	
	child = submaps_names[1]
	
	return child
)

fn delete_and_relink =
(
	global child
	global current
	global parent
	
	local unsupported_nodes -- This is your array or unsupported nodes, construct it the way you want
	
	for i in unsupported_nodes where ( superClassOf i == textureMap ) and ( classof i != Bitmaptexture ) do -- it was required to get rid of the Bitmaptexture class for me, otherwise bitmap type nodes return an extra parent to themselves
	(
		current = i
		
		index = getNumSubTexmaps i
		
		get_parent current
		
		get_child current
		
		setSubTexmap parent 1 child
		setSubTexmap current 1 undefined
	)
	
	free unsupported_nodes
	gc
)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 May 2018 14:09:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/3ds-max-programming-forum/material-editor-node-parent-and-children/m-p/8008999#M10516</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2018-05-17T14:09:42Z</dc:date>
    </item>
  </channel>
</rss>

