Up | Draw | Overlay | Tool | Toollist | Timer | SPB | Camera | CameraImage | Bitmap | Historylist - ImageBuffer | Clipboard | ScorpionGeometry | Statistics | Curve | States | Logging | Panels | Shared Memory | BarCode Reader | StdCtrls

Obsolete interface | Release Notes
 

  

 
Tool

The tool module is designed to provide access to the Scorpion Tool instances. This is a very powerful and provides the following important features:

  • Execute a tool any number of times
  • Set all configuration parameters from script including ROIs and threshold values
  • Extract all tool results to define custom business logic with Python
  • Save and load tool configuration to file

The tool requires basic knowledge of the Scorpion SPB concept - more information

The Tool class

Use the GetTool(toolname) to get a tool instance from Scorpion.

The GetTool may also be used to access tools above or below the current level when working with toolboxes by using dot notation

Access Tools in other toolbox scopes

  • GetTool('.tf3') accesses 'tf3' at the current level
    • equals GetTool('tf3')
  • GetTool('..tf3') accesses 'tf3' at the above level
  • GetTool('aaa.tf3') accesses 'tf3' in the toolbox 'aaa'
  • GetTool(':Insp1.SETUP') accesses the 'SETUP' tool in the root level toolbox 'Insp1'
  • GetTool('.') returns the parent toolbox tool
  • GetTool('..') returns the parent toolbox parent toolbox tool
  • GetTool(':DATA') accesses 'DATA' at root level from any level

Attribute Access Type Description
bound R bool verification of valid tool name, GetTool(<name>).bound returns true/false due to valid name/existing tool or not
debugLevel R/W int debuglevel, 1..n. Used by debugMsg method to filter message level
name R string the tool name
fullname R string the fully prefixed name for toolbox children
type R string the origin tool type (Blob1, TemplateFinder3,BaseTool)
toolType R string fully qualified tool type, including template and component name/version if assigned - applies to components only
friendlyToolType R string fully qualified tool type, including template and component short name/version if assigned
pyinst R object the python instance when the tool has script methods. The instance is the same as the self argument in all script methods. See example for usage. NOTE! instance is None if no tool methods is defined.
level R int level in toolbox hierarchi, 1 at root level, 2 in second toolbox...
index R int zero based index of tool (0..n-1)
active R/W int the active flag (0/1)
manual R/W int the manual execution flag (0/1)
threaded R int the threaded execution flag (0/1)
interpolationMode R/W int interpolationMode -1=default, 0=bilinear, 1=Nearest, 2=cubic, 3=FastWide
visible R/W bool overall visible flag, overriding the below flags
visibleOperation R/W bool visible in Operation mode
visibleService R/W bool visible in Service mode
overlay R object the overlay object for visual tools, see Overlay Module
imageNo R/W int the associated image number
imageName R/W string the associated image name
colorPlane R/W int 0=No Conversion, 1=Hue, 2=Saturation, 3=Intensity
statusText R/W string easy access to StatusText result. Changes to StatusText result will be immediately shown in the tool configuration dialog statusbar if open.
state R/W int the execution state
refSys R tuple the input reference matrix ((3)(3)(3)) 
childRefSys R/W tuple the output child reference matrix ((3)(3)(3))
pose R tuple the input pose matrix ((3)(3)(3)(3))
childPose R/W tuple the output child pose matrix ((3)(3)(3)(3))
configVariant R Tool returns the tools configuration variant tool, None if no variant
configVariantName R string returns name of configuration variant tool, "" if no variant
template R string name template if attached, else empty
templateDir R string name of template directory is attached, else empty
reference R Tool returns the tools reference tool, None if no reference
referenceName R string returns the tools reference name, "" if no reference
resultReference R Tool returns the tools result reference tool
resultReferenceName R string returns the tools result reference name, "" if no result reference
guard R string returns the tools guard, <None> if not guarded
group R string returns tool group
arrState R integer arrlib arrState handle used for misc arrlib functions
calibTool R Tool returns the associated calibration tool
calibToolName R string returns the associated calibration toolname, "" if no calibration
calib R/W pointer returns a pointer to the calibration structure, normally an array tree
config R/W string the SPB-XML string for the tool
localConfig R/W string the SPB-XML local configuration string for the tool, applies to tools grouped in either HARDWARE,CALIBRATION or LOCAL only
result R/W dictionary all results as a python dictionary
hedit R int window handle of configuration dialog, 0 if dialog not open
Component support
componentName R string applicable for tool components only
componentShortName R string applicable for tool components only
componentVersion R string applicable for tool components only
EK R string license ExecuteKey required to execute tool
Toolbox support
toolbox R Tool the owner tool for toolbox childs
count R int returns number of contained tools for toolbox tools

