How can I add a child to another object in a script?

I'd like to create an object and then add one or more child windows to it. I can add a new window, but how do I make it an actual hole in a wall.

The easiest way to add a child object is simply to create it and then use the command to link it to it's parent object. This emulates using the Edit»Link Objects menu item. The following script snippit shows how to do this...

-- Create the parent wall.
parent = add("object wall plane", true)
add("node", parent, 0, 10000, 2000, 0)
add("node", parent, 1, 15000, 2000, 0)
add("node", parent, 2, 15000, 2000, 3000)
add("node", parent, 3, 10000, 2000, 3000)

-- Create the child window.
child = add("object window plane", true)
add("node", child, 0, 11000, 2000, 600)
add("node", child, 1, 14000, 2000, 600)
add("node", child, 2, 14000, 2000, 2400)
add("node", child, 3, 11000, 2000, 2400)

-- Link the window to the wall.
cmd("", parent, child)

Ecotect will understand that the child object is a window and the parent, in this case is a wall. Hence it will set the window as a hole within the parent. If you tried to link two walls together, or a wall and a ceiling, Ecotect would simply treat them as related in space (move one and the other moves with it).

The view.redraw command at the end is simply there to make sure you see the new object appear when the script is run.

View desktop or mobile version of site.