Max script basic question. (Parent)

Max script basic question. (Parent)

jeffpanek3d
Participant Participant
5,753 Views
5 Replies
Message 1 of 6

Max script basic question. (Parent)

jeffpanek3d
Participant
Participant
 
I have a scene with a simple script that parents several objects.

select $Box01
$.parent = $Box00
select $Box02
$.parent = $Box00
select $Box_B01
$.Parent = $Box_B00
...etc
 
But i have some scenes that do not contain all the objects called in the script.
Is it possible to create an if, then functionality to ignore  these missing objects?

something like:

if $Box01 = undefined then ignore, otherwise
$.parent = $Box00

???

Thanks for any help

0 Likes
Accepted solutions (1)
5,754 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Accepted solution

Small world, Jeff! Great to see you here! As for the logic, you have the right idea. Before running the parenting operation, use and if statement:

 

 

 


if ($Box01 != undefined and $Box00 != undefined) then
(
$Box01.parent = $Box00
)

if ($Box02 != undefined and $Box00 != undefined) then
(
$Box02.parent = $Box00
)

if ($Box_B01 != undefined and $Box_B00 != undefined) then
(
$Box_B01.parent = $Box_B00
)

 

The code juts checks if both the child and parent exists, before running the parenting operation. If the child or parent does not exist, it won't do anything.

 

Is this what you're looking for?

Message 3 of 6

jeffpanek3d
Participant
Participant
This is exactly what i was looking for, smallsketch!

You saved me a ton of manual work.
 
Many, many thanks, my friend!

Cheers!

Jeff

0 Likes
Message 4 of 6

Radush
Contributor
Contributor

Dear friend, perhaps you can help me too, in my opinion the task is simple but the answer is nowhere to be found (
I have code that creates a new layer in tab Toggle Scene Explorer


LayerManager.newLayerFromName "Layer_A"

below is the code that creates the object

Box pos:[0,0,0] isSelected:on width:2 length:2 height:2

 

The Box object is located in the selected layer by default, but I want it to be located in the layer "Layer_A"

0 Likes
Message 5 of 6

MehdiZangenehBar
Advocate
Advocate

First of all, you should never use $ in your code.
Second, you can use "isvalidnode" function to check object validation.
So, your code should look like this:

child_obj = getNodeByName "Box01" exact:true ignoreCase:true all:false
parent_obj = getNodeByName "Box00" exact:true ignoreCase:true all:false
if isValidNode child_obj and isValidNode parent_obj do child_obj.parent = parent_obj

 

0 Likes
Message 6 of 6

MehdiZangenehBar
Advocate
Advocate
you should create new topic
0 Likes