getNodeByName in Material editor

getNodeByName in Material editor

Alireza.khoshpayam
Explorer Explorer
1,221 Views
9 Replies
Message 1 of 10

getNodeByName in Material editor

Alireza.khoshpayam
Explorer
Explorer

Hi!
I want the nodes that have a specific name, for example "fall_map", to be identified and to be able to change their information, for example, to change the front color of that map.
I have no idea, I would appreciate it if anyone could help me!

01.png

0 Likes
1,222 Views
9 Replies
Replies (9)
Message 3 of 10

Alireza.khoshpayam
Explorer
Explorer

Thank you Istan but none of the links work for me

0 Likes
Message 4 of 10

istan
Advisor
Advisor

I just checked: they work. AD probably locked you out.. where are you located?

0 Likes
Message 5 of 10

Alireza.khoshpayam
Explorer
Explorer

Iran!
I agree with you, probably the reason is the same 😞

0 Likes
Message 6 of 10

istan
Advisor
Advisor

But you have access to this board.. fascinating..

0 Likes
Message 7 of 10

denisT.MaxDoctor
Advisor
Advisor

You're asking how to find the Slate Material Editor node by name... but what does it matter where it's located? The only fact that this node exists makes sense.

So, it doesn't matter where we look for the node...

 

Because you want to change a specific node setting, this means you know the class of the node.

Let's find all instances of this class and check that the name matches:

 

 

fn findInstanceByName name class:FallOff = 
(
	instances = getclassinstances class
	node = undefined 
	for i in instances where (stricmp i.name name == 0) do exit with (node = i)
	node
)

/*** Usage:
findInstanceByName #fall_map class:FallOff
***/

 

 

to compare names, we use the stricmp method, which is case-insensitive and can take either a string or a name type argument.

  

0 Likes
Message 8 of 10

Alireza.khoshpayam
Explorer
Explorer

Thank you Denis! That's exactly what I wanted.
Can we change this code a bit?
to get only the nodes related to the object we selected and have this name, not all the maps with this name.

0 Likes
Message 9 of 10

denisT.MaxDoctor
Advisor
Advisor

 

fn findInstanceByName name class:FallOff target: = 
(
	/* the target optional argument must be a valid object or unsupplied */
	-- if not isvalidobj target do target = unsupplied

	instances = getclassinstances class target:target
	node = undefined 
	for i in instances where (stricmp i.name name == 0) do exit with (node = i)
	node
)

/*** Usage:
findInstanceByName #fall_map class:FallOff target:selection[1]
***/

 

Try to figure out how the code works... MSX's help is enough for that.
Don't use someone else's code without understanding.

 

0 Likes
Message 10 of 10

Alireza.khoshpayam
Explorer
Explorer

Thank you a lot Denis!

0 Likes