RvG Posted August 30, 2022 Share Posted August 30, 2022 Hi, I made a very simple Vectorscript to select all the viewports on a Sheet Layer called "Aanzichten" (see below). Is it possible change it to the currently visible Sheet Layer instead? PROCEDURE SelectViewport; BEGIN; SelectObj(INSYMBOL & INVIEWPORT & ((ST=SECTVIEWPORT) & (L='Aanzichten'))); END; Run(SelectViewport); Quote Link to comment
Pat Stanford Posted August 30, 2022 Share Posted August 30, 2022 Untested, but something like: PROCEDURE SelectViewport; BEGIN; MyLayer:=GetLName(ActLayer); MyCriteria:=Concat('(INSYMBOL & INVIEWPORT & ((ST=SECTVIEWPORT) & (L=', MyLayer, '))'); SelectObj(MyCriteria); END; Run(SelectViewport); The trick is to set the entire criteria into a single string (DynArray of Char) variable and then use that variable in the procedure that needs the criteria. Use an AlrtDialog(MyCriteria) to make sure that you have all the parens and quotes in the right place to make it work. HTH. Quote Link to comment
RvG Posted August 31, 2022 Author Share Posted August 31, 2022 Thank you Pat, much appreciated. I got it working with the script below. With T=VIEWPORT I can get it to work for both section and regular viewports. Very nice, but for some weird way, the script isn't working on all sheet layers. The layer name reported back by AlrtDialog gives the correct name, but it's not working. Do you have any ideas/suggestions? PROCEDURE SelectViewport; VAR MyLayer : STRING; MyCriteria : STRING; BEGIN; MyLayer:= GetLName(ActLayer); MyCriteria:=Concat('(((L=', MyLayer, ') & (T=VIEWPORT)))'); AlrtDialog(MyCriteria); SelectObj(MyCriteria); END; Run(SelectViewport); Quote Link to comment
MullinRJ Posted September 1, 2022 Share Posted September 1, 2022 Hello @RvG, You are close. Your variable MyCriteria is missing two single quotation marks around the Layer Name. The final criteria string should look something like: (L='the Active SheetLayer Name') & (T=Viewport). Here's the Pascal syntax to achieve this. (I took the liberty of removing unneeded parentheses.) : MyCriteria := Concat('(L=''', MyLayer, ''') & (T=Viewport)'); Note, to get a single quote to display in a Pascal String, you need to use two single quotes in a row to represent one literal single quote. So, between the commas in the Concat() statement, the first and last single quotes are string delimiters, and all the single quotes between them should be doubled up (i.e., pairs of single quotes); each pair representing one literal single quote that is part of the string text. It takes some getting used to when you look at it the first time, or the second or third, but eventually it starts to make sense. Python handles this better with two sets of string delimiters to choose from. Another note: Did you notice the & character does not show up in the AlrtDialog() output? It's really in your criteria string, but there be "forces" in the AlrtDialog() call that suppress it. (Ask if you'd like to know the minutiae of WHY.) If you had used Message() instead of AlrtDialog() you would have seen the & character. HTH, Raymond 2 Quote Link to comment
Pat Stanford Posted September 1, 2022 Share Posted September 1, 2022 12 hours ago, MullinRJ said: Here's the Pascal syntax to achieve this. (I took the liberty of removing unneeded parentheses.) : MyCriteria := Concat('(L=''', MyLayer, ''') & (T=Viewport)'); Or my preferred version so that you don't need to use triple quotes. I use the Ascii code for the single quote instead. More characters to type but much easier to see what you have done. CHR(39) returns a single quote mark. MyCriteria := Concat('(L=',CHR(39), MyLayer, CHR(39),') & (T=Viewport)'); 2 Quote Link to comment
MullinRJ Posted September 1, 2022 Share Posted September 1, 2022 28 minutes ago, Pat Stanford said: Or my preferred version so that you don't need to use triple quotes. I use the Ascii code for the single quote instead. More characters to type but much easier to see what you have done. CHR(39) returns a single quote mark. MyCriteria := Concat('(L=',CHR(39), MyLayer, CHR(39),') & (T=Viewport)'); Hey @Pat Stanford, Good tip, but while we're on the topics of de-obfuscation and typing conservation, why not elevate the coding experience by declaring a constant to represent a single quote? Particularly in larger scripts, containing multiple formatted strings, I like to use Pascal Constants to represent Tabs, CarriageReturns, and in this case, SingleQuotes. It helps with readability, and faster typing, ... and it's self documenting. At the beginning of any script define the character constants as needed. This is a short list of my favorites followed by the formatting example: PROCEDURE SelectViewport; CONST Tb = chr(9); { TAB character } CR = chr(13); { Carriage Return character } SQ = chr(39); { Single Quote character } VAR ... BEGIN ... MyCriteria := Concat('(L=', SQ, MyLayer, SQ, ') & (T=Viewport)'); Raymond 4 Quote Link to comment
Pat Stanford Posted September 1, 2022 Share Posted September 1, 2022 Another good hint from a Pro. 👍 1 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.