Jump to content
Developer Wiki and Function Reference Links ×

Vectorscript - Select viewports on current sheet layer - Please help!


RvG

Recommended Posts

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);

Link to comment

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.

Link to comment

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);

 

Link to comment

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

  • Like 2
Link to comment
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)');

 

  • Like 2
Link to comment
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

  • Like 4
Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...