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 > FlexSim Software > Q&A
Downloads

Q&A Using Flexsim and building models

  #1  
Old 04-06-2011
Nischith Kashyap's Avatar
Nischith Kashyap Nischith Kashyap is offline
Flexsim User
 
Join Date: Nov 2010
Location: Wollongong, Australia
Posts: 51
Downloads: 26
Uploads: 0
Thanks: 19
Thanked 0 Times in 0 Posts
Rep Power: 118
Nischith Kashyap is on a distinguished road
Default 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  
Old 04-07-2011
Steven Hamoen's Avatar
Steven Hamoen Steven Hamoen is offline
Talumis, Flexsim Distributor, The Netherlands
 
Join Date: Aug 2007
Location: Soest, NL
Posts: 854
Downloads: 43
Uploads: 0
Thanks: 391
Thanked 661 Times in 379 Posts
Rep Power: 684
Steven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond reputeSteven Hamoen has a reputation beyond repute
Default

Quote:
Originally Posted by Nischith Kashyap View Post
treenode nnobj = node("/Transporter", library());
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");


Quote:
Originally Posted by Nischith Kashyap View Post
tnode = createinstance(nnobj, model());
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


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.