Jonathan Pickup 273 Posted January 25, 2008 Hi, one of my clients asked for a script that would list all the classes in a file. Here is a quick script I knocked up. It doesn?t sort the classes alphabetically, it just exports the list of classes as they were made. Quote Share this post Link to post
Pat Stanford 1,428 Posted January 4, 2012 Here is a different version that does sort the classes alphabetically. Procedure Classes_to_Worksheet; {Make a worksheet listing all of the classes in a VW file} {Lists both used and unused classes} {The worksheet is named "Classes:"with and appended date} {October 13, 2010} {Updated to sort classes in alphabetical order prior to storing in worksheet} {As of VW2011, there is not way to get the display order of the classes in the Nav Palette} {October 14, 2008} {? 2010, 2008, Coviana, Inc - Pat Stanford pat@coviana.com} {Licensed under the GNU Lesser General Public License} var H1: Handle; N1: LongInt; ClassSort : Array[1..1024] of string; Begin H1:=CreateWS(Concat('Classes:',date(2,1)),Classnum+2,2); For N1:= 1 to Classnum do ClassSort[N1]:=ClassList(N1); SortArray(ClassSort,ClassNum,1); For N1:= 1 to Classnum do SetWSCellFormula(H1,N1+1,1,N1+1,1,ClassSort[N1]); SetWSCellFormula(H1,1,1,1,1,'Classes in File'); End; Run(Classes_to_Worksheet); Quote Share this post Link to post
Francois Levy 21 Posted September 18, 2017 Thanks, Pat! I needed this very script for my Design Summit Presentation! Is there a version for layers, separating design and sheet layers, and not alphabetizing them? I tried editing this one but swapping "layer" for "class" doesn't work... See you soon! Quote Share this post Link to post
cberg 195 Posted August 15, 2018 Has this changed for VW 2018? I am having difficulties with the Database Headers. Since they have changed. Quote Share this post Link to post
twk 233 Posted August 15, 2018 Updated version to @Pat Stanford's one, written in Python though, so make sure the interpreter Language is set to Python: import vs def classes_name_list(createOrder=0): """ createOrder=0, no sorting, list sorted based on class creation order createOrder=1, sorted Alphabetically """ classes_total = vs.ClassNum() classNameList = [] for x in range(classes_total): classNameList.append(vs.ClassList(x + 1)) if createOrder == 0: return classNameList elif createOrder == 1: classNameList.sort(key=lambda x: x.lower()) return classNameList date = vs.Date(2,1) classes = classes_name_list(1) # swap parameter for sorting in alphabetical order or order classes were created ws_handle = vs.CreateWS("Class List in Docuemnt: {}".format(date),len(classes)+2,2) for i, class_ in enumerate(classes): vs.SetWSCellFormulaN(ws_handle, i+1, 1, i+1, 1, class_) vs.ShowWS(ws_handle,True) Quote Share this post Link to post
SophieGW 0 Posted November 5, 2018 thanks for the script @twk I was wondering if anyone could help me with a script that draws an object (say a rectangle and text next to it with the name of the class) of each class within a document. Many thanks Quote Share this post Link to post
twk 233 Posted November 5, 2018 Here you go: You need to turn on all your classes visibilities (obviously) import vs def classes_name_list(createOrder=0): """ createOrder=0, no sorting, list sorted based on class creation order createOrder=1, sorted Alphabetically """ classes_total = vs.ClassNum() classNameList = [] for x in range(classes_total): classNameList.append(vs.ClassList(x + 1)) if createOrder == 0: return classNameList elif createOrder == 1: classNameList.sort(key=lambda x: x.lower()) return classNameList layer_scale = vs.GetLScale(vs.ActLayer()) #page mm scale 1:1 square_dim = 5 * layer_scale spacing = 7 * layer_scale groups = [] for clasN in classes_name_list(1): vs.BeginGroup() vs.Rect((-square_dim,square_dim/2),(0,-square_dim/2)) RECT = vs.LNewObj() vs.SetClass(RECT,clasN) vs.CreateText("{}".format(clasN)) TEXT = vs.LNewObj() # set text vertical align and horizontal align = center, left vs.SetTextVerticalAlign(TEXT,3) vs.SetTextJust(TEXT, 1) vs.HMove(TEXT,spacing,0) # move text in place on right of rectangle vs.EndGroup() groups.append(vs.LNewObj()) for i, group in enumerate(groups): if i != 0: prev_group = groups[i - 1] prev_group_bbox = vs.GetBBox(prev_group) group_bbox = vs.GetBBox(group) vs.HMove(group,0,(prev_group_bbox[1][1])-spacing) Cheers 1 Quote Share this post Link to post
Cris with no H 48 Posted November 20, 2018 Great script! Thank you! Quote Share this post Link to post
julia manrique 0 Posted March 19, 2019 Hi There, Is there any script that does the same but for layers? to create a layer list? Quote Share this post Link to post
twk 233 Posted March 19, 2019 Swap out integers for the get_layer_type_switch, to retrieve a list of either Design Layers, Sheet Layers or Both. -- Save your work before using -- get_layer_type = lambda x:vs.GetObjectVariableInt(x, 154) # 1 = Design Layer, 2 = Sheet Layer, 3 = Referenced Layer get_layer_type_switch = 0 #Custom switch, change to get different layer types 0=Design Layers Only, 1=Sheet Layers Only, 2=Both Design Layers and Sheet Layers layer_scale = vs.GetLScale(vs.ActLayer()) # page mm scale 1:1 spacing = 3 * layer_scale font_size = 10 layer_names = [] hLayer = vs.FLayer() while hLayer != None: layer_type = get_layer_type(hLayer) if get_layer_type_switch == 0: if layer_type == 1: layer_names.append(vs.GetLName(hLayer)) elif get_layer_type_switch == 1: if layer_type == 2: layer_names.append(vs.GetLName(hLayer)) elif get_layer_type_switch == 2: layer_names.append(vs.GetLName(hLayer)) hLayer = vs.NextLayer(hLayer) # we now reverse sort the layer_names list. For some reason this method retrieves layers in reverse order of the stack shown in the Navigation Pallette. layer_names.reverse() text_objects = [] for layer_name in layer_names: vs.CreateText(layer_name) TEXT = vs.LNewObj() # set text vertical align and horizontal align = center, left vs.SetTextVerticalAlign(TEXT, 3) vs.SetTextJust(TEXT, 1) vs.SetTextSize(TEXT, 0, len(layer_name), font_size) text_objects.append(TEXT) for i, text in enumerate(text_objects): if i != 0: prev_text = text_objects[i-1] prev_text_bbox = vs.GetBBox(prev_text) vs.HMove(text,0,(prev_text_bbox[1][1])-spacing) Quote Share this post Link to post
twk 233 Posted March 19, 2019 Heres another one that lists them all in one text object, adding the option to show the stacking order number with it or not. -- Save your work before using -- get_layer_type = lambda x:vs.GetObjectVariableInt(x, 154) # 1 = Design Layer, 2 = Sheet Layer, 3 = Referenced Layer get_layer_type_switch = 0 #Custom switch, change to get different layer types 0=Design Layers Only, 1=Sheet Layers Only, 2=Both Design Layers and Sheet Layers show_stacking_order = False #Set to True if you want the string to show the stacking order number beside it font_size = 10 layer_names = [] hLayer = vs.FLayer() while hLayer != None: layer_type = get_layer_type(hLayer) if get_layer_type_switch == 0: if layer_type == 1: layer_names.append(vs.GetLName(hLayer)) elif get_layer_type_switch == 1: if layer_type == 2: layer_names.append(vs.GetLName(hLayer)) elif get_layer_type_switch == 2: layer_names.append(vs.GetLName(hLayer)) hLayer = vs.NextLayer(hLayer) # we now reverse sort the layer_names list. For some reason this method retrieves layers in reverse order of the stack shown in the Navigation Pallette. layer_names.reverse() text_str = "\r".join([str(x) for x in layer_names]) if show_stacking_order: text_str = "\r".join(["[{}] {}".format(i, x) for i,x in enumerate(layer_names)]) vs.CreateText(text_str) TEXT = vs.LNewObj() vs.SetTextVerticalAlign(TEXT,3) vs.SetTextJust(TEXT, 1) vs.SetTextSize(TEXT, 0, len(vs.GetText(TEXT)), font_size) Quote Share this post Link to post
Boh 436 Posted March 19, 2019 Thanks @Pat Stanford & @twk. These are really useful. Quote Share this post Link to post