ATTENTIONThis 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 |
#1
|
|||
|
|||
Question on copyvariable
Hi
I am trying to copy the exittrigger from one source to another using code. This is what I used. switch_selected(node("Source3", model()),1); copyvariable(node("Source2", model()),node(">exittrigger", node("Source2", model()))); But an error appear "The variable that you specified does not exis on the highlighted object" What does it mean and why this happen? What is the right way of doing it?
__________________
Advent2 Labs David |
#2
|
||||
|
||||
Hi David,
This might be the code.You are not copying the variable to highlighted object but to itself.Other way to copy the variable into selected objects in the model is the command selectedobject() that gets the highlighted object. switch_selected(node("Source3", model()),1); copyvariable(node("Source3", model()),node(">exittrigger", node("Source2", model()))); or copyvariable(selectedobject(ownerview(c)),node(">e xittrigger", node("Source2", model()))); Last edited by sagar bolisetti; 06-24-2015 at 07:53 AM. |
The Following User Says Thank You to sagar bolisetti For This Useful Post: | ||
David Chan (06-24-2015) |
#3
|
|||
|
|||
sagar
First of all thanks for the reply. I have tried your suggestion. Unfortunately it did not work. what is ownerview(c)?
__________________
Advent2 Labs David |
#4
|
||||
|
||||
Hi David,
I am sorry selectedobject() does not gets the selected object(red bounding box) but the highlighted object(yellow bounding box) that won't work in this case.Ownerview() is the command that gets the topmost node of the view structure.In this code for source3 object I designate it as so().Please try the following code Code:
treenode object = so(); switch_selected(object,1); { pt(getnodename(object)); copyvariable(tonode(getnodename(object)),node(">exittrigger",node("Source2", model()))); } |
The Following 2 Users Say Thank You to sagar bolisetti For This Useful Post: | ||
Jörg Vogel (06-27-2015) |
#5
|
|||
|
|||
Sagar
Once again thanks for your help. By placing the above code recommended in the Script window, I have selected Source 3 as so(). The error given is that "No object is currently highlighted". Is there a miss?
__________________
Advent2 Labs David |
#6
|
|||
|
|||
Just use createcopy:
createcopy(getvarnode(fromobj,varname),assertvaria ble(toobj,varname,1),1,0,0,1); |
The Following 3 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
sagar bolisetti (06-27-2015) |
#7
|
|||
|
|||
Jason
Thanks. It works. But just wonder if there is some problem with this command and how it works? It is being used in the Edit Selected Object -> Copy from Highlighted. Don't quite understand.
__________________
Advent2 Labs David |
#8
|
|||
|
|||
There's no problem with the command - the second parameter is a node that contains the variable name as string data.
|
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
David Chan (06-29-2015) |
#9
|
|||
|
|||
Jason
Possible for you to show me how to use copyvariable to copy the exittrigger from Source2 to Source3. Because I keep have the error saying the variable does not exist in the highlighted object. Thanks
__________________
Advent2 Labs David |
#10
|
||||
|
||||
Hi David
We usually copy variables from highlighted object to selected object and the same we have to write in the form of code.The error we get because I have not set any highlighted object.The highlighted can be set by using the command setselectedobject() like switch_selected() for red selected objects .This highlighted object is accessed by the command selectedobject() and this command should be used in the first parameter of copyvariable.I was misunderstood the parameters of the copyvariable till yesterday.The two parameters of copyvariable belong to the same object that is highlighted and the variablenamenode are copied to selected object.But before using this copyvariable, we need to set the “selected” flag on the node.Thanks to Jason for suggesting createcopy() command that avoids writing redundant code. I just tried a small model but not successful yet.In this model if the input of sink is greater than 49 I want this copy operation to take place between highlighted and selected object.Someone may be able to put me in right direction. Code:
treenode item = parnode(1); treenode current = ownerobject(c); int port = parval(2); treenode object1 = inobject(current,1); treenode object2 = c; if(getinput(current)>49) { setselectedobject(ownerview(c),object2);//highlight object switch_selected(object1,1); if(switch_selected(object1,-1));//check to see if it is selected copyvariable(selectedobject(ownerview(c)),node(">entrytrigger",c)); deselectall();//Deselects all objects in the model stop(); } |
The Following User Says Thank You to sagar bolisetti For This Useful Post: | ||
David Chan (06-30-2015) |
#11
|
||||
|
||||
Hello David,
possibly you copied not the complete source code, but if it is your using code, you should write a slash "/" in front of the object name in the node-command. Because of the missing slash the engine can't find the variable. And beware of this mistake, you have had in every node-reference. switch_selected(node("/Source3", model()),1); Jörg |
The Following User Says Thank You to Jörg Vogel For This Useful Post: | ||
David Chan (06-30-2015) |
#12
|
|||
|
|||
Jorge,
Thanks. I have tried. It did not has any difference. When you use the sampler, the node is given without the /. So I am unsure that is problem. try out. Thanks
__________________
Advent2 Labs David |
#13
|
|||
|
|||
If you're just copying from one known object to another and not using a selection set, then why are you interested in finding the highlighted, selecting the target and using the command that is purposed for the GUI interface?
If it's for ease of reading your code, create a user command: copyVariable(<fromobj>, <toobj>,<variablename>) Code:
treenode fromobj=parval(1); treenode toobj=parval(2); string varname=parstr(3); createcopy(getvarnode(fromobj,varname),assertvaria ble(toobj,varname,1),1,0,0,1); |
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
sagar bolisetti (06-30-2015) |
#14
|
|||
|
|||
Sagar,
thanks. I kept having an error on the command ownerview(c). Try to run your model with out the "if" requirement. Check if you have the error too. David
__________________
Advent2 Labs David |
#15
|
||||
|
||||
Hi David,
Probably it has to do something with the VIEW tree to get the path of the trigger in the first parameter of setselectedobject().Btw you no longer require slash before the object name in Flexsim 7.See this Post |
The Following User Says Thank You to sagar bolisetti For This Useful Post: | ||
Jörg Vogel (06-30-2015) |
#16
|
||||
|
||||
Hello Sagar,
I think it has more to do with getting an object highlighted by command [yellow frame]. Selecting an object works [red frame], but how to write a source code wherein the simple procedure is implemented clicking with the mouse pointer on an object. Jörg |
The Following 2 Users Say Thank You to Jörg Vogel For This Useful Post: | ||
sagar bolisetti (06-30-2015) |
#17
|
||||
|
||||
Hi all,
If we use activedocumentnode() command as parameter 1 in the setselectedobject command, the second parameter, which is an object will be yellow highlighted. treenode acc = activedocumentnode(); setselectedobject(acc,current); In the attached model, the setselectedobject command is selecting the object which is the 2nd parameter. Moreover, the owner view of the object going to be selected is the perspective view. So when I use activedocumentnode(), it returns a reference to the perspective view, which is the active document node. If I am wrong anywhere, please correct me. Regards, Arun KR Last edited by arunkrmahadeva; 06-30-2015 at 10:42 AM. Reason: adding more description |
The Following 3 Users Say Thank You to arunkrmahadeva For This Useful Post: | ||
sagar bolisetti (06-30-2015) |
#18
|
||||
|
||||
Hi Jorg,
Absolutely!In the midway of solving this problem after going through some relevant commands I realized that these commands are more for developers than for regular users like getting the node associated with the window.I am happy that i have learnt few commands. @Arun:Thanks,that’s the right command.Somemore information while using this command activedocumentnode() https://www.flexsim.com/community/fo...77&postcount=4 Last edited by sagar bolisetti; 06-30-2015 at 11:29 PM. |
The Following User Says Thank You to sagar bolisetti For This Useful Post: | ||
David Chan (07-01-2015) |