Tool result access

Method Returns Description
isResult(name)
isPoint2D(name)
isLine2D(name)
isPoint3D(name)
isLine3D(name)
isCircle(name)
isSphere(name)
isPlane(name)
isTuple(name)
bool Returns True/False if tool has named result of type given by method name.

Tuple results are supported by some tools only for faster access to large data. They are symbolized in the tools results by an icon "(..)"
addBool(name,cfg=0,default=None,prec=2,unit="")
addInt(name,cfg=0,default=None,prec=2,unit="")
addFloat(name,cfg=0,default=None,prec=2,unit="")
addString(name,cfg=0,default=None,prec=2,unit="")
addPoint2D(name,cfg=0,default=None,prec=2,unit="")
addPoint3D(name,cfg=0,default=None,prec=2,unit="")
addLine2D(name,cfg=0,default=None,prec=2,unit="")
addLine3D(name,cfg=0,default=None,prec=2,unit="")
addCircle(name,cfg=0,default=None,prec=2,unit="")
addSphere(name,cfg=0,default=None,prec=2,unit="")
addPlane(name,cfg=0,default=None,prec=2,unit="")
addFloatVec1D(name,cfg=0,default=None,prec=2,unit="")
addFloatVec2D(name,cfg=0,default=None,prec=2,unit="")
addFloatVec3D(name,cfg=0,default=None,prec=2,unit="")
addFloatMatr1D(name,cfg=0,default=None,prec=2,unit="")
addFloatMatr2D(name,cfg=0,default=None,prec=2,unit="")
addFloatMatr3D(name,cfg=0,default=None,prec=2,unit="")
int Returns no of items added. Added results are "Dynamic" results and may be deleted. Results are considered static results and should be added only.

By setting cfg<>0, the result is configuration result and value and valid flag are persistent and not reset before tool execution.

Point2D - (float,float)
Point2D - (float,float,float)

Line2D - ((float,float),(float,float))
Line3D - ((float,float,float),(float,float,float))

