Jump to content
  • 0

Turn Layer & Class On/Off All Viewports


Jim Smith

Question

Maybe there's a way to do this, but from time to time I need a new Layer or Class & either forget to make it visible to all at the time of creation, or a situation changes & want to show this Layer or Class on all (or mostly all) Viewports. 

 

Alternatively  I'd like to be able to select several  Viewports & turn on a Layer of Class. 

Link to comment

14 answers to this question

Recommended Posts

  • 0
1 hour ago, Jonathan Pickup said:

Of course, you need to have named your viewports correctly. 


Naming viewports is also essential for linking viewports. There is an amazing script that renames viewports: sht no./dwg no./dwg title. Saves SO much time. Can dig it out on Monday if you want it. 

  • Like 2
Link to comment
  • 0
On 10/19/2019 at 11:49 AM, Boh said:

Naming viewports is also essential for linking viewports. There is an amazing script that renames viewports: sht no./dwg no./dwg title. Saves SO much time. Can dig it out on Monday if you want it. 

There are two scripts below - I use these all the time. Credit to @michaelk.

 

Rename selected viewport: 

{This script will take all selected viewports and change the name of those viewports to be

        (Sheet Layer) (Drawing Number) (Drawing Name)

Procedure ViewportRename;

{Badly Scripted by Michael Klaers.  Updated Aug 2, 2015}

{This script will take all selected viewports and change the name of those viewports to be

		(Sheet Layer) (Drawing Number) (Drawing Name)

This version tries to force the name to appear immeidately in the name field, data tab, OIP when only one VP is selected.

Prior to this version the new name appeared immediately in the Nav Palette, but not in the name field.}


	Var
	VPDwgTitle,VPName,BText,VPNum : String;	
	h,hh:  Handle;
	ViewportLayer: Handle;
	ViewportLayerString: String;

	
	


	Procedure RenameVP(h : HANDLE);
Begin							{***********  BEGIN Procedure  ***********}	
	ViewportLayer:= GetLayer(h);
	ViewportLayerString:= GetLName(ViewportLayer);
	VPDwgTitle := GetObjectVariableString(h, 1032);
	VPNum := GetObjectVariableString(h, 1033);
	ResetObject(h);


{	Message('Viewport Handle: ',h,chr(13), 
			'Layer Handle: ',ViewportLayer,chr(13),
			'Layer Name: ',ViewportLayerString,chr(13),
			'VP Num: ',VPNum,chr(13),
			'VP Name: ',VPDwgTitle);
}

	SetName(h, Date(2,2));
	SetName(h, CONCAT(ViewportLayerString,' ',VPNum,' ',VPDwgTitle));

	SetDSelect(h);		{These two commands are just here to force the new name to appear in the }
	SetSelect(h);		{name field immediately.  They can be deleted w/o consequence}

End;							{***********  END Procedure  ***********}



Begin							{***********  Main Program  ***********}	

	ForEachObject(RenameVP,(((T=VIEWPORT) & (SEL=TRUE))));

End;

Run(ViewportRename);




Rename all viewports. 

{This script will take all selected viewports and change the name of those viewports to be

        (Sheet Layer) (Drawing Number) (Drawing Name)

Procedure ViewportRename;

{Badly Scripted by Michael Klaers.  Updated Aug 2, 2015}

{This script will take all selected viewports and change the name of those viewports to be

		(Sheet Layer) (Drawing Number) (Drawing Name)

This version tries to force the name to appear immeidately in the name field, data tab, OIP when only one VP is selected.

Prior to this version the new name appeared immediately in the Nav Palette, but not in the name field.}


{Forked version.  Sept 10 2018

This version will rename all viewports in the drawing regardless of what is currently selected.}

	Var
	VPDwgTitle,VPName,BText,VPNum : String;	
	h,hh:  Handle;
	ViewportLayer: Handle;
	ViewportLayerString: String;

	
	


	Procedure RenameVP(h : HANDLE);
Begin							{***********  BEGIN Procedure  ***********}	
	ViewportLayer:= GetLayer(h);
	ViewportLayerString:= GetLName(ViewportLayer);
	VPDwgTitle := GetObjectVariableString(h, 1032);
	VPNum := GetObjectVariableString(h, 1033);
	ResetObject(h);


{	Message('Viewport Handle: ',h,chr(13), 
			'Layer Handle: ',ViewportLayer,chr(13),
			'Layer Name: ',ViewportLayerString,chr(13),
			'VP Num: ',VPNum,chr(13),
			'VP Name: ',VPDwgTitle);
}

	SetName(h, Date(2,2));
	SetName(h, CONCAT(ViewportLayerString,' ',VPNum,' ',VPDwgTitle));

	SetDSelect(h);		{These two commands are just here to force the new name to appear in the }
	SetSelect(h);		{name field immediately.  They can be deleted w/o consequence}

End;							{***********  END Procedure  ***********}



Begin							{***********  Main Program  ***********}	

	ForEachObject(RenameVP,((T=VIEWPORT)  ));

End;

Run(ViewportRename);




 

  • Like 2
Link to comment
  • 0
17 hours ago, Boh said:

There are two scripts below - I use these all the time. Credit to @michaelk.

 

 

Hi Boh!  Glad you like them.  I use these scripts every day, also 😁.

 

I'm not terribly good at writing scripts - this one is just simple enough that I could handle it.  

 

But I have to extend credit to the hardworking men and women who frequent the vectorscript forum who are always helping me out.  For example, I know this is the script where I learned from @PatStanford the trick of naming something the current date down to the second to make sure you don't have a duplicated name.

 

 

  • Like 1
Link to comment
  • 0

@Boh This script is great, thank you! I have never ran a script before (27 years on VW!) and am wondering if you could tell me how to simply insert an underscore _ after the page name, and thena lso after the VP number, so that it's more legible? I tried to do it in several parts of the script, but then I got error messages. I can't find the obvious place... 
 

Thanks so much! 

Meret

 

Link to comment
  • 0

@Meret

 

Look for the line 

SetName(h, CONCAT(ViewportLayerString,' ',VPNum,' ',VPDwgTitle));

 

SetName is the function that sets the name of an object in Vectorworks.  Believe it or not, not every function is named in such a helpful way.

 

h is the variable that points at the object that you want to name.

 

CONCAT means concatenate.  Take all of the following objects and stick them together.  The format is any piece of text or any number separated by commas will be glued together.  If the text or number is a variable, just put the name of the variable.  If you want to add your own text, put it in single quotes. (If your own text includes a single quote, reconsider the choices you've made in life.  If you still want a single quote as part of your text and you are fond of falling down rabbit holes, post back.)

 

So in this case it's the Sheet Layer Number COMMA 'SPACE' COMMA Viewport Number COMMA 'SPACE' Viewport Drawing Title.  This will create a name in the format like this

 

A1 3 Site Plan

 

You can add anything you want inside the single quotes or add another comma and anything you want in single quotes.  So you can put the underscore in the existing single quotes (if I understand correctly what you are trying to do.)

 

SetName(h, CONCAT(ViewportLayerString,'_',VPNum,'_',VPDwgTitle));

 

Should give you 

 

A1_3_Site Plan

 

While you are in the script editor and using VectorScript (as opposed to Python) you can click on the gear at the top and it will test compile the code and alert you to any syntax errors - including the line with the issue and what it thinks the issue is.  It's often misleading, but you can eventually learn in what ways it's misleading.  So it's super helpful.

 

 

  • Like 1
  • Love 1
Link to comment
  • 0
12 minutes ago, michaelk said:

 It's often misleading, but you can eventually learn in what ways it's misleading.  So it's super helpful.

It is often misleading because it notices the error when it tries to compile the next line in the script.  So often the error is not in the line it says, but one (or more) lines above. This is especially true for things like mismatched quotes or parentheses.

  • Like 3
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
Answer this question...

×   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...