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

Release Notes
 

  

 
Toollist

Use the GetToolList() to get the toolList instance from Scorpion

The GetToolList() may also be used to access tools in toolboxes at difference levels

GetToolList('.') returns the toollist at current level, equals GetToolList()
GetToolList('..') returns the above toolbox parent toollist
GetToolList('TB') returns the toollist of the toolbox 'TB' at current level
GetToolList(':') returns the root level toollist from any level
GetToolList(':TB') returns the toolist of the toolbox 'TB' at root level from any level

The ToolList uses the guards and active flag when executing tools (as opposites to the Tool class)

Attribute Access Type Description
count R int number of tools in toollist
next R/W string name of next tool in execution loop
recursiveCount R int current recursive counter, may be used to prevent entering too many recursive calls to execute
execCount R int total tools executed in last Inspect command
config R/W string toolbox configuration XML string

 

Method Returns Description
indexof(name) int Return index of tool
get(name) Tool Returns python Tool instance by name - more information
tool(index) Tool Returns python Tool instance by index - more information
reset(first="",last="") 0/1 Resets all tool results for a range of tools.
The first and last parameters are optional, but if last tool is given the first tool has to be given too. If first and last is omitted all tools will be reset.
add(type,name,notify=True) Tool Adds a tool of given type and name. Note that both type and name is case sensitive. If add fails, either due to type error or duplicate names, no tool instance is returned. The optional notify parameter notifies tool added. If multiple tools are to be added notified should be set to 0 and instead call the changeNotify method when done instead.
Note : Use tool object to configure tool instance or load tool configuration from a file.
insert(index,type,name,notify=True) Tool Inserts a tool at a given zero indexed position, see the add function for more information
delete(name) 0/1 Deletes a tool - returns 1 if deleted, else 0.
Note : A tool cannot be deleted if it is referred by another tools - you have to remove any dependencies before deletion.
deleteAll(notify=True) 0/1 deletes all tools in the toolist.
load(filename ,section="") 0/1 Loads tools from configuration file. Load replaces an existing toollist.  The filename must point to a valid toollist spb configuration file.
This can be a scorpion.spb file or an spb exported from Scorpion.
In the standard Scorpion configuration file - scorpion spb - the section is tools.config. When the section name is omitted tools will be loaded from spb configuration file's root level.
save(filename,section="") 0/1 Saves all tools to a spb configuration file. If section name is omitted the tools will be saved at spb root level.
clearOverlays(first="",last="") 0/1 Clears all overlay graphics for a range of tools. The first and last are optional, but if last tool is given the first tool has to be given too. If first and last is omitted all tools will be reset.
execute(first="",last="",manuals=True) 0/1 Executes a range of tools. The first, last and manuals are optional. If first and last is omitted all tools will be executed,  manual tools included. If manuals=0 the tool execution will be executed as in Scorpion inspect command. The general purpose of this method is to execute a group of manual tools.
changeNotify() 0/1 notify Scorpion it has been a change in the toollist.
Special care must be taken to prevent entering recursively execution of the ToolList.

When manipulating the tool list by scripts, deleting and adding tools, some operations have an optional notify parameter. The notify parameter is for speed optimization when executing multiple operations on the tool list.  Make sure to call notifyChanges when done. If not notifying Scorpion may enter an unstable condition if a module in Scorpion refers a deleted tool or parameter.

Example 1 - Execute a selected tool range four times

#the following example executes a range of tools 4 times, changing the image reference in each loop.
#this way 4 different images may be executed equal with a minimal number of tools  
tools=GetToolList()
for i in range(4):
  SetValue('ImageRef.Value',i+1)                #sets the external scalar used as  image reference
  tools.execute('Locate','ExportResults',0)     #exceutes tools named 'Locate' until including 'ExportResults', ignoring manual tools

Example 2 - Change Toolist Execution Order

tools=GetToolList()
tools.execute('FindLine0','FindLine10')
tools.next = 'Blob2' # sets the next tool to be executed

Example 3 - Iterating all templatefinder to Classify Inspection Status

tools=GetToolList()
ok = 1
for i in range(tools.count):
  tool = tools.tool(i)
  if tool.type == 'TemplateFinder3' and not(tool.name == 'tf3') :
    b0 = tool.getIntValue('Count') == 1 # object present
    print i+1,' - ', tool.name,b0
    if not b0:
      spb=SPB.CreateSpb(tool.config)
      x = spb.getFloat('Center.X')
      y = spb.getFloat('Center.Y')
      DrawText('',x,y,tool.name,'Red',12)
    if ok and not b0 :
      ok = 0

SetIntValue('Pass.Value',ok)

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

def browse(name):
  print '--- tools in "%s" ---'%name
  tools=GetToolList(name)
  for i in range(tools.count):
    t=tools.tool(i)
    print t.fullname,t.type

browse(':')    #root level
browse('tbox') #tools of toolbox 'tbox' at current level
browse('.')    #tools at current level
browse('..')   #tools at above level
 

Scorpion Vision Version XII : Build 665 - Date: 20170919
Scorpion Vision Software® is a registered trademark of Tordivel AS.
Copyright © 2000 - 2017 Tordivel AS.