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
|
||||
|
||||
create an object from UserLibrary1
Hello
I have created a new object called Train in my User Library 1, and i would like to use code to replicate this object into my model at different locations. The code below works for a default object say a Transporter, Network Node, but it doesn't work for a newly created Train. treenode nnobj = node("/Transporter", library()); treenode tnode; for(int row = 1; row<=gettablerows("Train Names"); row++) { tnode = createinstance(nnobj, model()); setname(tnode, gettablestr("Train Names",row,2)); setloc(tnode, row,0,0); } Please have a look at the code, and advice what needs to be done. Thanks.... |
#2
|
||||
|
||||
This points to an object called Transporter in your library. And your userlibrary is not the same as your library. An easy way to find the path to your node is the following:
1 Open the tree 2 Select the node you want to point to 3 Right click -> edit -> Designate this node (so()) 4 Go to the script window and type: nodetopath( so() , 1) This will give you a path to the node. You can simply copy it: treenode nnobj = node("Your path"); This piece will also not work, because an object that you have put in a userlibrary is already an instance of a class object in the library. For that reason you can't use createinstance but you should use createcopy because you want a copy of an instance and not a new instance |
The Following 2 Users Say Thank You to Steven Hamoen For This Useful Post: | ||
Nischith Kashyap (04-10-2011) |
Thread | Thread Starter | Forum | Replies | Last Post |
Create a table with random values | Michael Hartlieb | Q&A | 7 | 08-05-2009 08:09 AM |
where to create operator TS ? | qin tian | Q&A | 3 | 10-22-2008 07:59 PM |
question to create my own objects | Kang Han | Q&A | 0 | 09-25-2008 01:17 AM |
is there a command opposite to "destroyobject" which create a object? | KelvinHo | Q&A | 3 | 07-03-2008 08:09 AM |
Create tables on the fly | AlanZhang | Tips and Tricks | 0 | 08-24-2007 06:01 PM |