VS:GetOrigin: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (1 revision)
 
(this damn GetOrigin returns millimeters in objects, but current units elsewhere)
(3 intermediate revisions by the same user not shown)
Line 38: Line 38:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>
Inside plug-in objects, [{VS:GetOrigin]] always returns {0, 0} no matter what.
([[User:Orso.b.schmid|Orso]], 2015.05.31):
This routine behaves differently across years and usage method:
* until VW 2009:
** used in Commands: returned the User origin shift in current units
** used in Objects: returned {0, 0}
* from VW 2010:
** used in Commands: returns the User origin shift in current units
** used in Objects:  returns the User origin shift in millimeters
Below an example of reading the user origin shift from within a plug-in object. Save the code below as point Plug-in with Reset On Move and Rotation:
<code lang="pas">
PROCEDURE HereAmI;
VAR
pioHandle, pioRecHandle, wallHandle : HANDLE;
pioName : STRING;
o, s : VECTOR;


In 12.5.1, inside menu commands, [[VS:GetOrigin]] returns the correct coordinates of the user origin. I think this this is not true for earlier versions, where the origin would always be the absolute origin, not the user origin.
BEGIN
 
    IF GetCustomObjectInfo(pioName, pioHandle, pioRecHandle, wallHandle) THEN BEGIN
Inside document script, the user origin works correctly.
          GetOrigin(o.x, o.y); { on VW 2009 and before this will always be zero when used from within a plug-in object. }
 
          GetSymLoc(pioH, s.x, s.y);
Other comments that I haven't verified:
          Locus(0, 0);
          CreateText(Concat(
              'GetOrigin: ', o, Chr(13),  
              'GetSymLoc: ', s
          ));
    END;
END;
Run (HereAmI);
</code>


VectorScript is using the page origin instead of the symbol origin when operating inside symbols. Plug-ins and symbols should use their insertion point as their origin.
Objects inside Symbols use the reverse of the User Origin. I added a table of the values related to VectorScript origin in the article [http://www.vectorlab.info/index.php?title=Absolute_Origin#Available_routines:Link Absolute Origin], by Gerard Jonker, on VectorLab.
 
[[VS:Set3DRot]], [[VS:SetRot3D]], [[VS:GetPolyPt3D]], and other functions, may be using the wrong origin.
 
There are several complicating factors - 3D objects really have their own coordinate space (working plane/ground plane) - old scripts should continue to work when the above problems are fixed - some complicated internal details -  etc.
 
Objects inside Symbols use the reverse of the User Origin. I added a table of the values related to VectorScript origin in the article [http://www.vectorlab.info/index.php?title=Absolute_Origin#Available_routines:Link Absolute Origin], by Gerard Jonker, on VectorLab.
</remark>
</remark>


Line 61: Line 77:
PROCEDURE Example;
PROCEDURE Example;
VAR
VAR
originPt :VECTOR;
originPt : VECTOR;
BEGIN
BEGIN
GetOrigin(originPt.x, originPt.y);
GetOrigin(originPt.x, originPt.y);
Line 67: Line 83:
END;
END;
RUN(Example);</code>
RUN(Example);</code>
==== Python ====
==== Python ====
<code lang="py">
<code lang="py">

Revision as of 16:09, 31 May 2015

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Procedure GetOrigin returns the current origin location relative to the center of the page.

PROCEDURE GetOrigin(
VAR x :REAL;
VAR y :REAL);
def vs.GetOrigin():
    return (x, y)

Parameters

x REAL Returns X coordinate of origin.
y REAL Returns Y coordinate of origin.

Remarks

(Orso, 2015.05.31):

This routine behaves differently across years and usage method:

  • until VW 2009:
    • used in Commands: returned the User origin shift in current units
    • used in Objects: returned {0, 0}
  • from VW 2010:
    • used in Commands: returns the User origin shift in current units
    • used in Objects: returns the User origin shift in millimeters

Below an example of reading the user origin shift from within a plug-in object. Save the code below as point Plug-in with Reset On Move and Rotation:

PROCEDURE HereAmI;
VAR
	pioHandle, pioRecHandle, wallHandle : HANDLE;
	pioName : STRING;
	o, s : VECTOR;

BEGIN
     IF GetCustomObjectInfo(pioName, pioHandle, pioRecHandle, wallHandle) THEN BEGIN
          GetOrigin(o.x, o.y); { on VW 2009 and before this will always be zero when used from within a plug-in object. }
          GetSymLoc(pioH, s.x, s.y);
          Locus(0, 0);
          CreateText(Concat(
               'GetOrigin: ', o, Chr(13), 
               'GetSymLoc: ', s	
          ));
     END;
END;
Run (HereAmI);

Objects inside Symbols use the reverse of the User Origin. I added a table of the values related to VectorScript origin in the article Absolute Origin, by Gerard Jonker, on VectorLab.

Example

VectorScript

PROCEDURE Example;
VAR
originPt : VECTOR;
BEGIN
GetOrigin(originPt.x, originPt.y);
Message(originPt);
END;
RUN(Example);

Python

def Example():
	originPtX, originPtY = vs.GetOrigin()
	vs.Message(originPtX, originPtY);
Example()

Version

Availability: from All Versions