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
|
|||
|
|||
Batch object rename
Hi,
In a case of I have 1000 objects named "ABC 1", "ABC 2"...."ABC 1000" I want to rename them to "DEF 1","DEF 2"...."DEF 1000" I found there is a command "replacename" but i don know where to use it... Thanks. Kelvin |
#3
|
||||
|
||||
Kelvin,
To your first post about the replacename() command. I would not use it in your case. But let’s say you have a Queue in your model and you like to rename the items in the queue you could use the command as follows: replacename(node("/Queue",model()),"ABC","DEF"); ABC 1 will transform into DEF 1. I would use the setname() command and read the item name and modifiy it in the way I like to have it. In your case you want transform ABC 1, ABC 100 into DEF 001, DEF 100. Here is the code I would use and again the items are in an object called Queue // POINTER TO QUEUE treenode Queue = node("/Queue",model()); // FOR ALL ITEMS IN QUEUE for(int iRank = 1; iRank <= content(Queue); iRank++) { // GET THE CURRENT NUMBER STRING string sNumber = stringcopy(getname(rank(Queue,iRank)),5,3); // TRANSFORM NUMBER STRING INTO INTEGER int iNumber = stringtonum(sNumber); // CHECK NUMBER AND SET STARTING ZEROS if(iNumber < 10) sNumber = concat("00",sNumber); if(iNumber >= 10 && iNumber < 100) sNumber = concat("0",sNumber); // SET NEW NAME OF ITEM setname(rank(Queue,iRank),concat("DEF ",sNumber)); } If you want to keep the existing name you could also use stringcopy() to store the name depending on its length. Depending on the length of your name and the number of starting zeros you like to have you need to modify the code a bit. But I am pretty sure, that you can figure this out by yourself. There are a lot of more string commands which can be used like stringcopy(), stringreplace(), stringsearch(), etc. So I am not sure if there is not a more elegant way to solve it (with less code), but that’s the way I would go. But maybe someone else has a nicer solution?
__________________
tom the (A)tom: "We have solved our problems ... now we have to fight the solutions." |
The Following 4 Users Say Thank You to Tom David For This Useful Post: | ||
Steven Hamoen (02-04-2010) |
Thread | Thread Starter | Forum | Replies | Last Post |
Batch Processor? | Anthony Timmiss | Q&A | 7 | 08-19-2009 10:11 AM |
Batch from Queue and capacity of operator | Michael Pohl | Q&A | 3 | 05-18-2009 01:42 AM |
Batch production (Batch size for processor) | Patrick Cap | Q&A | 12 | 03-27-2009 12:14 AM |
Batch/Max Content | Gavin Douglas | Q&A | 4 | 07-09-2008 12:28 AM |
creating a batch trip task sequence | Paul Dowling | Q&A | 5 | 09-11-2007 06:55 PM |