question

Donghuang L3 avatar image
0 Likes"
Donghuang L3 asked Jason Lightfoot edited

Lost object attributes when creating instances from custom library.

Hi, I have created my User Library for Custom Objects, and use FlexScript codes to generate object instances.
I included some scripts under the behaviour attributes (the OnPreDraw codes) -- I realize that such scripts may need to be build explicitly using Build Node FlexScript.
I found that, when using the createinstance() method, the behaviour attributes of the Customer Object is lost (while all other attributes are OK). However, when I directly drag a copy from the library to the model, such attributes were kept.
Would you please help me figure out how to keep those attributes while using codes only to create object instances? Thanks.

Object Behaviour configured in User Library:
1691952882481.png



Object Behaviour lost when created using createinstance() method:
1691952882481.png


1691952899062.png1691952899062.png


FlexSim 23.2.0
user librarycreateinstance
1691952882481.png (17.5 KiB)
1691952899062.png (15.0 KiB)
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

·
Jason Lightfoot avatar image
1 Like"
Jason Lightfoot answered Jason Lightfoot edited

createinstance() is for creating instances of classes from the main library. You should be using ceatecopy().

· 6
5 |100000

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

Donghuang L3 avatar image Donghuang L3 commented ·
Thank you for replying, Jason. Is it possible to create instances directly from the library treenode that keeps all the behaviour attributes? Those FlexScript attributes are already configured inside the library treenode (as illustrated earlier).


If not possible, I know I could create an object in the model first, and then create copies of this object -- but that is not quite what I want because I am developing an auto-generation tool for simulation models.
0 Likes 0 ·
Jason Lightfoot avatar image Jason Lightfoot ♦ Donghuang L3 commented ·
The behavior nodes aren't needed on the model instances to inherit the behavior. If you add them to an instance you are overriding the behavior and have to use inheritcode() to make it perform the class's default behavior. If you have an instance in your user library with an overridden behavior node, then the copy you make in the model will also have that node.


0 Likes 0 ·
Donghuang L3 avatar image Donghuang L3 Jason Lightfoot ♦ commented ·

Yes, I did use inheritcode() to override the object's default behavior, as shown below. I configured this script under the object's "behaviour" node in the library. When I directly drag this object (from the toolbar) to the model window, the script is inherited perfectly; However, when I use createinstance(), the script is not inherited.

1692036064117.png

(this is a solution provided by Julie Weller in another question on visualizing items on the ASRS-vehicle:
Position / visualize multiple items on ASRS Vehicle (Crane Slider) - FlexSim Community)

0 Likes 0 ·
1692036064117.png (51.6 KiB)
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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