VS:GetPolyPt: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
m (fix name)
(add remark about vs python: this call clips the tuple)
Line 41: Line 41:
-----------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------
<remark>
<remark>
([[User:CBM-c-|_c_]], 2010 Dec. 22) Since the introduction of rotated rectangles, it doesn't turn them into polygons any longer. The routine fails with warning, as expected.  
([[User:CBM-c-|_c_]], 2022.01.18) In VS Python this routine will always return a 2-items tuple, clipping it if "necessary". If you need a 3 items tuple for usage in vs.Vec2Ang, for example, you will need to restore the third item.
<code lang="py">
# test GetPolyPt
p = (0, 0, 0)
vs.AlrtDialog( 'init tuple: ' + str(len(p)) ) # 3 items
p = vs.GetPolyPt(vs.FSActLayer(), 1) # take care to have a polygon selected
vs.AlrtDialog( 'after GetPolyPt: ' + str(len(p)) ) # 2 items?!?
</code>
 
Example()
 
([[User:CBM-c-|_c_]], 2010.12.22) Since the introduction of rotated rectangles, it doesn't turn them into polygons any longer. The routine fails with warning, as expected.  


(Charles Chandler, 2001 Jan. 25): Doesn't work on rectangles, unless you rotate them, which turns them into polygons.
(Charles Chandler, 2001 Jan. 25): Doesn't work on rectangles, unless you rotate them, which turns them into polygons.
Line 58: Line 69:
end;
end;
</code>
</code>
==== Python ====
==== Python ====
<code lang="py">
<code lang="py">

Revision as of 06:30, 18 January 2022

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

Description

Procedure GetPolyPt returns the coordinates of a specified vertex of the referenced object.

PROCEDURE GetPolyPt(
objectHd :HANDLE;
index :INTEGER;
VAR pX,pY :REAL);
def vs.GetPolyPt(objectHd, index):
    return p

Parameters

objectHd HANDLE Handle to polygon.
index INTEGER Index of vertex (range of 1 to n).
p REAL Returns coordinates of vertex.

Remarks

(_c_, 2022.01.18) In VS Python this routine will always return a 2-items tuple, clipping it if "necessary". If you need a 3 items tuple for usage in vs.Vec2Ang, for example, you will need to restore the third item.

# test GetPolyPt
p = (0, 0, 0)
vs.AlrtDialog( 'init tuple: ' + str(len(p)) ) # 3 items
p = vs.GetPolyPt(vs.FSActLayer(), 1) # take care to have a polygon selected
vs.AlrtDialog( 'after GetPolyPt: ' + str(len(p)) ) # 2 items?!?

Example()

(_c_, 2010.12.22) Since the introduction of rotated rectangles, it doesn't turn them into polygons any longer. The routine fails with warning, as expected.

(Charles Chandler, 2001 Jan. 25): Doesn't work on rectangles, unless you rotate them, which turns them into polygons.

(Gerard Jonker, 2007 Jan. 8) Please have a look at my comments on the VectorLab regarding this function, concerning index and origin.

Example

VectorScript

for i := 1 to GetVertNum(thePoly) do
begin		
GetPolyPt(thePoly, i, vertX, vertY);
end;	

Python

def Example():
	obj = vs.FSActLayer()
	for vertexNum in range(1, vs.GetVertNum(obj)):
		ptVt = vs.GetPolyPt(obj, vertexNum)
		vs.TextOrigin(ptVt[0], ptVt[1])
		vs.CreateText(vs.Concat('vNum: ', vertexNum))

Example()

Version

Availability: from All Versions

See Also

For polygons:

For polylines:

For polygons:
  • [[VS:SetPolyPt| SetPolyPt]]

For polylines:

  • [[VS:GetPolylineVertex| GetPolylineVertex]]
  • [[VS:SetPolylineVertex| SetPolylineVertex]]