Duplicate Cube

About Truespace Archives

These pages are a copy of the official truespace forums prior to their removal somewhere around 2011.

They are retained here for archive purposes only.

Duplicate Cube // Tech Forum

1  |  

Post by Shell1850 // May 6, 2009, 11:38am

Shell1850
Total Posts: 13
How can I duplicate a cube using jscript? I want to load a object and duplicate it but so far I have failed. I can load a object. I need someone to show me how to duplicate a simple object, like a cube.

Post by Jack Edwards // May 6, 2009, 11:39am

Jack Edwards
Total Posts: 4062
pic
The Node.Copy() function sounds like what you're looking for ;)

Post by Shell1850 // May 6, 2009, 11:46am

Shell1850
Total Posts: 13
I tried that but i get a error.



I created a cube then used the following script


var Base = System.ThisOwner();


Node.Copy(Base + '/Cube',Base + '/Cube,1');


I get a "invalid procedure call or argument".

Post by Jack Edwards // May 6, 2009, 12:02pm

Jack Edwards
Total Posts: 4062
pic
Are you using a script object or a command script? It makes a difference because script objects don't have access to the scene graph.

Post by Shell1850 // May 6, 2009, 12:10pm

Shell1850
Total Posts: 13
I created a script in "Jscript comand" from System::Scripts Library.

Post by Shell1850 // May 6, 2009, 12:36pm

Shell1850
Total Posts: 13
More information


/ Execute

// Called to execute the command

function Execute(params)

{


var Base = System.ThisOwner();


Node.Copy(Base + '/Cube1',Base + 'Cube');


}

Post by Jack Edwards // May 6, 2009, 1:18pm

Jack Edwards
Total Posts: 4062
pic
Hmm... the YafaRay4tS toolbar installer uses code pretty much like that, not sure why what you're doing here doesn't want to work... but it's not working for me either. I put in a System.Alert(Base); line and the path is correct so this one's got me stumped for the moment.

I'm sure we're missing something really obvious... :o

Post by Jack Edwards // May 6, 2009, 1:30pm

Jack Edwards
Total Posts: 4062
pic
This works:


function Execute(params)
{
Node.Copy(Node.FirstSelected(), '');
}


I'm not sure why it won't let me name it though... wierd.

Post by trueBlue // May 6, 2009, 7:22pm

trueBlue
Total Posts: 1761
pic
Going by your second example try this:
Node.Copy(System.ThisOwner() + "/Cube", System.ThisOwner())

ThisOwner would be the Parent node where the Cube resides like if the Cube is encapsulated and the above command would place a copy of the Cube within. The script is also within. HTH... else need more info.

Post by Shell1850 // May 6, 2009, 8:28pm

Shell1850
Total Posts: 13
I have it working now. I have to let Node.Copy to name the object and use Node.Rename to assign a new name.



var Base = System.ThisOwner();

var i = 5;


var NewCube = Node.Copy(Base + '/Cube','');

Node.Rename(NewCube, 'Rail' + i.toString(10));


Thanks for your help
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2021. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn