Jonathan Pickup Posted January 25, 2008 Share 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 Link to comment
Pat Stanford Posted January 4, 2012 Share 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); 1 Quote Link to comment
Francois Levy Posted September 18, 2017 Share 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 Link to comment
cberg Posted August 15, 2018 Share Posted August 15, 2018 Has this changed for VW 2018? I am having difficulties with the Database Headers. Since they have changed. Quote Link to comment
twk Posted August 15, 2018 Share 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 Link to comment
SophieGW Posted November 5, 2018 Share 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 Link to comment
twk Posted November 5, 2018 Share 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 Link to comment
SophieGW Posted November 6, 2018 Share Posted November 6, 2018 @twk thank you!!! Quote Link to comment
Cris with no H Posted November 20, 2018 Share Posted November 20, 2018 Great script! Thank you! Quote Link to comment
julia manrique Posted March 19, 2019 Share Posted March 19, 2019 Hi There, Is there any script that does the same but for layers? to create a layer list? Quote Link to comment
twk Posted March 19, 2019 Share 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) 1 Quote Link to comment
twk Posted March 19, 2019 Share 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) 1 Quote Link to comment
Boh Posted March 19, 2019 Share Posted March 19, 2019 Thanks @Pat Stanford & @twk. These are really useful. Quote Link to comment
hharker Posted August 1, 2023 Share Posted August 1, 2023 On 11/5/2018 at 2:09 PM, twk said: 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 twk - how do I implement this script? I've tried copying it into 'textedit' and saving the file as a .txt file - but the 'import script' in vectorworks does not work. There's a vital basic step I'm missing here. Thanks Quote Link to comment
michaelk Posted August 1, 2023 Share Posted August 1, 2023 Select and copy the script from the forum. In VW open the resource manager. At the top select scripts. At the bottom select New Script. VW will make you put it in a folder that is also a palette. Name the folder. Name the script. A script editor will open. At the top set the language to Python Script. Paste the text of the script. You can open the palette by right clicking on it in the RM or by selecting it in the Window pulldown. Double click on the script name in the palette to make it run. 2 Quote Link to comment
MullinRJ Posted August 2, 2023 Share Posted August 2, 2023 On 8/1/2023 at 6:27 AM, hharker said: twk - how do I implement this script? I've tried copying it into 'textedit' and saving the file as a .txt file - but the 'import script' in vectorworks does not work. There's a vital basic step I'm missing here. Thanks @hharker, The reason your import failed is because you saved the file with a ".txt" extension, which tells the Import Script... menu to treat the script as Vectorscript. If you save your file with a ".py" extension, the Import Script... menu will treat it is a Python script. Or you can do as @michaelk suggests above, which is good if you plan to run a script more than once. Sometimes you have to help the machines. They are made in our image and likeness, and therefore suffer the same shortcomings. 😉 Raymond 1 2 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.