question

Nathan S7 avatar image
0 Likes"
Nathan S7 asked Phil BoBo edited

Trigger on user library object not properly loading

I have a few objects with custom triggers that I would like to add to my model with custom code. If I simply drag the object on the model view, all of the triggers load correctly.

However, if I try to create the object using the following code:

Object newProcessor = createinstance(maintree().find("project/userlibrary/UserLibrary 1/Custom Object"), model());

One of my triggers, namely On State Change, is no longer present. Any idea as to why this would occur?

FlexSim 20.0.2
user library
· 2
5 |100000

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

tannerp avatar image tannerp commented ·

Maybe try using the createcopy() function rather than createinstance() function? I'm not sure if that will work on a custom object. Do you have the code and/or an example model you could upload so we can test things on our end?

1 Like 1 ·
Nathan S7 avatar image Nathan S7 tannerp commented ·

createcopy() works! Although I think the reason it was not properly creating instances was due to a problematic reference in the code. Thanks!

0 Likes 0 ·

1 Answer

Phil BoBo avatar image
1 Like"
Phil BoBo answered Phil BoBo edited

You should be using createcopy() to create copies of user library objects.

Objects in user libraries are not defining classes of objects. They are instances already and you are simply copying them.

You should only call createinstance() on a a class object defined in MAIN:/project/library.

5 |100000

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