Jump to content
Developer Wiki and Function Reference Links ×

Drop in functions?


Will

Recommended Posts

Hi, I just noticed that if you look at the vectorscript guide online here

http://developer.vectorworks.net/ there are lots of extra Vectorscript functions that don't appear to be documented in the Vectorscript docs in the /Vectorworks 2013/VWHelp/Vectorscript reference folder. Here is an example: http://developer.vectorworks.net/index.php?title=VS:RelativeCoords at the bottom of the page is a little note saying 'Drop in function'.

I can't work out how to call them? I just get compile errors.

I've been googling this for about an hour and I can't find anything about what this means and how to use them... Can anyone help?

W

Link to comment
  • Vectorworks, Inc Employee

You call them just like any other VS function. For your example make sure you are using the correct variables. Even though the function lists 3 reals for each parameter that represents one vector variable. Look at the example below the function.

Link to comment

Will,

Because you didn't post a code example or the error you are getting I can't address your issue directly. More information is always better than less.

On a general note, when you encounter an undocumented function that contains three similarly named variables with an XYZ last character, and those variables are declared as type REAL, if you get compiler errors, try using a single variable of type VECTOR instead.

The online documentation shows the following, which is not only suspect, but syntactically wrong:

FUNCTION RelativeCoords(

?????ptX, ptY, ptZ??:REAL;

?????begPtX, begPtY, begPtZ??:REAL;

?????endPtX, endPtY, endPtZ??:REAL) X, Y, Z :REAL;

It should read:

FUNCTION RelativeCoords(

?????pt??:VECTOR;

?????begPt??:VECTOR;

?????endPt??:VECTOR) :VECTOR;

If you examine the EXAMPLE code posted on the same page you cited, you can see this is true. RelativeCoords() was introduced in VW11. As long as you are using a version of VW newer than that you will be able to compile this command.

If you need help using VECTORS, write back and I or someone else will elaborate.

Also, please create a signature with your computer specs and VW version. This helps others provide better answers.

Raymond

Link to comment

Here's my code edited down. I'm trying a different drop in function here but still having problems.

PROCEDURE Main;

VAR

selectedPoly, lastSlate:HANDLE;

pX, pY, pZ, outZ:REAL;

pt:POINT;

FUNCTION CheckObjCallback(h : HANDLE) : BOOLEAN;

VAR

objType:INTEGER;

BEGIN

{GetTypeN Returns the type index of the referenced planar or screen object. Rectangle 3 RECT. Polygon 5 POLY}

objType := GetTypeN(h);

IF ((objType = 3) OR (objType = 5)) THEN CheckObjCallback := true ELSE CheckObjCallback := false;

END;

BEGIN

{TrackObject Interactively, including highlighting, allows the user to select one object meeting the specified criteria}

TrackObject(CheckObjCallback, selectedPoly, pX, pY, pZ);

Message('Found Poly: handle:', selectedPoly, ' Point clicked: ',' x: ', pX, ' y: ', pY, ' z: ', pZ);

pt.x := pX;

pt.y := pY;

GetZatXY(selectedPoly, pX, pY, outZ);

END;

RUN(Main);

This wont compile, here's the error:

Line #25: GetZatXY(selectedPoly, pX, pY, outZ);

|

{ Error: Cannot use a FUNCTION name here. }

{ Error: Expected a RUN statement at the end of the scirpt }

Also, I have no idea from reading the documentation if the GetZatXY function will operate on a 2d poly drawn on an arbitrary 3D plane. The concept of 2D stuff floating around in 3D space on planes is quite confusing why isn't it all just 3D? If i want to make a pure 3D object aligned with a 2D poly drawn on an arbitrary 3D plane whats the best way to do this? Do I have to convert the Poly to 3D, transform it to the document origin plane, do my stuff (I want to tile the poly with 3D 'tiles') then transform everything back into position?, what's the easiest way to apply a transform to some geometry? Can I draw 2D rects to the 2D plane that the poly is on then extrude these and rotate about a point on the extrude using a transform relative to the 2D plane? (thats roughly what I do if I was coding this in sketchup).

Thanks for any help/advice you can give

Will

Link to comment

Hi, I'm using this to try and draw a rect on a 3D plane. Note that the variable selectedPoly contains a handle to a 2D poly on a 3D plane.

...

GetPt(pX, pY);

Rect(pX, pY, pX+100, pY-160);

