MarcelP102 Posted July 5, 2022 Share Posted July 5, 2022 I'm building a script to smarter and faster select similar objects then the default tool can do. I've got the first part of the code working but I'm unable to make it work within a symbol. FSActLayer returns the symbol name instead of the selected object. Before I used "SelectObj(selCriteria);" to select the objects. I read somewhere that "ForEachObject(SelectThem, selCriteria);" can work within symbols. But somehow I use it wrong I think. Any help would be appreciated. PROCEDURE SelectSimilarSubtype; {Select similar objects based on select object type and sub-type} {© 5-7-2022 Arnhem - The Netherlands, Marcel Plomp} VAR Hd :HANDLE; selCriteria :STRING; iObjectType :INTEGER; PROCEDURE SelectThem(h :HANDLE); BEGIN SetSelect(h); END; BEGIN Hd := FSActLayer; iObjectType := GetTypeN(Hd); CASE iObjectType OF {symbool} 15: selCriteria := CONCAT('S=''', GetSymName(Hd), ''''); {wall} 68: selCriteria := CONCAT('WST=''', GetWallStyle(Hd),''''); {text} 10: selCriteria := CONCAT('TSTY=''', Index2Name(getTextStyleRef(Hd)),''''); {roof} 83: selCriteria := CONCAT('RST=''', Index2Name(GetRoofStyle(Hd)),''''); {PIO} 86: selCriteria := CONCAT('PST=''', GetPluginStyle(Hd),''''); END; {CASE} DSelectAll; message(selCriteria); ForEachObject(SelectThem, selCriteria); END; RUN(SelectSimilarSubtype); Quote Link to comment
MullinRJ Posted July 5, 2022 Share Posted July 5, 2022 (edited) If adding INSYMBOL to your criteria doesn't do what you want, you might need to use one of the other ForEachObject... functions. Then you might need to use "Waldo". If you search the Forum you should find references to this mysterious name. Essentially Waldo, (reminiscent of "Where's Waldo") is the colloquial name given to a function that gets an object handle when you are running a script inside a container object, like a Symbol Definition, or a Group, and you only want to process the objects in that container. When you are working on a Design Layer, then FSActLayer works well. Waldo's will also work on Design Layers. Try: function Waldo1 :Handle; { return handle to selected object on bottom of stacking order } Begin Locus(0, 0); { drop a bread crumb } HMoveBackward(LNewObj, True); { move it to the front of stacking order } Waldo := NextSObj(LNewObj); { use NextSObj or NextObj, as required } DelObject(LNewObj); { remove bread crumb } End; function Waldo2 :Handle; { return handle to selected object on top of stacking order } Begin Locus(0, 0); { drop a bread crumb } Waldo := PrevSObj(LNewObj); { use PrevSObj or PrevObj, as required } DelObject(LNewObj); { remove bread crumb } End; If you are using the ForEachObjectInList() function, then use Waldo1, as the those functions work from the bottom up. If you are traversing a list manually, then you can choose which Waldo you need. Waldo1 works with NextObj() and NextSObj() in your program loop, where Waldo2 works with PrevObj(), and PrevSObj(). If you are specifically using ForEachObject(), then you are going to process the whole document. And there are other ways to navigate, but I cannot advise you further without knowing exactly how you intend your script to run. Pick your poison, carefully. HTH, Raymond Edited July 5, 2022 by MullinRJ 3 Quote Link to comment
MarcelP102 Posted July 5, 2022 Author Share Posted July 5, 2022 I found Waldo😉 thanks it's working now! Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.