Jump to content
Sign in to follow this  
Walther in Europe ( Mac us

How to select a existing HATCH within VScript?

Recommended Posts

[Roll Eyes]

Hello, I found today this forum and I am learning VectorScript Language.

I would like writing and automatic plug-in or script that is able to select one of the existing Hatches that I made before in my existing list of hatches with a Wall tool.

I'm an European user and my version is 9.5.3 (Dutch language) except for the scripts which are in English ( Apple OS X Jaguar or OS 9.22 )

I would like to be able to click on different buttons that give me depending the button I choose for example a certain wall with a pensize, a hatch, a fillback ....but I don't know how to select the hatch with the procedure below.

In the following script I can select a wall with a pattern, but I prefere to select one of my own created hatches......

Procedure CustTool;

VAR

Name:STRING;

Result:BOOLEAN;

BEGIN

PushAttrs;

ClearCavities;

DoubLines(30cm);

PenSize(14);

PenPat(2);

SetZVals(0cm, 250cm);

FillFore(255);

FillBack(0);

FillPat(5);

PenFore(255);

PenBack(0);

PenPat(2);

PenSize(14);

PenPat(2);

CallTool(-208);

PopAttrs;

END;

Run(CustTool);

[Confused]

I found the procedure

SetVectorFill(theObj:HANDLE; hatchName:STRING):BOOLEAN;

which I think could be useful, but I don't know if it is the right procedure and how to fill in some values.

What should I write instead of

<theObj:HANDLE> ?

<hatchName:STRING> ( my own hatch between ' ' ) ?

and instead of <BOOLEAN> YES/NO 0 or 1 ?

After wich line do I place the procedure

Or has someone better ideas or already created such a script ?

Thanks a lot !

[smile]

Share this post


Link to post

I've never used vectorfills and there are people here with more knowledge of vectorscript, but I think I can help you along a little anyway.

HANDLE is a type of variable. Every object in a drawing is internally identified by a number attached to it. This number is the HANDLE. You would need to create a wall and then get it's handle so you can tell vectorworks which object you wish to operate on. In your case it would be the last object created so you would use function "LObject". If you view the online function reference by class and look under "Document List Handling" you'll find a number of functions designed to deal with getting handles. This is a very important concept to grasp as it is needed in almost all scripts at some point.

So the first thing to do is declare a variable under VAR that will later take the handle number. Something like: nuwall:HANDLE

Here's where I'm a little unsure cause I've never used CallTool in a script. But I would try putting this after CallTool:

nuwall:=LObject;

SetVectorFill(nuwall,'hatch_name');

Here hatch_name is whatever you have called your fill. Notice the use of the assignment operator :=. You can read about it in the language guide.

So what you've done is

1.told the script editor what you will be calling your handle variable

2.referenced the object you need to operate on (last object) and assigned it's internal number to your variable

3.used this variable in a function to identify which object in the document you want the function to apply to.

I believe that you can ignore the fact that SetVectorFill returns(":") BOOLEAN...that's to say it returns true if the operation is a success. This would most likely be used in error checking in a dialog like:

IF SetVectorFill(nuwall,'coolfill',)= False

THEN AlrtDialog('that fill does not exist here');

Good luck and if I'm not correct in my explanation I'm sure somebody will be along with the right stuff.

[ 02-02-2003, 03:05 PM: Message edited by: ccroft ]

Share this post


Link to post

The reason why I use hatches or vector-fills is that I often work with engineers that use Autocad .

We cannot export patterns (bitmap) into DWG or DXF, because Autocad doesn't support patterns.

So when using vector-fills I can produce quite a lot of more different kinds of special hatches and I'm able to export them to not-VectorWorks users. In that case my drawing will be more readable by my engineers.

I'll test your advise, thanks.

Share this post


Link to post

Hi,

The HANDLE code is very useful when your script is going to change an existing object.

In this case you can do something simpler, choose your VectorFill/Hatch and Wall tool before you try the CustomTool/Attributes... at the Organise menu.

It will write for you a script more or less like this (I removed some parts I didn't like):

code:

Procedure CustTool;

VAR

Name:STRING;

Result:BOOLEAN;

BEGIN

PushAttrs;

Name:= 'My Special Hatch #23'

Result:=SetVectorFillDefault(Name);

CallTool(-208);

PopAttrs;

END;

Run(CustTool);
[/code]

[ 02-05-2003, 10:30 AM: Message edited by: Alexandre B A Villares ]

Share this post


Link to post

Thanks for the tips :-), I am very happy.

I have tried the last one and it works but how do you think I can have f.e three different kinds of hatches in one wall like the procedure below ( which is working ) but then not with the patterns changed by mu own existing vectorfills.

And after that I would like to make also in several separated scripts different kinds of walls with one, two, three, four different vectorfills. [Confused]

Procedure CustTool;

VAR

Name:STRING;

Result:BOOLEAN;

BEGIN

PushAttrs;

ClearCavities;

PenSize(14);

PenPat(2);

AddCavity(TRUE, -7cm, -17cm, 24);

{ not pattern 24 but vectorfill #x }

PenSize(14);

PenPat(2);

AddCavity(TRUE, -3cm, -7cm, 1);

{ not pattern 1 but vectorfill #y }

PenSize(14);

PenPat(2);

AddCavity(TRUE, 7cm, -3cm, 71);

{ not pattern 71 but vectorfill #z }

DoubLines(34cm);

PenSize(14);

PenPat(2);

SetZVals(0cm, 250cm);

FillBack(0);

FillPat(5); { in this case it is a general pattern that covers the whole wall below the others, something llike a background }

PenFore(255);

PenBack(0);

PenPat(2);

PenSize(14);

PenPat(2);

CallTool(-208);

PopAttrs;

END;

THANKS A LOT FOR SUPPORTING

Share this post


Link to post

I know that the last argument of AddCavity(TRUE, -0.070, -0.170, # ); is the Fill information (a positive index means Pattern, a negative index means Hatch)

But I'm stuck with the problem of getting the VectorFill index from the Hatch's name. The oposite is easy (VectorFillList(index: LONGINT):STRING;).

If you set the Hatches you want for your cavities inside the Wall tool preferences, and then use the Custom Tool/Attributes... command you'll get a script with the correct negative index. But I guess it will not be universally valid for any document.

Share this post


Link to post

Alexandre,

I have run into the missing Get/Set statement often in the past. Sometimes however, there are enough statements available to script the missing code. You are lucky today. [big Grin] Here is a short function that will get the index number from the hatch name. The function returns 0 (zero) if the hatch name is not found, and the hatch name is case insensitive.

Best wishes,

Raymond

code:

 

function GetVectorFillIndex(VFName :String) :Longint;

{ Return a VectorFill index # from a VectorFill name. }

{ Raymond Mullin - 6 February 2003 }

Var

Done, Match :Boolean;

I, VFCnt :Longint;

function UpStr(S :String) :String;

{ An upper string FUNCTION. }

Begin

UprString(S);

UpStr := S;

End; { UpStr }

Begin

VFCnt := NumVectorFills;

UprString(VFName);

I := 0;

Match := False;

Done := VFCnt = 0;

while not Done do begin

I := I + 1;

Match := UpStr(VectorFillList(I)) = VFName;

Done := Match | (I = VFCnt);

end;

if not Match then I := 0;

GetVectorFillIndex := I;

End; { GetVectorFillIndex }

Example:

Var

VFIndexNum :Longint;

HatchName :String;

...

HatchName := 'any Hatch Name';

VFIndexNum := GetVectorFillIndex(HatchName);

[/code]

Share this post


Link to post

I thank everybody here for the suport, I finally know that a negative index means Hatch ( [smile] Alexander )

But I wasn't able to let work the script from Raymond. ( I have copy/paste it and I changed VFName:string by my Dutch hatch-name 'A metselwerk type A' but no result.

In my version 9.53 ( we don't have version 10 yet in Europe ) the procedure GetVectorFillIndex is not in the list in my version.

In the meanwhile I found some number by trying some number between -1 and -999 and when I change # in for exemple AddCavity(TRUE, -0.070, -0.170, # ) by -103 it works !!!.

Still I praying to have some day a script that produces a list whit all the negative numbers and their hatch-name for the default drawing.

And I will post a topic to Nemetschek for changing something in their hatch/vectorfill menu.

I could be useful for everyone that beside the hatch-name you could see instantly the corresponding negative number.

Something like :

hatch sample A (-189)

hatch sample B (-540)

hatch sample C (-610)

hatch sample D (-105)

hatch sample X (-nnn)

Thanks <= [smile] =

Share this post


Link to post

Thanks Raymond!

Now Walther, your script with Raymonds's contribution and mine, I tested it and there is still something missing...

I added a Message(I); to see the VectorFill index produced, and the Custom Tool/Attributes generated coge gives much bigger negative numbers...

Anyone else?

code:

Procedure CustWall;

VAR

Name:STRING;

Result:BOOLEAN;

Function GetVectorFillIndex(VFName :String) :Longint;

{ Return a VectorFill index # from a VectorFill name. }

{ Raymond Mullin - 6 February 2003 }

Var

Done, Match :Boolean;

I, VFCnt :Longint;

function UpStr(S :String) :String;

{ An upper string FUNCTION. }

Begin

UprString(S);

UpStr := S;

End; { UpStr }

Begin

VFCnt := NumVectorFills;

UprString(VFName);

I := 0;

Match := False;

Done := VFCnt = 0;

while not Done do begin

I := I + 1;

Match := UpStr(VectorFillList(I)) = VFName;

Done := Match | (I = VFCnt);

end;

if not Match then I := 0;

GetVectorFillIndex := I;

End; { GetVectorFillIndex }

BEGIN

PushAttrs;

ClearCavities;

PenSize(14);

PenPat(2);

AddCavity(TRUE, -7cm, -17cm, -GetVectorFillIndex('My Hatch X'));

PenSize(14);

PenPat(2);

AddCavity(TRUE, -3cm, -7cm, -GetVectorFillIndex('My Hatch Y'));

PenSize(14);

PenPat(2);

AddCavity(TRUE, 7cm, -3cm, -GetVectorFillIndex('My Hatch Z'));

DoubLines(34cm);

PenSize(14);

PenPat(2);

SetZVals(0cm, 250cm);

FillBack(0);

Name:= 'My Special Hatch Below';

Result:=SetVectorFillDefault(Name);

{ in this case it is a general pattern that covers the whole wall below the others, something llike a background }

PenFore(255);

PenBack(0);

PenPat(2);

PenSize(14);

PenPat(2);

CallTool(-208);

PopAttrs;

END;

Run (CustWall);
[/code]

[ 02-07-2003, 02:40 PM: Message edited by: Alexandre B A Villares ]

Share this post


Link to post

Alexandre, thanks, I tried it with 90% succes !

What do I mean ...

In the part :

PenSize(14);

PenPat(2);

AddCavity(TRUE, -7cm, -17cm, -GetVectorFillIndex('My Hatch X'));

PenSize(14);

PenPat(2);

AddCavity(TRUE, -3cm, -7cm, -GetVectorFillIndex('My Hatch Y'));

PenSize(14);

PenPat(2);

AddCavity(TRUE, 7cm, -3cm, -GetVectorFillIndex('My Hatch Z'));

I changed "My Hatch X, Y and Z" by three of my hatches but instead of giving me X, Y, Z it gives me G, T, W.

So, it works but the script is giving me other hatches and sometimes it leaves it blank ( because I think that the number is being generated does exist in my drawing.)

It seams that the script is filling in another index number, strange, isn't it?

In other words and for example, I ask -203 and I'm getting -345.

I don't if there a logical scheme in giving me other negative numbers. That thing I'll have to find out unless you see other code problems.

Greetings,

Share this post


Link to post

Rj's code returns the hatch's index within the vector fill list. If you have 5 hatches in a doc then this is in a range of 1 to 5.

It would seem that addcavity needs a different kind of identifier...like it doesn't recognize that you are refering to something in the vectorfill list.

You don't have hundreds of hatches in a document do you?

It's possible this is beyond the reach of vectorscript....using this strategy at least.

[ 02-08-2003, 07:53 PM: Message edited by: ccroft ]

Share this post


Link to post

Hi, Mr Ccroft, have you changed your topic, it disappeared ?

I tried your suggestion Maybe there's a problem with the loop in GetVectorFillIndex....I think the minus signs need to be removed from in front of GetVectorFillIndex in the main body and added inside GetVectorFill somewhere. , but it didn't work in VW 9.5.3 Mac.

Still I'm happy that people from Brazilia, Canada, Texas, Australia, Belgium ... can help each other. We will finaly find out, this WorldWideSupport is always amazing.

I have two thoughts about the approach to find the right hatch :

1/ the vectorfill name

The code in the topic from { Raymond Mullin - 6 February 2003 } is, I think, the good way to produce different scripts were you can determine a hatch with the real or determined name in your personal drawing. I'm still working arround and testing Raymonds' procedure trying to find out why I'm getting other vectorfills than the those that I determined.

2/ the vectorfill index-number

The procedure could build a hatch list in one of the layers from the active document in text format with the index-number beside.

In that case I could fill in the right index-number from the active document. The danger could be that it won't work in another documents with more or less hatches. ( Therefore a stationary is very wise to use. )

Greetings,

Share this post


Link to post

Hi Walther

Yeah, I removed that post cause I could see the suggestions where not addressing the root of the problem.

When I use rj's code in a drawing with 5 hatches it returns a number 1..5. From your posts it looks like you need a number like -293.

Two questions:

How many hatches do you have in this drawing?

How do you presently create this wall without using vectorscript? Or can you?

I'm not an architect so I've never really used the wall tool, at least not in this way. I'm always interested in learning more about this program. RJ's code has already taught me some new boolean moves in the escape conditions in his loop.

thanks to all!

Share this post


Link to post

Well, I did some testing. I created 5 hatches in a drawing. I used "create custom tool" with the wall tool set to fill a cavity with each hatch to make 5 scripts and noted the number in addcavity for each. I then ran rj's code set up to return each ones vectorfill index.

Below is the hatch name followed by the number used by addcavity in the custom tool script followed by the vectorfill index from rj's code.

black -196 1

blue -197 2

green -200 3

tan -204 0 (no match?)

yellow -198 5

What the relationship is between these numbers isn't clear to me.

I think it's possible that there isn't one, or that it may change from drawing to drawing depending on when the hatch is created or imported. Like how handle values can change.

Good luck with this one. Maybe somebody can compose all this into a coherent question for the guys on v-script list who might know.

Share this post


Link to post

Hi mister Ccroft,

Different answers:

How many? I'm use about 55 hatches but depending on the document it can be more or less?

( if you want I can sent you an email with a sample VW document, therefore you need to send me your email address )

I presently create this wall with the 'wall' tool or 'double lines' tool with polygone.

I have then to determine the number of cavities to fill up, it can be 1, mostly for internal walls or 2, 3, 4 for external wals. ( let's say, for example, representing concrete, bricks, wood, insulation, foamglass, foamconcrete, .... )

I have now 20 predefined scripts linked to a push button with different walls but they are all provided with patterns.

For all those patterns we can easily find there positive index-numbers in Nemetscheks' literature , but I cannot export patterns to AutoCad for some engineers I'm working with. They lose important information to see the difference between concrete, wood, insulation, ... because the space between two lines remains white.

Indeed, I need numbers like -293, -540, -103, and I started to fill in some numbers with results.

I tried some other numbers and I sometimes I was lucky to find other right negative numbers.

But there is no logical scheme in these numbers, wich is I think logical, because creating a hatch is something personal that can slightly differ from yours or some other user.

As I said before in a topic, there are two ways :

1/ I use the negative numbers and therefore I need to know wich hatch is linked to wich number.

2/ I fill in their names as I created them, but therefore the script from Raymond is doing some good work, except that instead of giving me hatch X the scripts is giving me hatch Q.

I also thanks everybody for the useful help, I'm not an expert in vectorscript but I'm learning from you and all the others.

Here one to test with patterns:

____________________________________________

Procedure CustTool;

{ www.vectorworks.be }

VAR

Name:STRING;

Result:BOOLEAN;

BEGIN

PushAttrs;

ClearCavities;

PenSize(14);

PenPat(2);

AddCavity(TRUE, -7cm, -17cm, 24);

PenSize(14);

PenPat(2);

AddCavity(TRUE, -3cm, -7cm, 1);

PenSize(14);

PenPat(2);

AddCavity(TRUE, 7cm, -3cm, 71);

DoubLines(34cm);

PenSize(14);

PenPat(2);

SetZVals(0cm, 250cm);

FillFore(255);

FillBack(0);

FillPat(5);

PenFore(255);

PenBack(0);

PenPat(2);

PenSize(14);

PenPat(2);

CallTool(-208);

PopAttrs;

END;

Run(CustTool);

_____________________________________

Walther

Share this post


Link to post

Try this:

Procedure CustWall;

VAR

Name:STRING;

Result:BOOLEAN;

Function GetVectorFillIndex(VFName :String) :Longint;

{ Return a VectorFill index # from a VectorFill name. }

{ Raymond Mullin - 6 February 2003 }

Var

Done, Match :Boolean;

I, VFCnt :Longint;

function UpStr(S :String) :String;

{ An upper string FUNCTION. }

Begin

UprString(S);

UpStr := S;

End; { UpStr }

Begin

VFCnt := NumVectorFills;

UprString(VFName);

I := 0;

Match := False;

Done := VFCnt = 0;

while not Done do begin

I := I + 1;

Match := UpStr(VectorFillList(I)) = VFName;

Done := Match | (I = VFCnt);

end;

if not Match then I := 0;

GetVectorFillIndex := -Name2Index(VectorFillList(I));

End; { GetVectorFillIndex }

BEGIN

PushAttrs;

ClearCavities;

PenSize(14);

PenPat(2);

AddCavity(TRUE, -7cm, -17cm, GetVectorFillIndex('My Hatch X'));

PenSize(14);

PenPat(2);

AddCavity(TRUE, -3cm, -7cm, GetVectorFillIndex('My Hatch Y'));

PenSize(14);

PenPat(2);

AddCavity(TRUE, 7cm, -3cm, GetVectorFillIndex('My Hatch Z'));

DoubLines(34cm);

PenSize(14);

PenPat(2);

SetZVals(0cm, 250cm);

FillBack(0);

Name:= 'My Special Hatch Below';

Result:=SetVectorFillDefault(Name);

{ in this case it is a general pattern that covers the whole wall below the others, something llike a background }

PenFore(255);

PenBack(0);

PenPat(2);

PenSize(14);

PenPat(2);

CallTool(-208);

PopAttrs;

END;

Run (CustWall);

The change is:

GetVectorFillIndex :Name2Index(VectorFillList(I));

and remove the minus signs in the main body before each call for GetVectorFillIndex.

[ 02-09-2003, 05:54 PM: Message edited by: ccroft ]

Share this post


Link to post

Dear Ccroft

You did some trying while I was writing a reply, fine !

Maybe I'm a little stupid, but how did you managed it.

How did you get the numbers ? Where did you find them ?

I have copied/pasted RJ's script but nothing in the application seems to present me those numbers.

Maybe my knowledge of English is not high enough to understand every word, but I'm amazed to read your topic and to discover that you're doing better!

If you could mail me your document, I must be missing some important steps.

Thanks,

Share this post


Link to post

That should read:

GetVectorFillIndex :=-Name2Index(VectorFillList(I));

Stop typing and try the code that's up a few messages. I believe you will be happy!

[ 02-09-2003, 06:01 PM: Message edited by: ccroft ]

Share this post


Link to post

quote:

Originally posted by ccroft:

GetVectorFillIndex:=-Name2Index(VectorFillList(I));


Oh great! It seems you found it!

And Name2Index was one of the first things I've tried, and it didn't work. It just never occured to me at that point it was just a question of sign change.

PS: Won't -Name2Index('Hatch Name') work directly?

[ 02-09-2003, 07:20 PM: Message edited by: Alexandre B A Villares ]

Share this post


Link to post

Yeah, you probably could just use it directly and forgo the getvectorfillindex function totally.

I like the function myself. It becomes error checking with something like:

If I=0 then AlrtDialog('the hatch does not exist or is misspelled');

This actually happened to me with an accidental space in the name. Took a while to find it. That's the problem with literals.

Also, I'm not sure what UpStr does, but I guess that's the case insensitive part. I don't think Name2Index is case sensitive though. If I had any use for this script I might refine it some.

So which way you go depends on what kind of environment the script will be used in.

Share this post


Link to post

Great, I thank Alexandre, Raymond, MullinRJ, Jeffrey, CCroft, for this finally result.

I was aware of those accidental spaces in the names. That's indeed the problem with literals. ( The same is true for the Terminal in OS X )

I'm am now able to select and draw my own hatches in wall type or double lines .

It will better in the future for exporting those vectorfills.

This morning during a meeting a constructor asked me again a set of exported VectorWorks documents.

Now I'm going to make some prefab scripts wich I will link to pushbuttons in a palet and give them a unique icon.

These icons can easily been made with Photoshop or GraphicConverter.

Thanks again,

See or read you later,

Walther,

Share this post


Link to post

ccroft,

You are correct. UpStr is used to make the data case insensitive by converting all the strings to uppercase before they are compared. I put it in because I like to use functions over procedures for routines that return only one variable. If I had used the plain vanilla VS procedure UprString, I would have had to write the following 3 lines inside the while loop:

TmpName := VectorFillList(I);

UprString(TmpName);

Match := TmpName = VFName;

For readability, I like code on one line, so I wrote UpStr to be able to write the following:

Match := UpStr(VectorFillList(I)) = VFName;

which sets Match to TRUE if the hatch name in the list equals the hatch name passed to the function GetVectorFillIndex.

The procedure UprString needs a variable passed to it, so VectorFillList(I) must first be assigned to a variable, which can then be passed to UprString, where it gets modified, returned, and subsequently used in a boolean comparison.

Granted, UpStr does not save a lot of room in this program, but I will use it elsewhere then the need arises.

This has been a very interesting topic. I have not followed it closely, but when I get a little free time I intend to come back and pick through all the code. Thanks to all for writing.

Raymond

Share this post


Link to post

Raymond

Thanks for posting. The main thing I have learned from this thread:

"Done := Match | (I = VFCnt);"

works the same as

"IF (match=true)|(I=VFCnt) then done:=true;"

with a whole lot less hassle.

I also learned something about using a variable in UprString. The next time you use the variable it is already converted, without having to assign UprString to a temp variable and using that? I'm not sure I understand why that works or if it has uses in other VSfunctions (well, procedures in this case).

BTW Alexandre is right, you can just use:

AddCavity(TRUE, -3cm, -7cm, -Name2Index('hatch name'));

And it is not case sensitive. But like I said before, I like GetVectorFillIndex for the ease of error checking.

Thanks to everyone for helping me learn!

[ 02-11-2003, 11:36 PM: Message edited by: ccroft ]

Share this post


Link to post

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.

Sign in to follow this  

 

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.

×
×
  • Create New...