PDA

View Full Version : findInCode User Command


Jason Lightfoot
11-05-2009, 06:49 PM
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 :
findInCode("objectexists");

If you specify a node as a second parameter it will only search from that point down in the tree, otherwise it will search through the model, including the /Tools folder. eg:
findInCode("TASKTYPE",node("/Processor",model()));

Just open this library into your libraries and it will autoinstall the user command into your model.

Have fun.

Jason

Phil BoBo
11-06-2009, 08:51 AM
Jason,

Awesome.

Vincent Bechard
11-06-2009, 11:39 AM
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: http://www.flexsim.com/community/forum/showthread.php?goto=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

Luciano
11-16-2009, 06:54 AM
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

Jason Lightfoot
11-17-2009, 07:05 PM
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

Steven Hamoen
11-18-2009, 02:45 AM
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

Lars-Olof Leven
11-18-2009, 06:30 AM
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

Jason Lightfoot
11-18-2009, 04:27 PM
In this version the tree views also mark the lines of text containing the search string.

Kris Geisberger
11-20-2009, 01:18 AM
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

Vincent Bechard
11-23-2009, 08:18 AM
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!

Steven Hamoen
11-27-2009, 07:04 AM
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.:D

Steven

Jason Lightfoot
11-29-2009, 04:36 AM
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.

Steven Hamoen
11-30-2009, 02:57 AM
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

Jason Lightfoot
11-30-2009, 03:21 AM
Updated to account for the maintree() as the root of the search, and corrected the switch_dllfunc error

Steven Hamoen
11-30-2009, 03:43 AM
Hi Jason,

It seems to work fine now. Thanks for the quick reply!

Steven

Nico Zahn
01-14-2010, 03:48 AM
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....:o

Jason Lightfoot
01-14-2010, 06:51 AM
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.

Jason Lightfoot
01-14-2010, 12:04 PM
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!