Jump to content
Jonathan Pickup

List All Classes in file

Recommended Posts

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.

Share this post


Link to post

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

Share this post


Link to post

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!

Share this post


Link to post

Has this changed for VW 2018?  I am having difficulties with the Database Headers.  Since they have changed. 

Share this post


Link to post

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)

 

Share this post


Link to post

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

Share this post


Link to post

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

  • Like 1

Share this post


Link to post

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)

 

 

Share this post


Link to post

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)

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

 

7150 Riverwood Drive, Columbia, Maryland 21046, USA   |   Contact Us:   410-290-5114

 

© 2018 Vectorworks, Inc. All Rights Reserved. Vectorworks, Inc. is part of the Nemetschek Group.

×