PC-DMIS 2022.2 Object Library
Sample Automation Script 1
Send Topic Feedback | See Object Hierarchy Chart

Glossary Item Box

Sample Automation Script 1 - Increment a PC-DMIS Variable

Important: After you insert a PC-DMIS comment, to type additional PC-DMIS commands in Command Mode, you must first press Enter twice after the COMMENT command. This tells PC-DMIS that you no longer want to add text to the comment but are ready to add a new command.

The following example first uses PC-DMIS code to receive an integer value from the user and assigns it to the V1 variable.

C1         =COMMENT/INPUT,NO,FULL SCREEN=NO,
            Type an integer
            ASSIGN/V1=INT(C1.INPUT)
            COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
            "BEFORE SCRIPT - Variable is: " + V1

It then calls a BASIC script named TEST2.BAS.

CS1        =SCRIPT/FILENAME= D:\MYAUTOMATIONSCRIPTS\TEST2.BAS
            FUNCTION/Main,SHOW=YES,,
            STARTSCRIPT/
            ENDSCRIPT/

Test2.bas Copy Code
Sub Main
  Dim App As Object
  Set App = CreateObject ("PCDLRN.Application")
  Dim Part As Object
  Set Part = App.ActivePartProgram
  Dim Var As Object
  Set Var = Part.GetVariableValue ("V1")
  Dim I As Object
  If Not Var Is Nothing Then
    MsgBox "Initial value of V1: " & Var.LongValue,0,"Script Message Box"
    Var.LongValue = Var.LongValue + 1
    Part.SetVariableValue "V1", Var
    MsgBox "V1 is now: " & Var.LongValue,0,"Script Message Box"
  Else
    MsgBox "Could not find a V1 variable",0,"Script Message Box"
  End If
End Sub

This script takes the V1 variable and, using the GetVariableValue and SetVariableValue automation methods, increments the value in V1 by one and then sets the new value for V1 in the measurement routine.

PC-DMIS then displays the changed variable in an operator comment.

            COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,
            "AFTER SCRIPT - Variable is: " + V1

Copyright © 2022. Hexagon Manufacturing Intelligence – Metrology Software, Inc. All Rights Reserved.