ATTENTION

This FlexSim Community Forum is read-only. Please post any new questions, ideas, or discussions to our new community (we call it Answers) at https://answers.flexsim.com/. Our new Question & Answer site brings a modern, mobile-friendly interface and more focus on getting answers quickly. There are a few differences between how our new Q&A community works vs. a classic, threaded-conversation-style forum like the one below, so be sure to read our Answers Best Practices.


flexsim.com

Go Back   FlexSim Community Forum > Downloads > Commands
Downloads

Latest Files
Latest Files
Most Popular Files
Most Popular Files
Top Contributors
Top Contributors
Tom David 47
Tyson Nordgren 35
Paul Toone 31
Matt Long 29
Phil BoBo 18
Regan Blackett 16
Cliff King 14
Cameron Pluim 11
Alex Christensen 8
Brandon Peterson 6

Uploaded files must be in one of the following formats: zip rar jpg jpeg jpg2 gif png pdf fsm xls xlsx doc docx ppt pptx

Please no copyrighted material without author's permission!!
  
Navigation
Main | Category Tree | Stats
Downloads [Download CreateAndConnect Command]
File Name: CreateAndConnect Command (1.7 KB) Download
Author: Cliff King)
Date Added: 09-24-2007
Downloads: 2161
Grade: D
Description
This is a custom User Command made available to you in a user library. The command can be used to automatically create instances of a library class object, position them in your model and connect their input and output ports to a specified object in your model. This is especially useful for creating a variable number of operators during an experiment and connecting them to a dispatcher.

Unzip contents of downloaded file into the libraries directory. Load library through the File menu of the Flexsim Library window.

Name:
CreateAndConnect

Parameters:
(int numobjs, treenode classobj, treenode fromobj, treenode toobj, double xoffset, double yoffset)

Description:
Create or delete instances of the classobj as needed, and connect with fromobj so that there are a total of numobjs connected to the output ports of the fromobj. If a toobj exists, then also connect the output ports of the new instances to the toobj. The relative position of each instance is defined by the xoffset and yoffset values. Each new instance gets a unique color and name based on the fromobj output port it is connected to.

The command is useful for trying a variable number of operators in a simulation experiment as suggested by the example below where the number of operators is defined by a label on the dispatcher object whose OnReset trigger executes the statement.

Example:
CreateAndConnect(getlabelnum(current, "NumOperators&quot, node("/Operator",library()), current, NULL, 2, 1);

Code:
int numobjs = parval(1);
treenode classobj = parnode(2);
treenode fromobj = parnode(3);
treenode toobj = parnode(4);
treenode curoobj = NULL;
double xoffset = parval(5);
double yoffset = parval(6);
//remove objects as needed
while(nrop(fromobj) > numobjs)
{
curoobj = outobject(fromobj,nrop(fromobj));
contextdragconnection(fromobj, curoobj, "Q");
destroyobject(curoobj);
}
//add objects as needed
while(nrop(fromobj) < numobjs)
{
createinstance(classobj, model());
curoobj = last(model());
contextdragconnection(fromobj, curoobj, &quot;A&quot;);
setname(curoobj, concat(getname(classobj), numtostring(nrop(fromobj), 0, 0)));
double xpos = xloc(fromobj) + xoffset;
double ypos = yloc(fromobj) - ((nrop(fromobj)-1) * yoffset);
setloc(curoobj, xpos, ypos, zloc(fromobj));
colorarray(curoobj, nrop(fromobj));
if(objectexists(toobj))
contextdragconnection(curoobj, toobj, &quot;A&quot;);
}
Images
None
Downloads [Download CreateAndConnect Command]


Comments
AlanZhang
01-29-2008 at 12:11 AM
This is great. But can you make it a little bit more useful so that we can create objects not only under model() but also under other containers, say visual tools? When I was trying to do that, I have issues setting locations of created objects. Thanks.

DownloadsII 5.1.2 by CyberRanger & Jelle
Based on ecDownloads 4.1 © Ronin

All times are GMT -6.
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.
Copyright 1993-2018 FlexSim Software Products, Inc.