Jump to content
Developer Wiki and Function Reference Links Read more... ×
tca

Create classes from worksheet

Recommended Posts

Hi,

I'm looking for a way to create classes from a worksheet.

We have an extensive program for a large hospital project. We've created a list of classes we would like to use to structure that program in VW.

The list is currently in excel but could easily be pasted in a VW worksheet were a script could pick it up and generate classes with the names from the worksheet.

Unfortunately I'm not able to script this myself.

I've attached the VW worksheet.

any ideas?

Share this post


Link to post

This should do it.

Open the worksheet. Select the range of cells you want to use to create classes. Run the script.

I'll also attach the file in 2015 and 2016.

hth

mk

Procedure CreateClasssesFromWorksheet;
{Badly scripted by Michael Klaers}
{Open a worksheet.  Select a cell or range of cells.  Run this script.}
{This script will create a class using the contents of the cells as names.}

VAR

WSHand		: Handle; 				{Handle to Worksheet}

topRow,leftColumn,bottomRow,rightColumn  :INTEGER;

currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow   :INTEGER;

LoopColumn,LoopRow	:INTEGER;

ClassNameinWorksheet  :STRING;

BEGIN
WSHand:=GetTopVisibleWS;

GetWSSelection(WSHand,currentCellRow,currentCellColumn,topRangeRow,leftRangeColumn,topRangeSubrow,bottomRangeRow,rightRangeColumn,bottomRangeSubrow);


For    LoopColumn := leftRangeColumn TO rightRangeColumn
DO	BEGIN

		FOR LoopRow :=	topRangeRow TO bottomRangeRow
		DO	BEGIN


			GetWSCellString(WSHand,LoopRow,LoopColumn,ClassNameinWorksheet);
			If ClassNameinWorksheet <> ''
			THEN
			NameClass(ClassNameinWorksheet);

			END;
	END;

END;


RUN(CreateClasssesFromWorksheet);

 

classes_v2015.vwx

classes_v2016.vwx

  • Like 1

Share this post


Link to post

It was mostly luck :-)

I'm a pretty bad scripter, but I already had a script that queried every selected cell in a worksheet. From there it only takes 2 lines of script to get the text from the cell and create a class.

Wish they were all that easy.

I'm glad it works for what you need.

mk

Share this post


Link to post

This script should do it.

 

Put the class names you want in column A.  Put the descriptions in column B.  

 

Leave the worksheet open.  Run the script.

 

PROCEDURE CreateClasssesFromWorksheet;
{Badly scripted by Michael Klaers}
{Open a worksheet.  Run this script.}
{This script will create a class using the contents of the cells in Column A as names.}
{The contents of Column B will be the desciption for the class in Column A of the same row.}


VAR
	
	WSHand,ClassHandle									:HANDLE; 				

	LoopRow												:INTEGER;

	ClassNameinWorksheet,ClassDescriptioninWorksheet	:STRING;
	
	BResult, IsThisACell								:BOOLEAN;

BEGIN
	WSHand:=GetTopVisibleWS;
		
		IsThisACell := TRUE;
		LoopRow := 1;
            
			WHILE (IsThisACell) 
			DO	BEGIN
				
				
				GetWSCellString(WSHand,LoopRow,1,ClassNameinWorksheet);
				GetWSCellString(WSHand,LoopRow,2,ClassDescriptioninWorksheet);
				If ClassNameinWorksheet <> ''
					THEN
					NameClass(ClassNameinWorksheet);
					ClassHandle := GetObject(ClassNameinWorksheet);
					BResult := SetDescriptionText(ClassHandle, ClassDescriptioninWorksheet);
					IsThisACell:=IsValidWSCell(WSHand,LoopRow + 1,1);
					LoopRow := LoopRow + 1;
				
				END;
		
	
END;


RUN(CreateClasssesFromWorksheet);

 

 

Share this post


Link to post

Hello, 

Fantastic thread!

Is there a way to assign the attributes at creation in the methods described above. All from a table?

 

Any clue is welcomed.

 

Share this post


Link to post

I haven't tried it, but I wonder if it would be possible to make the worksheet entries for the class attributes human readable.  Perhaps.

 

Check out this thread:  

 

 

At the end of the thread is a script that uses the graphic attributes of a selected object to create a class with the objects attributes and one to edit the graphic attributes of a class.

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.

×