The following 2D functions are available for visualizing in an image.
- ok = DrawMarker(refName, x, y, color, markerSize, vertexStyle)
- ok = DrawLine(refName, x, y, u, v, color, penWidth, vertexStyle)
#u=length, v=angle units
- ok = DrawLineEx(refName, x1, y1, x2, y2, color, penWidth, penStyle)
#x2,y2 - end point
- ok = DrawRect(refName, x, y, w, h, color, penWidth, penStyle)
- ok = DrawPolygon(refName, pnts, color, penWidth, penStyle, closed)
- ok = DrawCircle(refName, x, y, r, color, penWidth, penStyle)
- ok = DrawText(refName, x, y, text, color, fontSize, fontName,
backColor, textStyle)
The following 3D functions are available for visualizing in an image.
- ok = DrawMarker3D(refName, x, y, z, color, markerSize, vertexStyle)
- ok = DrawLineEx3D(refName, x1, y1, z1, x2, y2, z2, color, penWidth, penStyle)
#x2,y2 - end point
- ok = DrawText3D(refName, x, y, z, text, color, fontSize, fontName,
backColor, textStyle)
When drawing from a PythonScript tool, either from the tool directly, or
by calling Central scripts from the PythonScript tool, all drawing will be
in the image given by the PythonScript's ImageIndex.
When drawing in Central
scripts and the caller is not a PythonScript tool, the image to draw in must
be given by the DrawAt function.
Transform functions:
- PixToRef - transform from pixel coordinates to
reference coordinates
- (x,y) = PixToRef( refName, x, y )
- (x,y) = PixToRef( refName, p )
available from 9.2.0.513
- ((x,y),(x,y)..(x,y)) = PixToRef( refName, pnts )
available from 9.2.0.513
- RefToPix - transform from reference coordinates
to pixel coordinates
- (x,y) = RefToPix( refName, x, y )
- (x,y) = RefToPix( refName, p )
available from 9.2.0.513
- ((x,y),(x,y)..(x,y)) = RefToPix( refName, pnts )
available from 9.2.0.513
From version 9.2.0.513
The parameters in italics are optional.
- refName -
- text
- referencename
- refName="" means pixelcoordinates or coordinates of
tool instance
- x,y -
- pnts -
- array of points as python tuple, ((x1,y1),(x2,y2),(x3,y3),...(xn,yn))
- color -
- text
- 'Red',
'Yellow', 'Blue', 'White', 'BtnFace' etc....
- '$Hex' - '$FFFF00'=Cyan, '$FF0000'=Blue etc...
- '0xHex' - '0xFFFF00'=Cyan, '0xFF0000'=Blue etc...
- Default is 'Yellow'
- vertexStyle -
- integer
- ovsNone=0, ovsDot=1, ovsPlus=2, ovsX=3, ovsStar=4,
- ovsCir=5, ovsCrosshairs=6, ovsLine=7, ovsDotLine=8,
- ovsPlusLine=9, ovsXLine=10, ovsStarLine=11, ovsCirLine=12,
- ovsCrosshairsLine=13, ovsArrow=14, ovsDotArrow=15,
- ovsPlusArrow=16, ovsXArrow=17, ovsStarArrow=18,
- ovsCirArrow=19, ovsCrosshairsArrow=20, ovsFatX=21,
- ovsTriangle=22, ovsStop=23, ovsSquare=24
- markerSize
-
- integer - pixelsize on marker
-
default=3
- penWidth -
- integeri - penwidth
- default = 1
- penStyle -
- integer
- psSolid=0, psDash =1, psDot=2, psDashDot=3, psDashDotDot=4,
psClear=5, psFilled=6
- fontsize -
- font size in points
- default = -1
- fontName -
- backColor -
- the text back color, coded the same way as color
- default = '' - transparent background
- textStyle
- binary coded integer
- 1=bold, 2=italic, 3=underline, 4=strikethrough
- default=0 (nomal text)
Example 1: DrawLineEx
- DrawLineEx('Reference',10,10,20,20,'Red',2,0)
Example 2: Drawmarker
- DrawMarker('',12,12,'Blue',12,18)
Example 3: DrawRect
- DrawRect('Reference',12,12,200,100,'Yellow',3,1)
Example 4: DrawPolygon
- DrawPolygon('Reference',((0,0),(10,13),(13,17),(20,11)),'red')
Example 5: DrawText - default font tahoma
- DrawText('Reference',10,10,'Some Text')
Example 6: DrawText - fontsize 12 - bold with default font yellow on
red background
- DrawText('Reference',10,10,'Some Text','yellow',12,'','red',1)
Example 7: 3D Measurement Visualisation

