Topics
Dropscript Example
Create a new user library by going to File > New User Library. Click on the down arrow next to the newly created User Library in the Librar Icon Grid and select Explore Tree.
You should now see an empty tree.
Insert a new object into the library by right clicking on it and selecting Node > Insert Into, or by left-clicking on it and hitting the Enter key. Expand the user library tree so you can see the node you created by pushing the plus button. Give it the name "Custom". Now add object data to the node by right-clicking on it and selecting Node > Add Object Data or by left-clicking on the node and hitting the O key. Click on the button to expand the object. Then insert an attribute node by clicking on the object node and hitting the Enter key. Give the attribute node the name "dropscript". The tree should appears as follows.
Add text to the dropscript attribute by right-clicking on it and selecting Node > Add Text Data or by left-clicking the node and pressing the T key. Toggle the node as flexscript by right-clicking on it and selecting Build>Toggle as FlexScript. Give the attribute the following flexscript text:
msg("Object Dropped", concat( "Onto Object: ", getname(parnode(1)), "/n", "X: ", numtostring(parval(2),2,2), "/n", "Y: ", numtostring(parval(3),2,2), "/n", "Z: ", numtostring(parval(4),2,2), "/n", "Onto View: ", getname(parnode(5)) ) );
Click off of the attribute node, then right-click it and select Build>Build Node FlexScript.
Finally, add a picture attribute to the attribute tree of the object by right-clicking on the drop-script node and selecting Node > Insert After. Name the new node "picture". The libraries icon grid will only show the object in the grid if the object has a picture attribute. Usually this is a path to a bitmap file that represents the picture that is shown in the icon grid for that object. In our case we won't worry about that and will just leave the picture attribute blank, which causes only the object text to be shown in the grid. The tree should appear as follows.
The library icon grid should appear as follows.
Now drag the Custom icon from the Libary Icon Grid into the model. A message should appear.
This message is the code of the dropscript being executed. It shows the object that you dropped onto if there is one, an x, y and z location of the drop, and the view window that the object was dropped into. You can also drop it onto another object. Drag a regular library object into your model, then go back to the user library and drag the Custom object onto the object in the model. The following message should appear.
This time the message shows that it was dropped onto Source1. The x, y and z locations are now relative to the source object.
Dropscript Dynamic Parameters Example
In this example, we will have an object that is created through our User Library that will have it's size defined by a Global Table.
Create a new User Library as described in the above Dropscript Example.
Drag-and-drop a processor object from the Library Icon Grid to the 3D view. Right click the processor and select Edit > Add to User Library > UserLibrary 1 to add it to our library.
We want to dynamically change the size of our processor as it is dragged into the 3D view. In order to accomplish this, we will use our Custom object with code in our dropscript node. We don't want our processor to show up in the Library Icon Grid, so we'll copy it into our Custom object as an attribute node.
Copy the processor object (left click and hit Ctrl+C). Left click on the Custom object and open the object's attribute tree if it is not currently open by pressing the . Hit the enter key to create a new attribute node in the Custom object. Left click the new node and hit Ctrl+P to paste the processor object. You can then delete the original processor object.
Create a new GlobalTable through Tools > Global Tables > Add. Name the table sizetable. Make your GlobalTable look as follows:
The values from this table will define the size of our processor.
Back in the Custom object, update the dropscript code to the following:
treenode ontoObj = parnode(1); double x = parval(2); double y = parval(3); double z = parval(4); treenode ontoView = parnode(5); treenode newprocessor = dropuserlibraryobject(node("..>processor", c), ontoObj, x, y, z, ontoView); setnodenum(spatialsx(newprocessor), gettablenum("sizetable", 1, 1)); setnodenum(spatialsy(newprocessor), gettablenum("sizetable", 1, 2)); setnodenum(spatialsz(newprocessor), gettablenum("sizetable", 1, 3)); return newprocessor;
Right click the dropscript node and select Build > Build Node FlexScript.
Now create a Custom object by dragging and dropping it from the Library Icon Grid to a 3D view. Notice the size of the object has been altered by our dropscript.
Note: This is the proper way to dynamically change parameters or variables of a custom library object when it is dropped into a view (though it does not matter where the created object is contained). If you add a dropscript node straight to the processor, the processor will not be created. If you try and create the object in the processor's dropscript node, you will cause FlexSim to get into an infinite loop and crash.
Automatic Install Example
For this example, we will have the processor object from the Dropscript Dynamic Parameters Example be automatically installed when the user creates a new model.
Open the GlobalTable sizetable. Click on the button and select Add to UserLibrary 1 > As Auto-Install Component.
Open UserLibrary 1's Tree view by click the arrow next to the User Library in the Library Icon Grid and select Explore Tree.
Expand the library's attributes tree by pressing the button next to UserLibrary 1. The tree should appear as follows.
Press the plus button next to the newmodelinstall to expand the node. Notice our sizetable already appears inside the node. This is important as our Custom object's dropscript refers to this GlobalTable.
Create a subnode of newmodelinstall by left-clicking the node and hitting the Enter key. Copy and paste the Custom object onto this new node.
Now you can hit the "New" button on the toolbar of File > New Model. You'll notice that there is a processor1 object in the 3D view and our sizetable in the GlobalTables. The newmodelinstall folder acts a set of objects that will be "dropped" into the model when a new model is created. The object's are "dropped" in that the same functionality is executed as when you actually drag an object from the icon grid. In the case of a dropscript object, the script is executed as if the object were dropped at the point (0,0,0) in the model.