Getting the parent node in SME

Getting the parent node in SME

zsomborAFFE3
Enthusiast Enthusiast
1,924 Views
4 Replies
Message 1 of 5

Getting the parent node in SME

zsomborAFFE3
Enthusiast
Enthusiast

Hi,

 

SME has a poor maxscript access, so I couldn't find a good solution for this.

What is the best method to get the parent node of a selected node in SME?

 

Thank you!!

Zsombor

0 Likes
Accepted solutions (1)
1,925 Views
4 Replies
Replies (4)
Message 2 of 5

denisT.MaxDoctor
Advisor
Advisor

Your question is incorrect. For SME nodes there is no such thing as hierarchy (parent - child). These can be nodes and dependent nodes.

I suggest you to show some picture to clarify the issue.

  

0 Likes
Message 3 of 5

zsomborAFFE3
Enthusiast
Enthusiast

Hi,

 

You can definitely find a hierarchic structure in a material, that goes from the maps (children) towards the material (parent).

Also, you can find actions in the SME menus, like Select Children, Layout Children, Hide Children, etc.

 

2020-05-25_211917_2.jpg

So what I want to achieve is to get the parent node of a selected node, like marked on the image.

 

Thx,

Zsombor

 

 

0 Likes
Message 4 of 5

denisT.MaxDoctor
Advisor
Advisor
Accepted solution

First of all, I want to say again that the use of the concepts of “parent” and “child” in the case of SME nodes is inappropriate. The names of the SME top menu items are misleading. Anyway, if someone likes these definitions, I don't care.

 

Here is all that you need to find the dependents sme nodes by specified one:

fn sme_get_node_ref node view: = 
(
	if view == unsupplied do view = sme.getview sme.activeview

	tv = trackviewnodes[#sme]
	vsub = tv[view.name]
	ref = undefined
	for k=1 to vsub.numsubs while ref == undefined do
	(
		_ref = vsub[k].reference
		if node == view.getnodebyref _ref do ref = _ref
	)
	ref
)

fn sme_get_dependent_nodes node view: = 
(
	if view == unsupplied do view = sme.getview sme.activeview

	ref = sme_get_node_ref node view:view
	dependents = refs.dependents ref
	for d in dependents where (p = view.getnodebyref d) != undefined collect p
)	

fn sme_get_selected_nodes view: = 
(
	if view == unsupplied do view = sme.getview sme.activeview
	view.getselectednodes()
)

selected_nodes = sme_get_selected_nodes()
dependent_nodes = sme_get_dependent_nodes selected_nodes[1]
node_ref = sme_get_node_ref dependent_nodes[1]

 

 

0 Likes
Message 5 of 5

zsomborAFFE3
Enthusiast
Enthusiast

I see what you mean.

 

Anyway, thank you very much for the script, it works great!

 

Zsombor

0 Likes