question

Adam C avatar image
0 Likes"
Adam C asked Matthew Gillespie commented

Dynamic User Library Objects with User Input & External Connections

Hello,

I need some help on a rather involved problem to assist with scalability on a complex model. I have a user library object (visual tool containing an assortment of combiners, queues, and separators) that needs a lot of changes to occur in the dropscript (or maybe another method, if better). Once the object is dragged to the model, it should prompt the user for the ID number of the new object (think hotel room number). That ID number then needs to be written on labels of the visual tool and its child objects, and the visual tool name needs to change to reflect the ID. Finally, some A and S connects need to be made from other objects already in the model to a few of the child objects.

The generic pseudo-code below is basically how I have approached it. Setnodestr worked at one point, but it is messed up now due to meddling. It is backing out of the dropscript and diving down to the visual tool labels, borrowing from the Dropscript examples. There are also issues with how to change the new object's name without permanently changing the user library object (or how to change it back after creating the object).

Any guidance is appreciated!

  1. treenode newitem = dropuserlibraryobject(node("..>item",c));
  2.  
  3. userinput(globalvariableA,"Please input text value for label A");
  4.  
  5. setnodestr(node("..>item/labels/labelA", c), globalvariableA);
  6.  
  7. setnodestr(node("..>item>subitem/labels/labelA", c), globalvariableA);
  8.  
  9. contextdragconnection(externalobject1,item,"A");
  10.  
  11. contextdragconnection(item,externalobject2,"A");
  12.  
  13. contextdragconnection(externalobject3,item,"S");
  14.  
  15. replacename(node("..>item",c),"item",globalvariableA);
  16.  
  17. return newitem;
FlexSim 17.1.6
user librarydynamicuser inputconnections activities from code
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

Matthew Gillespie avatar image
0 Likes"
Matthew Gillespie answered Matthew Gillespie commented

You shouldn't set anything on the library object. The newitem returned from the dropuserlibraryobject command is the new instance of the library object created in the model. You should modify that object, something like this:

  1. treenode newitem = dropuserlibraryobject(node("..>item",c));
  2.  
  3. userinput(globalvariableA,"Please input text value for label A");
  4.  
  5. newitem.labelA = globalvariableA;
  6. newitem.subnodes[1].labelA = globalvariableA;
  7.  
  8. contextdragconnection(externalobject1,newitem,"A");
  9. contextdragconnection(newitem, externalobject2,"A");
  10. contextdragconnection(externalobject3,newitem,"S");
  11.  
  12. newitem.name = globalvariableA;
  13.  
  14. return newitem;

Note that you can access labels of objects by name using dot syntax.

· 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.