planeRef := GetPlanarRef(selectedPoly);

SetPlanarRef(LNewObj,planeRef);

...

What I had hoped would happen is that the GetPt function would return the coordinates of the mouse click on the plane the poly is drawn on, as this is highlighted using automatic working plane when I make the click, and that I could draw a rectangle at these coords and then set it's plane ref to be the same as the poly. Having done this I would expect the newly drawn rect to appear under the cursor which it doesn't, the rect is at least aligned to the same plane as the poly though. Does GetPt always return a point on the document XY plane regardless of the active working plane? How does SetPlanarRef transform the rect from the document XY plane to the plane the poly is on?

Link to comment

Could someone explain what the coordinates are that GetPt returns? Are they screen plane coordinates, active working plane coordinates, layer plane coordinates or document XY plane coordinates?

OK I experimented a bit and it seems they are active working plane coordinates but the working plane doesn't seem to be preserved between the call to GetPt and the call to Rect.

Setting the plane ref of the Rect to be the same as a previously selected Poly is on a hiding to nowhere as there doesn't seem to be a way to get the origin of the plane?

Is there any way to store the working plane that exists while the GetPt function is executed so that I can draw to it or is this a fundamental limitation of Vectorscript?

I think I will probably just give up if I have to go and relearn 3D matrix maths and reconstruct everything from first principals...

Edited by Will
Link to comment

PROCEDURE Main;

VAR

selectedPoly, lastSlate:HANDLE;

pX, pY, pZ, outZ:REAL;

offsetX, offsetY, offsetZ : REAL;

rotationXAngle, rotationYAngle, rotationZAngle : REAL;

throwawayBool:BOOLEAN;

pt, beg_pt, END_pt, mat_org_pt, v:VECTOR;

FUNCTION CheckObjCallback(h : HANDLE) : BOOLEAN;

VAR

objType:INTEGER;

BEGIN

{GetTypeN Returns the type index of the referenced planar or screen object. Rectangle 3 RECT. Polygon 5 POLY}

objType := GetTypeN(h);

IF ((objType = 3) OR (objType = 5)) THEN CheckObjCallback := true ELSE CheckObjCallback := false;

END;

BEGIN

{Ask user to select a Poly}

TrackObject(CheckObjCallback, selectedPoly, pX, pY, pZ);

{Stuff the point at which poly is selected into a VECTOR}

pt.x := pX;

pt.y := pY;

pt.z := pZ;

{Get the matrix which transforms the Poly's plane from Document X-Y to the 3D plane which it is drawn on}

throwawayBool := GetEntityMatrix(selectedPoly, offsetX, offsetY, offsetZ, rotationXAngle, rotationYAngle, rotationZAngle);

Message('Found Poly: handle:', selectedPoly, ' Entity Matrix: x: ', offsetX, ' y: ', offsetY, ' z: ', offsetZ, ' ', rotationXAngle, ' ', rotationYAngle, ' ', rotationZAngle);

{Stuff the orgin of the Poly's plane into a VECTOR}

beg_pt.x := offsetX;

beg_pt.y := offsetY;

beg_pt.z := offsetZ;

{Make a VECTOR which is 1 unit long on the X axis of the Poly's plane}

END_pt.x := offsetX + 1;

END_pt.y := offsetY;

END_pt.z := offsetZ;

{Transform the point clicked on the Poly to the document XY plane}

v := RelativeCoords(pt, beg_pt, END_pt);

Message('Vector:', v);

{SetPlanarRefIDToGround(selectedPoly);}

{Draw the Rect at this point on XY plane}

Rect(v.x,v.y,v.x+100, v.y-100);

{Transform the Rect back to the plane which the Poly is drawn on by setting it's Entity matrix to be the same as the Poly's}

{If you comment out the next line you will see the Rect drawn at the correct location relative to the Document Origin. But when I set the entity matrix it gets transformed to the correct plane but with an 'incorrect' (compared to what I expected) offset relative to the Poly}

throwawayBool := SetEntityMatrix(LNewObj, offsetX, offsetY, offsetZ, rotationXAngle, rotationYAngle, rotationZAngle);

{Message('Status: ', throwawayBool);}

END;

RUN(Main);

Why when I set the entity matrix of the Rect does it not get transformed back to the original xyz point from the TrackObject call? Can anyone explain what I have misunderstood here?

Thanks,

W

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