Jump to content

Script to class Sheet Layer objects


Recommended Posts

"""
This a global script that affects all sheet layers.  It classes all objects on sheet layers as follows.
Viewport Drawing labels to class = Sheet-Label
Viewport Annoatations to class = Sheet-Anno
Viewports and sheet items = Sheet-Main
Redlines remain on Notes-Redlines or A-ANNO-REDL

All classes listed above are turned on on all viewports. 

This Python Script may be freely distributed. No warranty provided.
Use at your own risk.

David Hamer, 2020 revision 07-31-2020
"""

# collect handles of selected VPs on active layer
def GetHandle(h):
	if vs.GetObjectVariableInt(vs.GetLayer(h), 154) == 2:
		if vs.GetObjectVariableString(h, 1166) != 'Redline Object':
			vs.SetClass(h, 'Sheet-Main')
		if vs.GetTypeN(h) == 122:
			hVP.append(h)

ACName = vs.ActiveClass()  # Record name of active class

ClassCount = vs.ClassNum()  # determine number of classes in drawing
vs.NameClass('Sheet-Main')  # Creates class if it does not exist and sets properties
if ClassCount + 1 == vs.ClassNum(): 
	vs.NameClass('Sheet-Main')
	vs.SetClFillFore('Sheet-Main',0,0,0)
	vs.SetClFillBack('Sheet-Main',0,0,0)
	vs.SetClPenFore('Sheet-Main',65535,65535,65535)
	vs.SetClPenBack('Sheet-Main',65535,65535,65535)
	vs.SetClFPat('Sheet-Main',1)
	vs.SetClLSN('Sheet-Main',2)
	vs.SetClLW('Sheet-Main',10)
	vs.EnableCLDropShadow('Sheet-Main',False)
	vs.SetClUseGraphic('Sheet-Main',True)

ClassCount = vs.ClassNum()  # determine number of classes in drawing	
vs.NameClass('Sheet-Label')  # Creates class if it does not exist and sets properties
if ClassCount + 1 == vs.ClassNum():  
	vs.NameClass('Sheet-Label')
	vs.ShowClass('Sheet-Label')
	vs.SetClFillFore('Sheet-Label',0,0,0)
	vs.SetClFillBack('Sheet-Label',0,0,0)
	vs.SetClPenFore('Sheet-Label',65535,65535,65535)
	vs.SetClPenBack('Sheet-Label',65535,65535,65535)
	vs.SetClFPat('Sheet-Label',1)
	vs.SetClLSN('Sheet-Label',2)
	vs.SetClLW('Sheet-Label',28)
	vs.EnableCLDropShadow('Sheet-Label',False)
	vs.SetClUseGraphic('Sheet-Label',True)

ClassCount = vs.ClassNum()  # determine number of classes in drawing	
vs.NameClass('Sheet-Anno')  # Creates class if it does not exist and sets properties
if ClassCount + 1 == vs.ClassNum():  
	vs.NameClass('Sheet-Anno')
	vs.ShowClass('Sheet-Anno')
	vs.SetClFillFore('Sheet-Anno',0,0,0)
	vs.SetClFillBack('Sheet-Anno',0,0,0)
	vs.SetClPenFore('Sheet-Anno',65535,65535,65535)
	vs.SetClPenBack('Sheet-Anno',65535,65535,65535)
	vs.SetClFPat('Sheet-Anno',1)
	vs.SetClLSN('Sheet-Anno',2)
	vs.SetClLW('Sheet-Anno',10)
	vs.EnableCLDropShadow('Sheet-Anno',False)
	vs.SetClUseGraphic('Sheet-Anno',True)
	
vs.NameClass(ACName)  # Return active class

hVP = []
vs.ForEachObjectInLayer(GetHandle, 0, 2, 1)

# Traverse into the annotations group of selected VPs and set classes
for VP in hVP:
	vs.SetVPClassVisibility(VP,'Sheet-Anno',0)
	vs.SetVPClassVisibility(VP,'Sheet-Label',0)
	vs.SetVPClassVisibility(VP,'Sheet-Main',0)
	vs.SetVPClassVisibility(VP,'Notes-Redlines',0)	
	vs.SetVPClassVisibility(VP,'A-ANNO-REDL',0)
	anno = vs.GetVPGroup(VP, 2)
	h = vs.FInGroup(anno)
	objs = [h]
	h = vs.NextObj(h)
	while h != vs.Handle(0):
		if vs.GetObjectVariableString(h, 1166) == 'Drawing Label':
			vs.SetClass(h, 'Sheet-Label')
			vs.SetLWByClass(h)
			vs.SetFPatByClass(h)
			vs.SetLSByClass(h)
			vs.SetFillColorByClass(h)
			vs.SetOpacityByClass(h)
			vs.SetPenColorByClass(h)
		else:
			if vs.GetObjectVariableString(h, 1166) != 'Redline Object':
				vs.SetClass(h, 'Sheet-Anno')
				if vs.GetTypeN(h) == 11:
					gobj = vs.FInGroup(h)
					while gobj != []:
						vs.SetClass(gobj, 'Sheet-Anno')
						gobj = vs.NextObj(gobj)
		h = vs.NextObj(h)

 

Edited by The Hamma
  • Like 1
Link to comment
  • 2 years later...
4 minutes ago, Jiajing said:

Circling back to it, I am having hard to find those INDEXes from Appendix, for instance, not sure 1166 means in GetObjectVariableString, is there a doc with full list of index. 

Find it here

https://developer.vectorworks.net/index.php/VS:Function_Reference_Appendix_F

or the root

https://developer.vectorworks.net/index.php/VS:Function_Reference_Appendix

  • Like 1
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...