Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

attachObjects fails to attach objects

attachObjects fails to attach objects

32loyal
Advocate Advocate
1,384 Views
6 Replies
Message 1 of 7

attachObjects fails to attach objects

32loyal
Advocate
Advocate

Hello,

Iam trying to take two nodes and put node2 into node1 but when i run the script it gives me a error saying Unable to convert:#($LOD222) to type:<node>.It seems that the node variables arent actually of type node,i dont know what i need to call to get the correct variable types.any help is appreciated

node1 =  getNodeByName "LOD222" exact:true ignoreCase:false all:true
node2 =  getNodeByName "_e94c_Var1_LOD3" exact:true ignoreCase:false all:true

attachObjects node1 node2 move:true
0 Likes
Accepted solutions (1)
1,385 Views
6 Replies
Replies (6)
Message 2 of 7

istan
Advisor
Advisor

why don't you check in the mxs-listener what the contents of node1 and node2 are?

Message 3 of 7

32loyal
Advocate
Advocate

Sorry I didn't mention IAM still new to max script how exactly would I do this?

0 Likes
Message 4 of 7

miauuuu
Collaborator
Collaborator

Try this:

(
node1 = selection[1]
node2 = selection[2]
node2.parent = node1
node2.pos = node1.pos
)

 

 

https://miauu-maxscript.com/
Message 5 of 7

ads_royje
Alumni
Alumni
Accepted solution

Hi @32loyal ,

 

in the message error : Unable to convert:#($LOD222) to type:<node>

is because #($LOD222) is an array of 1 node, not a node.

 

The getnodebyname will return an array of nodes instead of a node when the all:true argument is passed.


Either use node1[1] and node2[1] to get the first node of the array of node or remove the all:true argument.

Regards,

Message 6 of 7

32loyal
Advocate
Advocate

Ok perfect this all makes sense now, that its returning a array instead of a single node your solution and @miauuuu would work the only difference is i would need a "max select" command for miauuuu solution.I've opted to set the all parameter in getNodyByName to false to only get a single node.Thanks for everyones help and input i appreciate it

Message 7 of 7

miauuuu
Collaborator
Collaborator

You can use my code without selecting any objcets. Its just need a little modification:

(
	node1 =  getNodeByName "LOD222" exact:true ignoreCase:false all:false
	node2 =  getNodeByName "_e94c_Var1_LOD3" exact:true ignoreCase:false all:false
	node2.parent = node1
	node2.pos = node1.pos
)

 

https://miauu-maxscript.com/