How can I insert 3D Object to the 3D view using FlexScript?

How can I insert 3D Object to the 3D view using FlexScript?

sakamoto_ryosuke
Collaborator Collaborator
1,529 Views
9 Replies
Message 1 of 10

How can I insert 3D Object to the 3D view using FlexScript?

sakamoto_ryosuke
Collaborator
Collaborator

[ FlexSim 19.0.9 ]

Hello, I would like to insert 3D object such as queue , processors, etc. from the library to the 3D view by FlexScript. How can I do that? I can't seem to find commands such as create or load in the FlexScript reference.

The purpose I want to do this is to automate the insert of the 3D object if the customer has the list of equipment in Excel or csv.

Thank you in advance,

0 Likes
Accepted solutions (1)
1,530 Views
9 Replies
Replies (9)
Message 2 of 10

joerg_vogel_HsH
Mentor
Mentor
Accepted solution
0 Likes
Message 3 of 10

allister_wilson
Not applicable

You can use createinstance to instantiate library objects, and createcopy if you want to create copies of an object you have already preconfigured.

createinstance documentation

createcopy documentation

Message 4 of 10

sakamoto_ryosuke
Collaborator
Collaborator
@Jörg Vogel Thank you! Also thank you for the dragconnection. I also needed that.
0 Likes
Message 5 of 10

sakamoto_ryosuke
Collaborator
Collaborator

@Allister Wilson Thank you for your reply! I also wanted to give best answer to you but Jörg replied just one minute earlier than you did.

0 Likes
Message 6 of 10

patrickABAWF
Collaborator
Collaborator

Hello, When I try to create boxes in this fashion:

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

or with this:

createinstance(library().find("Tools/FlowItemBin/Box"), model());

I get a variable/codenode error. But if I put ?Queue or other objects instead of a flowitem all works fine. Is that normal?

It works if I do it with the ProcessFlow activity "Create Object" but I'd need to do it in code for various reasons.

You can see the problem in the attached 1-line model.

1linemodel.fsm

0 Likes
Message 7 of 10

joerg_vogel_HsH
Mentor
Mentor

@Patrick Cloutier, you find Flow Items never in the library! They are in the Flow Item Bin under the Model treenode in Tools. The create object activity involves a field where you can select directly the Flow Item and you don’t need to set a reference as a pointer.

The reference should be

Model.find("Tools/FlowItemBin/Box/Box")

Maybe you can use the sampler tool in the model tree to get the right reference to the object node of a flow item.

If you need a reference directly in Main then it is:

MAIN:/project/exec/globals/FlowItemBin
Tree Organization
0 Likes
Message 8 of 10

patrickABAWF
Collaborator
Collaborator

When I use the sampler either in the Toolbox or the Tree I get this:

Model.find("Tools/FlowItemBin/Box")

without the 2nd /Box

and it creates an invisible box with no dimensions and returns this error:

time: 0.000000 exception: int ByteBlock::write(char *source, long unsigned int size, int nullterminate)
ex: write

The only way to make it right is to manually add the 2nd /Box and then it works.

Not very user friendly...

0 Likes
Message 9 of 10

joerg_vogel_HsH
Mentor
Mentor

@Patrick, if you expand the first box node in the tree, you’ll see that this node is not an object. The icon looks like a directory symbol described as standard in manual chapter Tree Properties Section Nodes. The next box node deeper in the tree is an object node, which you can expand into sub list of attributes nodes by the > icon left to the node.

0 Likes
Message 10 of 10

philboboADSK
Autodesk
Autodesk

You don't use createinstance() to create flowitems. You use createinstance() to create instances of classes defined in the library.

If you want to make a flowitem, use createcopy().



Phil BoBo
Sr. Manager, Software Development