def GetPoint3D(name):
x = GetFloatValue(name+'_x')
y = GetFloatValue(name+'_y')
z = GetFloatValue(name+'_z')
return x,y,z
def CenterPoint3D(x1,y1,z1,x2,y2,z2):
x = x1 + (x2-x1)/2.0
y = y1 + (y2-y1)/2.0
z = z1 + (z2-z1)/2.0
return x,y,z
x,y,z = GetPoint3D('Height.center')
print 'pos -',x,y,z
str0 = '(%(x).1f,%(y).1f,%(z).1f) [mm]' %vars()
DrawMarker3D('1-3DRef',x,y,z,'Red')
DrawText3D('1-3DRef',x,y,z,str0,'yellow',10,'','red',1)
status = GetValue('Height.status')
if status == 1 :
x,y,z = GetPoint3D('Height.corner')
print 'pos -',x,y,z
str0 = '(%(x).0f,%(y).0f,%(z).0f) [mm]' %vars()
DrawMarker3D('1-3DRef',x,y,z,'Red')
DrawText3D('1-3DRef',x,y,z,str0,'red',10,'','yellow',1)
x,y,z = GetPoint3D('Height.corner2')
print 'pos -',x,y,z
DrawMarker3D('1-3DRef',x,y,z,'Red')
x,y,z = GetPoint3D('Height.corner3')
print 'pos -',x,y,z
DrawMarker3D('1-3DRef',x,y,z,'Red')
w = GetValue('Height.width')
x,y,z = GetPoint3D('Height.corner')
x2,y2,z2 = GetPoint3D('Height.corner2')
x,y,z = CenterPoint3D(x,y,z,x2,y2,z2)
str0 = 'w=%(w).0f [mm]' %vars()
DrawText3D('1-3DRef',x,y,z,str0,'red',10,'','yellow',1)
h = GetValue('Height.height')
x,y,z = GetPoint3D('Height.corner')
x2,y2,z2 = GetPoint3D('Height.corner3')
x,y,z = CenterPoint3D(x,y,z,x2,y2,z2)
str0 = 'h=%(h).0f [mm]' %vars()
DrawText3D('1-3DRef',x,y,z,str0,'red',10,'','yellow',1)
Example 7: Drawing a 3D Cube |
|
|

def DrawCube3D(ref,x,y,z,w,d,h,color='red',line=2):
x1 = x + w
y1 = y + 0
z1 = z + 0
x2 = x + 0
y2 = y + d
z2 = z + 0
x3 = x + 0
y3 = y + 0
z3 = z + h
x4 = x + w
y4 = y + d
z4 = z + 0
x5 = x + w
y5 = y + 0
z5 = z + h
x6 = x + 0
y6 = y + d
z6 = z + h
x7 = x + w
y7 = y + d
z7 = z + h
DrawLineEx3D(ref, x, y, z, x1, y1, z1, color,line)
DrawLineEx3D(ref, x, y, z, x2, y2, z2, color,line)
DrawLineEx3D(ref, x, y, z, x3, y3, z3, color,line)
DrawLineEx3D(ref, x1, y1, z1, x4, y4, z4, color,line)
DrawLineEx3D(ref, x1, y1, z1, x5, y5, z5, color,line)
DrawLineEx3D(ref, x2, y2, z2, x6, y6, z6, color,line)
DrawLineEx3D(ref, x2, y2, z2, x4, y4, z4, color,line)
DrawLineEx3D(ref, x3, y3, z3, x5, y5, z5,color,line)
DrawLineEx3D(ref, x3, y3, z3, x6, y6, z6, color,line)
DrawLineEx3D(ref, x4, y4, z4, x7, y7, z7, color,line)
DrawLineEx3D(ref, x5, y5, z5, x7, y7, z7, color,line)
DrawLineEx3D(ref, x6, y6, z6, x7, y7, z7, color,line)
DrawCube3D('3dref',300,300,100,100,100,-200)
|