Circle - ((float,float),float)
Sphere- (((float,float,float),float)
Plane - (float,float,float,float)

FloatVec1D - tuple of float
FloatVec2D - tuple of (float,float)
FloatVec3D - tuple of (float,float,float)

FloatMatr1D - tuple of floatVec1D
FloatMatr2D - tuple of floatVec2D
FloatMatr3D - tuple of floatVec3D
deleteDynamicResults() int Returns no of items deleted. Deleting dynamic results must be used carefully as results may be linked to other tools or components in the profile. This method is primarily ment for cleanup during tool development and requires SDK license and the actual tool's configuration dialog to be open to execute. 
getDynInt(name,default=None,min=maxint,max=maxint)
getDynFloat(name,default=None,min=-maxdouble,max=maxdouble)
getDynString(name,default=None)
getDynResult(name,default=None)
getDynPoint2D(name,default=None)
getDynPoint3D(name,default=None)
getDynLine2D(name,default=None)
getDynLine3D(name,default=None)
value return either numeric value or value from linked parameter
getValue(name)
getBool(name)
getInt(name)
getFloat(name)
getString(name)
getResult(name)
getPoint2D(name)
getLine2D(name)
getPoint3D(name)
getLine3D(name)
getCircle(name)
getSphere(name)
getPlane(name)
getFloatVec1D(name)
getFloatVec2D(name)
getFloatVec3D(name)
getFloatMatr1D(name)
getFloatMatr2D(name)
getFloatMatr3D(name)
getTuple(name)
Tool get result methods

Returns a single or tuple value due to method name from the tool results.
setValue(name,value,valid=True)
setBool(name,value,valid=True)
setInt(name,value,valid=True)
setFloat(name,value,valid=True)
setString(name,value,valid=True)
setResult(name,value,valid=True)
setPoint2D(name,value,valid=True)
setLine2D(name,value,valid=True)
setPoint3D(name,value,valid=True)
setLine3D(name,value,valid=True)
setCircle(name,value,valid=True)
setSphere(name,value,valid=True)
setPlane(name,value,valid=True)
setFloatVec1D(name,value,valid=True)
setFloatVec2D(name,value,valid=True)
setFloatVec3D(name,value,valid=True)
setFloatMatr1D(name,value,valid=True)
setFloatMatr2D(name,value,valid=True)
setFloatMatr3D(name,value,valid=True)
setTuple(name,value,valid=True)
int Tool set result methods

Set tool results, value type corresponds to method name.

Returns 1 for success, 0 for fail.
getValid(name)
getValidPoint2D(name)
getValidLine2D(name)
getValidPoint3D(name)
getValidLine3D(name)
getValidCircle(name)
getValidSphere(name)
getValidPlane(name)
int Tool get result validation methods - returns true or false for a tool result.
setValid(name,valid)
setValidPoint2D(name,valid)
setValidLine2D(name,valid)
setValidPoint3D(name,valid)
setValidLine3D(name,valid)
setValidCircle(name,valid)
setValidSphere(name,valid)
setValidPlane(name,valid)
int Tool set result validation methods - sets true or false of a tool result
Visualization
addVisualObject(name,color,visible=True) bool Add item in the Visulalization list.
getObjectColor(name) string returns the color from visualization list if defined, else None
getObjectVisible(name) bool returns boolean whether the object is checked or not in visualization list
clearOverlay() 0/1 clears overlays. Is tool is a ToolBox tool, then embedded tools overlays are cleared as well
     
Coordinate transforms    
objToPix(point) (x,y) converts tool object coordinates to pixels, single point, tuple/list of point tuples or arrlib object
pixToObj(point) (x,y) converts pixel coordinates to tool object coordinates, single point, tuple/list of point tuples or arrlib object
childToPix(point) (x,y) converts tool child coordinates to pixels, single point tuple, tuple/list of point tuples or arrlib object
pixToChild(point) (x,y) converts pixels to tool child coordinates, single point tuple, tuple/list of point tuples or arrlib object
toObj(referenceName,point) (x,y)(x,y,z) transform 2D or 3D single point tuple, tuple/list of point tuples or arrlib object from tool object coordinates into the references result coordinates.
decimate(image,pitch,size=None,center=(0,0)) matr decimate image. Pitch may be either scalar or (px,py) for aniso desimation.

If size is None, whole image is decimated. Set center to offset from incoming reference. ROI is automatic clipped if outside image.
resample(image,pitch,size=None,center=(0,0),angle=0) matr resample image using the tools calibration and reference. Pitch may be either scalar or (px,py) for aniso resampling.

If size is None, whole image is resampled
 
Configuration
     
expandLink(tag) string expands links of dynamic indexing format <name>%1i.<param>%2i
getConfigValue(tag,value) value returns the configuration value of a tool - more
setConfigValue(tag,value,reload=True) bool sets the configuration value of a tool - more
load(filename,section="") bool loads configuration from spb configuration file. SPB section is given by tool name. The  optional parameter section may be given if tool section is not located at spb root level.
save(filename,section="") bool saves configuration to spb configuration file. SPB section is given by tool name. The  optional parameter section may be given if tool section is not located at spb root level.
edit(tabindex=0,context="") bool opens the configuration dialog. Only one configuration may be open at a time. Returns 0 if another dialog is already open.

Optional tabindex and dialog context may be given to specify one tab only
Misc
debugMsg(msg,level=1) bool print message to console. The message is printed if level is equal or less than the property "debugLevel"
errorMsg(msg) bool print error message to console, always printed.
showHelpDlg(msg,header='') bool show help dialog
reset(force=False) bool resets all results and overlays. Some tools like External<Type> and BaseTool, values are persistent by default. To force reset of results added by python (add<Type>) and cfg parameter set to 0/False, set force to 1/True.
execute(image=None) bool executes the tool. The optional matrix is an image matrix as defined in the ArrLib library. When no parameter is given the tool executes on the image given by the tools imageindex. By supplying an image matrix, the tool can execute on another image (the matrix is retrieved by the GetImageMatr(imagename) function.
executeCmd(cmd, param="") bool executes a tool specific command. See the actual tool for available commands.
More information.
apply() bool apply configuration if dialog is open
Toolbox support
get(name) Tool returns contained tool for toolbox tools by name
tool(index) Tool returns contained tool for toolbox tools by index
 Note: Modifying the result dictionary, the dictionary itself has to be assigned to the tool.result attribute after modification is done, see the two examples below

Example 1 - Set a tool result

t=GetTool('ExData')
t.setFloat'Radius',12.0)

Example 2 - Run tools outside normal execution order

t=GetTool('FindCircle')            
t.execute()
t=GetTool('CircleFound')         
if t.execute(None)==1:
  print 'circle found'
else:
  print 'circle not found'
im=GetImageMatr('Image2')	#get the image matrix of Image2
t.execute(im)             	#execute on another image

Example 3 - Change tool configuration using the SPB

import SPB
t=GetTool('FindReference')
spb=SPB.CreateSpb(t.config)
spb.setFloat('ROI.x',10.3)  
spb.setFloat('ROI.y',15.2)
t.config=spb.xml

Example 4 - Access tools outside current toolbox (valid inside toolbox scripts only)

t=GetTool('.')		#returns owner toolbox tool
t=GetTool(':DATA')		#returns the tool 'DATA' at root level from whatever scope
t=GetTool('Circle.SETUP')	#returns the toolbox tool 'SETUP' in the toolbox 'Circle' at current level

Example 5 - Load and save tools

def LoadTool(name,fileName):
  #precondition: tool and file exists with identical tool class
  #postcondition: tool is loaded from file 
  return GetTool(name).load(fileName)
def SaveTool(name,fileName):
  #precondition: tool exists 
  #postcondition: tool configuration is written to file  
  return GetTool(name).save(fileName)

 

Example 6 - Accessing the python instance

Below is two methods defined in the tool scripts, the predefined 'init' scripts defined a instance property cnt. The 'execute' method is a user defined method taking a command argument. From the outside, both the cnt property and the execute method may be accessed, as seen in then last lines of the example.

Note that the instance is None if the tool don't implement any methods.

def init(self):
  self.cnt=0
def execute(self,command):
  if command=='inc':
    self.cnt+=1
  elif command=='dec':
    self.cnt-=1
  elif command=='reset':
    self.cnt=0
#sample code for accessing the instance
t=GetTool('py0')
if t.pyinst<>None:
  if t.pyinst.cnt<10:
    t.pyinst.execute('inc')
  else:
    t.pyinst.execute('reset')
  print 'cnt',t.pyinst.cnt



Scorpion Vision Version XII : Build 714 - Date: 20180713
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2018 Tordivel AS.