Jump to content
Developer Wiki and Function Reference Links ×

Simple function


pixel2

Recommended Posts

Hello, I'm a Vectorworks user that doesn't have a clue how to start using Vectorscript in little rutines.

Now I have to do a boring job that consists in change the width of 84 rectangles in 24 mm having to put the resize handle in the middle.

Does anyone can help me with this task or point some tutorials to know how can I do this?

Thanks in advance

Bruno

Link to comment

Not quite sure what you are after... Because of public outcry and protest, I usually no longer post scripts here, but I think I'll make an exception this time and just face the wrath of the riff-raff... Yes, it is quite OK to have ? in such a short script, you nitwits, nincompoops and otherwise average VW users!

Assuming that the rectangles are supposed to be 24 x 24 mm:

PROCEDURE ResizeRectangles; { ? Petri Sakkinen 2007 }

CONST

theSize = 24;

VAR

x1, y1, x2, y2, x0, y0, dx, dy : REAL;

obHd : HANDLE;

BEGIN

obHd := FSACTLAYER;

WHILE NOT (obHd = NIL) DO BEGIN

GETBBOX(obHd, x1, y1, x2, y2);

HCENTER(obHd, x0, y0);

x1 := x0-theSize/2;

x2 := x0+theSize/2;

y1 := y0+theSize/2;

y2 := y0-theSize/2;

SETBBOX(obHd, x1, y1, x2, y2);

obHd := NEXTSOBJ(obHd);

END;

END;

RUN(ResizeRectangles);

Link to comment

Hello to all!

Many thanks for the quick answer! This is a great help, but my problem consists in having multiple widths. I have 5 or 6 different widths and I want to decrease the 24mm in each one. Is it difficult?.

Maybe the best is to know where can I learn Vectorscript. Is there a VectorScript for dummies? Or tutorials?

Thanks for all the help to this NOOBIE.

Best regards

Bruno

Link to comment

Right.

PROCEDURE ResizeRectangles; { ? Petri Sakkinen 2007 }

CONST

theChange = 12;

VAR

x1, y1, x2, y2, x0, y0, dx, dy : REAL;

obHd : HANDLE;

BEGIN

obHd := FSACTLAYER;

WHILE NOT (obHd = NIL) DO BEGIN

GETBBOX(obHd, x1, y1, x2, y2);

SETBBOX(obHd, x1+theChange, y1, x2-theChange, y2);

obHd := NEXTSOBJ(obHd);

END;

END;

EDIT

Now, one could have theChange as a variable and get the value with a RealDialog, then divide it by two (theChange := theChange/2). But this was supposed to be a learning experience - constants are very useful.

Edited by Petri
Link to comment

Bruno

To begin understanding vScript, I suggest that you go to the Vectorscript Reference in Help and look up FSACTLAYER, GETBBOX,SETBBOX,NEXTSOBJ and HCENTER, and see if you can begin to understand how the scripts that Petri has so generously provided do their magic. The reference is a list of pre-made functions that we weave together to get the work done. This is the basic "vocabulary".

You'll also need to spend some time with the Vectorscript Guide, also in Help. This explains the structure that the functions need to be set within, and a few other concepts. Generally speaking, this is the "grammar".

If and when the examples provided here by the Hellion of Helsinki start to make some sense, head over to Vector Depot and download a few Plug-Ins and puzzle over them for a while. There are more examples on NNA's main site under Support>Customization. You may want to stick with Tools and Menu Commands for the moment, as they're generally a little easier to follow than Objects.

Welcome to Vectorscript for Dummies. (or should that read by Dummies? :-)

Charles

Link to comment

The lasagne is in the oven, so I have a few minutes... OK, I cheated: I used tomato paste, instead of cooking the sugo from fresh (or even tinned whole) tomatoes and did not make the lasagne sheets myself. One of those days...

PROCEDURE ResizeRectangles; { ? Petri Sakkinen 2007 }

CONST

{ Constants are fixed values that can be used anywhere in the script. The value given implies the data type. }

theChange = 12; { We have an integer; the value is half of the desired change of size, for reasons perhaps explained later. }

VAR { Variables, well, vary during the execution. In addition to the useful variables, here we have a few redundant ones that I "declare" in every script. }

x1, y1, x2, y2, x0, y0, dx, dy : REAL;

obHd : HANDLE; { One, hmm, handles stuff with handles. If there is an object you want to deal with, first you have to get a handle to it. Thus, obHd. Could be objHd, theObject, theCat, theBlowerOnTheRight or whatever. Maybe "it".}

BEGIN

obHd := FSACTLAYER; { We are starting the handling from the FirstSelectedobjectontheACTiveLAYER... )

WHILE NOT (obHd = NIL) DO BEGIN { ... and shall continue as long as there are selected objects on the active layer. }

GETBBOX(obHd, x1, y1, x2, y2); { How big is "it"? What is The Bounding BOX? The coordinates of the top left corner and the bottom right corner are read and placed into VARiables. See: we needed variables! }

SETBBOX(obHd, x1+theChange, y1, x2-theChange, y2); { Make "it" this big, will'ya. Now we retrieve the variables and set the corners. }

obHd := NEXTSOBJ(obHd); { We're ready, so we'll "traverse" to the NextSelectedOBJect. When we said "FSACTLAYER", we established the list of objects we want to handle. }

END; { No more selected objects on the active layer. }

END; { Every beginning has an end and every silver lining has a cloud. }

Ahh, the dinner is ready!

EDIT

False alarm. The bechamel had sheep's milk pecorino which made it to get brown too early and the smell of nutmeg did not really help... No, it's not ruined, but thanks for asking.

Most scripts that handle things use the construct "obHd <> NIL", which is fine. I just find "NOT (obHd = NIL)" more elegant; besides, "obHd = NIL" can be nicely used in a REPEAT - UNTIL loop, which may come handy, too.

Edited by Petri
Link to comment

ccroft and Petri, thank's very much for the help!

sometimes I have to do stupid routines, that make me crazy with the amount of time wasted, so I've decided that I urgently need to add Vectorscript to my skills!

I will be waiting for your kind help once more if the Lasagne burns out!

By the way, today I've cooked Lasagne. Isn't that weird?

Thanks once more!

Bruno

Link to comment

Bruno,

You are welcome to join us in the VectorScript Asylum, but keep you expectations in check. The amount of time to learn VS, write and debug the code and actually run the routines is often much longer than doing it by hand. Especially if you only need to do something one time.

If it is something that you need to do often (more than a few times a year), scripting will almost always save you time in the long run.

Pat

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...