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!

treenode newitem = dropuserlibraryobject(node("..>item",c));

userinput(globalvariableA,"Please input text value for label A");

setnodestr(node("..>item/labels/labelA", c), globalvariableA);

setnodestr(node("..>item>subitem/labels/labelA", c), globalvariableA);

contextdragconnection(externalobject1,item,"A");

contextdragconnection(item,externalobject2,"A");

contextdragconnection(externalobject3,item,"S");

replacename(node("..>item",c),"item",globalvariableA);

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:

treenode newitem = dropuserlibraryobject(node("..>item",c));

userinput(globalvariableA,"Please input text value for label A");

newitem.labelA = globalvariableA;
newitem.subnodes[1].labelA = globalvariableA;

contextdragconnection(externalobject1,newitem,"A");
contextdragconnection(newitem, externalobject2,"A");
contextdragconnection(externalobject3,newitem,"S");

newitem.name = globalvariableA;

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.

Adam C avatar image Adam C commented ·

@Matthew Gillespie Thanks for your input. Between your comment and reviewing with some colleagues, this is mostly functional. There seems to still be an issue with retrieving the data (which is now stored directly to a label on the newitem object to cut out the global variable, which had issues) set with userinput. My more experienced colleague believes the code does not pause while the input box is open and that is the issue. He suggested making a custom GUI, but I am hoping there is a simpler fix

//call and drop new item
treenode itemn = dropuserlibraryobject(node("..>itemn",c));
Object newitem = itemn.as(Object);
//prompt user for item ID, store to variable, and write to labels
userinput(newitem.labels["labelA"],"Please input new item ID.");
string labelA = newitem.labels["labelA"].value;
newitem.subnode[1].labels["labelA"].value = labelA;
//make connections to external objects
contextdragconnection(model().find("ExternalObject1"),newitem.subnodes[1],"A");
contextdragconnection(model().find("ExternalObject1"),newitem.subnodes[1],"S");
//rename new item and return
newitem.name = labelA;
return newitem;
0 Likes 0 ·
Matthew Gillespie avatar image Matthew Gillespie ♦♦ Adam C commented ·

Yeah, the userinput command doesn't stop the rest of the code in the function from executing.

Here's an example where I use a custom GUI made from the GUI builder to ask for user input. The GUI is set to be modal so you can't do anything else in the model until the name is input. The OnPress of the OK button calls a function on the library object and passes it the input name. That function then sets the object's name and label.

customgui.fsm

0 Likes 0 ·
customgui.fsm (14.9 KiB)

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.