Skip to content

Script Loop

Project Flow

1. Initialization

  1. Select the Lua Language Script tool, and initialize two global variables to store the current row and column of the loop.
lua
-- Set global variables to store the current row and column
SetVariable("Column", 0)
SetVariable("Loop", 0)
  1. Use the Load Point Cloud Tool to load the point cloud image to be processed.

2. Preprocessing

Plane Fitting

  1. Use the 3D Region Tool to select the region for plane fitting.

  2. Use the 3D Plane Tool, bind the variable region output by the operator in the previous step as the input region, fit the plane, and set it as the zero plane.

3. Script Loop for Pin Height Measurement

  1. Use the 3D Clipping tool to clip the region of the Pin to be measured.

  2. Use the 3D Transformation tool to rotate the Pin region.

  3. Use the 3D Blob tool to frame the required Pins and obtain the position information of each Pin.

  1. Select the Marker tool, set the name to loopColumn, and use it as the row loop jump point.

  2. Select the Lua Language Script tool, bind the Pin center position information output by the 3D Blob tool and name it blob. Set the current column number to Loop = 0, obtain the current row number, get the starting point coordinates of this row, and save them to StartColumn.

lua
-- Set the column number to zero, starting from the first Pin of a new row.
SetIntVariable("Loop", 0)
-- Get the current row number
Column = GetVariable("Column")
-- Get the coordinates of the starting point of the current row
x = blob[Column + 1].X
y = blob[Column + 1].Y
z = blob[Column + 1].Z
-- Assign the starting point coordinates to "StartColumn"
SetPoint3D("StartColumn", x, y, z)
  1. Select the Marker tool, set the name to loopPin, and use it as the column loop jump point.

  2. Select the Lua Language Script tool, set the start and end coordinates of the box to 0, bind the row start point coordinates output by the Lua script tool in Step 5 and assign them to cs_x, cs_y, cs_z, get the current column number, perform arraying based on the spacing between two Pins, and then push the box data to the operator output variable.

lua
pcb_pinsx1 = 0
pcb_pinsy1 = 0
pcb_pinsz1 = 0
pcb_pinex1 = 0
pcb_piney1 = 0
pcb_pinez1 = 0

Loop = GetVariable("Loop")

-- 2.5 and 0.5 can be adjusted freely according to the on-site device drawings; the data here has no actual reference significance
pcb_pinsx1 = cs_x + Loop * 2.5 - 0.5
pcb_pinex1 = cs_x + Loop * 2.5 + 0.5
pcb_pinsy1 = cs_y - 0.8
pcb_piney1 = cs_y + 0.8
pcb_pinsz1 = cs_z - 0.1
pcb_pinez1 = cs_z + 0.6


-- Push the box position information to the register for height measurement
SetBox("box1", pcb_pinsx1, pcb_pinsy1, pcb_pinsz1, pcb_pinex1, pcb_piney1, pcb_pinez1)
DrawBox(0, "green", pcb_pinsx1, pcb_pinsy1, pcb_pinsz1, pcb_pinex1, pcb_piney1, pcb_pinez1)
  1. Select the 3D Height tool, bind the output variable (box) of the Lua script tool in the previous step as the region to be measured, and measure the height.

  2. Select the Lua Language Script tool to judge the number of rows and columns. When the column number is less than 3, jump to the loopPin marker; when the column number is equal to 3, jump to the loopColumn marker; when the row number is equal to 5, jump to the End marker.

lua

-- Loop judgment
Loop = GetVariable("Loop") + 1
if Loop == 3 then
    Column = GetVariable("Column") + 1
    SetIntVariable("Column", Column)
    if Column < 5 then
    -- Loop for 5 rows
        Jump("loopColumn")
    else
        Jump("End")
    end
elseif Loop < 3 then
    -- Inner loop of the row
    Jump("loopPin")
end

SetIntVariable('Loop', Loop)
  1. Select the Marker tool, set the name to End, and use it as the loop termination jump point.

AI-Vision, Making 3D Measurement Easier