question

anon-user avatar image
0 Likes"
anon-user asked anon-user commented

Script move, rename, create

I want to make a script like this.


STEP1

Move the position of Processor1 to (0,0,0).


STEP2

Create Processor2 at (10,10,0).


STEP3

Rename Processor2 to "SubProcess".




STEP1 was found in the manual.

https://docs.flexsim.com/en/20.0/Reference/CodingInFlexSim/FlexScriptAPIReference/Tree/Object.html#Property-location

I found that I should write the script like this.


Object obj = Model.find ("Processor1");

obj.location = Vec3 (0,0,0);



However,

How should I write a script for STEP2 and STEP3?




FlexSim 20.1.3
flexscriptflexsim 20.1.3script
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Joerg Vogel avatar image
0 Likes"
Joerg Vogel answered anon-user commented

command reference >alphabetical index > initiate a search by key shortcut eg “ctrl + f” > insert a typical phrase like “create” or “copy” > test the results in a model.

Step 2: try createinstance, createcopy, insertcopy

Step 3: assign a different content to the property name of FlexScript Class treenode.

· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

anon-user avatar image anon-user commented ·

STEP2 understood to write like this.


createinstance(library().find("?Processor"), model());


However, I cannot proceed to STEP 3 because the name of the Processor created this way changes every time.

Is it possible to set the name of the instance created in STEP2?


0 Likes 0 ·
Joerg Vogel avatar image Joerg Vogel anon-user commented ·

Any new created object is the last object of your container like model tree or just model model().

treenode myNewObj = model().last;
or
treenode myBewObj = Model.last;

Or you declare the result of this function as a direct pointer like

treenode myNewObj = createinstance(obj library, obj container);
1 Like 1 ·
anon-user avatar image anon-user Joerg Vogel commented ·

Thank you! This is a good method.

0 Likes 0 ·