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

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.

×