Jump to content
Developer Wiki and Function Reference Links ×

ViewMatrix


Recommended Posts

Michael,

Present! (See attached!)

I've never touched these two functions until about 30mins ago but I think I've got them.

I had to go back to some 2007 documentation though to find out that it's 6 vars not 4 as the current documentation says.

Here's a little script I whipped up (Sorry it's messy, wrote it at lunch...):

--------------------------

Procedure VPTest;

VAR

h,WSH:Handle;

x, y, cx, cy, cz, rotx, roty, rotz : REAL;

str1,str2,str3,str4,str5,str6 :String;

xxx:Boolean;

Begin

GetPt(x, y);

h:=PickObject(x, y);

xxx:=GetViewMatrix(h,cx,cy,cz,rotx,roty,rotz);

WSH:=CreateWS('Values',10,10);

Str1:=Num2Str(3,cx);

Str2:=Num2Str(3,cy);

Str3:=Num2Str(3,cz);

Str4:=Num2Str(3,rotx);

Str5:=Num2Str(3,roty);

Str6:=Num2Str(3,rotz);

SetWSCellFormula(WSH,1,1,1,1,'X-Coord');

SetWSCellFormula(WSH,1,2,1,2,'Y-Coord');

SetWSCellFormula(WSH,1,3,1,3,'Z-Coord');

SetWSCellFormula(WSH,1,4,1,4,'X-Rot');

SetWSCellFormula(WSH,1,5,1,5,'Y-Rot');

SetWSCellFormula(WSH,1,6,1,6,'Z-Rot');

SetWSCellFormula(WSH,2,1,2,1,Str1);

SetWSCellFormula(WSH,2,2,2,2,Str2);

SetWSCellFormula(WSH,2,3,2,3,Str3);

SetWSCellFormula(WSH,2,4,2,4,Str4);

SetWSCellFormula(WSH,2,5,2,5,Str5);

SetWSCellFormula(WSH,2,6,2,6,Str6);

ShowWS(WSH,true);

End;

Run(VPTest);

----------------------

Should work on any viewport placed and then you just have to click on it and the script will generate a worksheet for the data. Attached is my quick testing file. Although I haven't touched SetViewMatrix I'd imagine it's pretty easy after this.

Let me know how you go, I'm interested to know what you're using this for! ;)

J

Link to comment
  • Vectorworks, Inc Employee

Hi Michael,

The boolean will be true if the function was successful, false if not. These boolean functions can be written like this:

GotIt := GetViewMatrix(h,cx,cy,cz,rotx,roty,rotz);

IF GotIt

THEN do my stuff

ELSE do something else;

Often times, there's not a need to do this and it can be used with a dummy var as James shows. I usually have a boolean variable called "boo" in scripts to use this way.

Link to comment

Hi Matt

I see that it works this way. But why does it behave so differently from other Get functions? For example, I've been playing around with GetBBox. It works like all other Gets

GetBBox(h,p1X,p1Y,p2X,p2Y); returns the real values for the 2 points of object with handle h.

It's not

boo := GetBBox(h,p1X,p1Y,p2X,p2Y);

Am I missing something that's fundamentally different about GetViewMatrix from all the other Get functions (that I know about)?

Or is it just that way because it's that way?

mk

Link to comment
  • Vectorworks, Inc Employee

Having a functions return a Boolean is rather standard for new calls. If the return value is FALSE the function failed for some reason. (Unsupported object type, invalid handle etc.) Without a Boolean return you had to guess that the function failed by looking at the return values.

This is an extreme example and why you need to do type checking but you have no way of knowing that GetBBox gives you invalid information if you pass it the handle to a record format object. If you pass GetViewMatrix the same handle it will return FALSE.

Link to comment
  • Vectorworks, Inc Employee

There are quite a few more that work that way. It would be nice if things were more consistent (in how the functions are named) so it was more obvious which of the "Gets" worked this way. Some "Gets" are procedures, some are functions that return the desired value, and some are these boolean functions that report back a success/fail. Knowing the success/fail of the function does come in quite handy sometimes.

Link to comment
GetBBox(h,p1X,p1Y,p2X,p2Y); returns the real values for the 2 points of object with handle h.

It's not

boo := GetBBox(h,p1X,p1Y,p2X,p2Y);

Am I missing something that's fundamentally different about GetViewMatrix from all the other Get functions (that I know about)?

The main thing you are missing is the age of the function. GetBBox has been around forever (I think literally. I believe it was in the first version of MiniPascal). GetViewMatrix is much newer, coming some time since it was converted to Vectorscript.

Newer in this case means that NV has learned what makes the functions/procedures easier/better for them to use internally and that flows down to all of us.

Luckily, they also understand that changing the definitions of procedures that are used in scripts who know how old will break many things and cause howls of outrage sot they have not done that (much) yet.

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