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
|
|||
|
|||
findInCode User Command
Sometimes it's fairly laborious going through your code & triggers when searching for some text, as the standard Find/Replace is printed to the console.
This user command lets you right-click a table of search results that it generates to edit the code directly. It also shows you on which line(s) in the code the text you're searching for is located (thanks Phil for pointing me towards the code for that). You can use it in a script window like : Code:
findInCode("objectexists"); Code:
findInCode("TASKTYPE",node("/Processor",model())); Have fun. Jason Last edited by Jason Lightfoot; 11-06-2009 at 04:25 AM. |
The Following 13 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
zhang xin (11-06-2009) |
#3
|
|||
|
|||
Updated version
Hi,
Amazing!!!! This will increase productivity! I modified it a little bit. Deprecated commands have been replaced by their current implementation, and the UserCommand can now be c++ compiled. This is very useful in my context, see thread: https://www.flexsim.com/community/fo...=newpost&t=542. I strongly recommend to upgrade the find/Replace in Tree, for version 5.0. Vincent Béchard, ing., M.Sc.A. Simulation & optimization __________________________ SNC-Lavalin Devonyx Inc. 360, St-Jacques O. Montréal (Canada) H2Y 1P5 514-845-2166 #2204 **UPDATE** The attachments were lost in a server crash. These features have now been included natively in FlexSim Software, making this attachment obsolete. Last edited by Ben Wilson; 11-19-2014 at 02:58 PM. Reason: attachments lost in server crash |
The Following 5 Users Say Thank You to Vincent Bechard For This Useful Post: | ||
Tom David (11-11-2009) |
#4
|
|||
|
|||
Updated Version
Hi,
Thanks Jason and Vincent for the library. Very Useful! Attached a new version that open the code edit window also with a doubleclick on the selected cell of the results search table. Luciano Cavallero Flexcon s.r.l. Viale Risorgimento, 16 I–10092 Beinasco (TO) - Italy phone +39-011-19682600 fax +39-011-19682640 |
The Following 8 Users Say Thank You to Luciano For This Useful Post: | ||
Tom David (11-16-2009) |
#5
|
|||
|
|||
Update #3
Hi again and thanks for the feedback and help!
I've now marked the row of each result with S,C or D (or blank - see below) to indicate what type of node it is (flexscript,C or DLL). I've also added findInText() which searches all string data nodes, not just those toggled as code. This is useful if you're using executefsnode or want to find text within scripts in GUIs. The 'non-code' node you want to edit will open in a tree view with the target as the head (and only) node. I haven't found a way to auto-mark the search text in the tree view for these types of nodes yet. Also be warned that there are no Cancel functions when editing the tree directly (although closing the window without clicking away from the node may produce this effect), so this isn't for the faint hearted. I'd recommend sticking with findInCode unless you know you need findInText. Jason |
The Following 6 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Tom David (11-17-2009) |
#6
|
||||
|
||||
update #4
I made a small addition to this superb usercommand. I added an openmodelinstall so that if you have this library loaded and you open a different model, the commands are automatically added so you don't have to load the library again to install those commands again.
Steven |
The Following 5 Users Say Thank You to Steven Hamoen For This Useful Post: | ||
Tom David (11-18-2009) |
#7
|
|||
|
|||
Hi,
I found a bug that caused Flexsim to crach, Jason help me found what the problem was. The problem was that I had a corrupt node in my model. I add a check to check if a node is okay or not, using objectexists solved the problem. Thanks Jason for put me in right direction. Lars-Olof |
The Following 5 Users Say Thank You to Lars-Olof Leven For This Useful Post: | ||
Tom David (11-18-2009) |
#8
|
|||
|
|||
Update #7
In this version the tree views also mark the lines of text containing the search string.
|
The Following 6 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Tom David (11-18-2009) |
#9
|
|||
|
|||
Update #8
Great work Jason and all for joining in!
I tend to have a short memory so I made the following additions: *the picklistedit window title displays the full path to the code *column added to the search results table that reports when you have pressed the OK button on a given picklistedit. Kris |
The Following 6 Users Say Thank You to Kris Geisberger For This Useful Post: | ||
Tom David (11-20-2009) |
#10
|
|||
|
|||
findString UserCommand
Hi,
Following to the posts on the wonderful findInCode command, here is a lighter version derived from version 8. The changes are: - all C++ nodes were tagged "D"; switch_cppfunc was used instead of switch_dllfunc for detecting DLL nodes - the right-click Edit Code option (menupopup) is removed; double-clicking on the row is so nice! - some deprecated flexscript functions are replaced; findString now C++-compiles successfuly - there is only one User Command which dows everything Here is the findString description: Search for the string "searchtext" in the subtree of startnode. If the flag alltexts is 0, search is limited to nodes toggled as code (FS, C++, DLL). If the flag alltexts is 1, search is extended to any node containing string data. The results table tells if the node containing searchtext is FS, C++, DLL or string data (F, C, F, or blank in row header, respectively). Double-click on a row of the results table to edit the code. If OK is pressed after editing the node, a OK word will appear in column 2. Enjoy! **UPDATE** The attachments were lost in a server crash. However, these features are now built in to FlexSim as of 2014. Last edited by Ben Wilson; 11-19-2014 at 02:56 PM. Reason: attachments lost in server crash |
The Following 3 Users Say Thank You to Vincent Bechard For This Useful Post: | ||
Tom David (11-23-2009) |
#11
|
||||
|
||||
Hi Guys,
I just try to use our command to find something. I looked for "ROUNDNUM" which is a macro used in the Fluids. Our command just came up with 1 hit in a user command in the model (which is the one I was working on) but the Flexsim find/replace command came up with 9 hits. So something is not 100% ok here. If somebody has to time to look into it, please be my guest. Steven |
#12
|
|||
|
|||
Steven did you use findInText ? This searches all the nodes with string data and should give the same results.
If you used findInCode and had user commands with the macro name in the command's code it would find those, but if the macro is referenced in the example of the user command, it wouldn't find those - so you would see a difference. I tried this in a model I have with the macro DISPATCHER and findInCode found 35 references while findInText found 928 - the same as the standard Find and Replace in Flexsim. |
#13
|
||||
|
||||
Hi Jason,
I used all commands. If you startup Flexsim blank and add the library and type: findInText( "ROUNDNUM", maintree()) you end up finding nothing. If you use the Flexsim find & replace and select main and then the project node (so MAIN:/1) you will find 2 occurences. Steven |
#14
|
|||
|
|||
Update #9
Updated to account for the maintree() as the root of the search, and corrected the switch_dllfunc error
Last edited by Jason Lightfoot; 12-01-2009 at 07:08 AM. |
The Following 5 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Tom David (11-30-2009) |
#16
|
||||
|
||||
Hi,
I really like this command. Need to find all strings in my code like =" so I tried findInCode(concat("=",strascii(34))); The command gives back a table with results, but it returns an error when I click on the tableentry to jump to the code....
__________________
kind regards Nico. |
#17
|
|||
|
|||
Nico we'll look into this - unfortunately I think there's a problem with the code needed to fix it which hopefully we'll resolve.
By the way you can use the escape character '\' to prefix a quotation mark (and other special characters) and thereby add it to your string: string str="=\""; assigns the two characters =" to the string str. |
The Following 2 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Phil BoBo (01-14-2010) |
#18
|
|||
|
|||
Okay, here's an update to take care of double quotation marks within the search string - thanks to Phil for pointing out a simple solution. There may be other string combinations (I'm thinking with escape characters) that also yield errors with the highlighting logic. If you find some - please post them here.
Good luck! |
The Following 5 Users Say Thank You to Jason Lightfoot For This Useful Post: | ||
Tom David (01-17-2010) |
#19
|
|||
|
|||
difference
Could someone tell me what is the difference between this library and the Find/Replace in a tree which you find in Edit menu?
|
#20
|
|||
|
|||
This was developed first and then added with alterations to version 5 as the find/replace in tree you mention. If you want to customize your own search then this might still be useful.
|
The Following User Says Thank You to Jason Lightfoot For This Useful Post: | ||
shafizad (05-22-2012) |