Dynamic User Library Objects with User Input & External Connections

Dynamic User Library Objects with User Input & External Connections

adam_c1
Not applicable
72 Views
3 Replies
Message 1 of 4

Dynamic User Library Objects with User Input & External Connections

adam_c1
Not applicable

[ FlexSim 17.1.6 ]

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;
0 Likes
Accepted solutions (1)
73 Views
3 Replies
Replies (3)
Message 2 of 4

Matthew_Gillespie
Autodesk
Autodesk
Accepted solution

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.



Matthew Gillespie
FlexSim Software Developer

0 Likes
Message 3 of 4

adam_c1
Not applicable

@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
Message 4 of 4

Matthew_Gillespie
Autodesk
Autodesk

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



Matthew Gillespie
FlexSim Software Developer

0 Likes