Jump to content
Developer Wiki and Function Reference Links ×

$include is confusing me


Recommended Posts

I have written a script named door.vsm using the script editor

I want to call this script from another script named create.vsm

When I run the create.vsm script I have a dialog box with a check box. If the check box is checked I want $include to run the door.vsm script.

Does anyone have a simple example on how to do this properly?

Link to comment

A couple of things.

1. Don't name either of the scripts Door. There can only be one object type or command with a given name in a VW document. Also don't name your classes of layers door as the Door object won't work.

2. The {$INCLUDE} directive just brings code into the script from an outside text document. The function or procedure you want to run needs to be written in the include file just like if you were writing it as part of the main procedure. Depending on what you are doing, you might need to use mulitple includes as the constant and variable declarations need to be included in the correct parts of the main routine as does the actual code.

If the checkbox in the dialog box returns a boolean variable then something like:

VariableInMainScript := FunctionFromIncludFile;

or

ProcedureFromIncludeFile(VariableDependentOnProcedure);

would work to call it.

{$INCLUDE} is just a way to break up the code into different files, not a way to call external procedures/functions.

Link to comment

Ok I finally got this Include thing working! Now I just have to make sure I use a common file path so it will work on multiple computers.

I created the following test script. The script creates two rectangles. All the variables are declared and assigned values in the main script. The first rectangle is created in the main script. The $Include directive is then used to call the file named "rectb" which only contains the code to draw the second rectangle. The main script "includes" the code from "rectb" then proceeds to complete the remaining code in the main script.

The Main Script:

Procedure CreateRect;

VAR

X01, X02, Y01, Y02: REAL;

X03, X04, Y03, Y04: REAL;

BEGIN

X01:=0;

X02:=10;

Y01:=0;

Y02:=5;

X03:=15;

X04:=25;

Y03:=10;

Y04:=15;

Rect(X01, Y01, X02, Y02);

{$INCLUDE Macintosh HD:Users:MyName:Desktop:MiniDrive Sync:Completed Tools:Include Test:rectb}

END;

RUN(CreateRect);

The file "rectb" simply Contains the Following:

Rect(X03, Y03, X04, Y04);

I'm guessing that as the long as the code is written correctly and compiles successfully then I can break it into as many pieces as possible. I just have to make sure that all the little pieces are called in the correct order. I'm assuming it doesn't matter where variables are declared as long as they are declared in the correct position in the code. Are my assumptions correct?

Link to comment

Unfortunately, your assumptions are not correct.

All global constants and global variables must be defined at the top of the main procedure.

Local variables (those defined within a function or procedure block) can be defined anywhere.

How big do you expect the overall code to be? Unless you are looking at a very large project, I would probably do a copy/paste of the include code prior to publishing a shipping version. It will save you a lot of tech support in the long run.

You might also want to check out the ability to do a relative location for the include file. Using this, it will look for the include file in the same place as the original script. Makes it easier since the user can then install in the Plug-ins folder in either the Vectorworks or the User folder.

Link to comment

well some of the code I've created in the past has had a problem due to file size. One of the codes I am working on for my office draws a door in elevation. the users have the option to choose what type of door, as well as, the type of panels the door has. I'm always modifying and adding to this code. Depending on what I am adding I create small test scripts (like the one above) so that I do not have to work within the main script. After I get the piece of code working correctly I add the code to the main script.

I fear that one day, like in the past, I will end up adding too much to the Main script and it will no longer run in vectorworks. So I think the include directive will help me to create a new type of organization that will allow me to keep the main script much much smaller in size. The main problem I see with this organization is getting the file paths correct. One missed link will screw up the entire script.

Now that I am beginning to understand the Include directive I want to start learning how to create Plugin Objects that will make the objects created by my script interactive via the Object Info Pallete. any good clean examples on that?

Link to comment

The code size limitation is in the VS editor, not in the size of the code itself.

One way around this is to use the $INCLUDE to include all of your code from an external text editor. TextWrangler or BBEdit both work well on the Mac. TextWrangler is Free.

Orso B. Schmidt has written some free plugins for TextWrangler that will let you send your code directly to VW for testing.

Check out

http://www.vectorlab.info/index.php?title=VectorScript_Resources

or

http://www.vectorlab.info/index.php?title=Run_VectorScript_-_BBedit_or_TextWrangler

for more information on external editors.

As for sample PIOs. check out some of the freebies available from vectordepot or the examples from NNA available on this page:

http://www.nemetschek.net/support/custom/vscript/example.php

The brief explaination of a PIO is that it is an object with a Parameter Record attached. Those parameters show up in the OIP. They work as constants in the program and you use them in the code just like constants, but put a P (letter P) before the name of the parameter (i.e. PParameterName). Use SetRField to store a changed value back to the parameter record.

Edited by Pat Stanford
Link to comment

I've downloaded the sample Rectangle Plugin Object.

The archive file contains the following:

Simple Grid.vso

simplegrid.vss

i was able to open the file simplegrid.vss in textwrangler. I have tried to compile the simplegrid.vss code in vectorworks but I get an error telling me that specific identifiers are not declared.

How am I suppose to correctly load these files into vectorworks?

Link to comment

The VSS file is just a version of the code that is readable in a text editor. The vso is a Vectorworks Plug-in object.

Put the vso file into the following path

Users:You:LibraryApplication Support:Vectorworks:2009: Plug-ins

and then restart VW.

Go to Tools:Scripts:Vectorscript Plug-in Editor.

Scroll down until you see Simple Grid and select it.

Click on the Scripts button to see/edit the script.

Click on the Parameters button to see/edit the parameters.

Link to comment

Thanks Pat!

check out my first Plugin Object.

See any problems?

PROCEDURE Shutter;

VAR

l,Offset,PanOffset,PanNumber,X01,Y01,A,B,C,D,E : REAL;

M01,M02,M03,M04,i :INTEGER;

result : BOOLEAN;

objname : STRING;

oh,rh,wh : HANDLE;

BEGIN

{ retrieve custom object information }

result:= GetCustomObjectInfo(objname,oh,rh,wh);

{ if object information was successfully retrieved }

IF result THEN BEGIN

{ retrieve parameters }

Y01 := PHEIGHT;

X01 := PWIDTH;

Offset := POFFSET;

PanOffset := PPANOFFSET;

PanNumber := PPANNUMBER;

A:=(X01-Offset);

{ B is equal to the size of the panel }

B:=(Y01-(Offset*(PanNumber+1)))/PanNumber;

{ C is the point relative to the height (Y01) }

C:=((0+Y01)-(Offset*PanNumber)-(B*(PanNumber-1)));

{ draw Shutter }

FillPat(1);

PenPat(2);

PenSize(4);

Rect(0,0,X01,Y01);

M01:=1;

M02:=0;

M03:=PanNumber;

M04:=(PanNumber-1);

{ draw Panels }

BEGIN

repeat

i:=i+1;

E:=(0+(Offset*M01)+(B*M02));

D:=(Y01-(Offset*M03)-(B*M04));

PenSize(4);

Rect(0+Offset,E,A,D);

PenSize(2);

Rect(0+Offset+PanOffset,E+PanOffset,A-PanOffset,D-PanOffset);

M01:=M01+1;

M02:=M02+1;

M03:=M03-1;

M04:=M04-1;

until i=PanNumber;

END;

END;

END;

Run(Shutter);

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...