Sample Automation Script 4 - Passing Data into a Script
This script shows how to pass a variable's ID into a script from a PC-DMIS measurement routine, how to locate the passed in ID in the script, and then how to modify the right side of the ASSIGN command associated with the ID.
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. |
Sample Measurement Routine Code
START =LABEL/
C1 =COMMENT/INPUT,NO,'Type a variable's id: V1, V2, V3, V4, or V5.'
IF/C1.INPUT <> "V1" AND C1.INPUT <> "V2" AND C1.INPUT <> "V3" AND C1.INPUT
<> "V4" AND C1.INPUT <> "V5"
COMMENT/OPER,NO,You did not enter a correct variable ID.
GOTO/START
END_IF/
ELSE/
CS1 =SCRIPT/FILENAME= D:\MYAUTOMATIONSCRIPTS\SETASSIGNMENTVALUE.BAS
FUNCTION/Main,SHOW=YES,ARG1=C1.INPUT,,
STARTSCRIPT/
ENDSCRIPT/
ASSIGN/V1 = ""
ASSIGN/V2 = ""
ASSIGN/V3 = ""
ASSIGN/V4 = ""
ASSIGN/V5 = ""
END_ELSE/
SETASSIGNMENTVALUE.Bas Code
Below is the code for SETASSIGNMENTVALUE.BAS. Once the script opens, it takes the passed in ID, cycles through all the commands, and when it finds the matching ID, it displays an input box asking you to specify a new value for the command:
SetAssignmentValue.Bas | Copy Code |
---|---|
Sub Main (strID As String) Dim App As Object Set App = CreateObject ("PCDLRN.Application") Dim Part As Object Set Part = App.ActivePartProgram Dim Cmds As Object Set Cmds = Part.Commands Dim Cmd As Object Dim FCCmd As Object Dim VarCommentValue As Variant VarCommentValue = InputBox("Type a Value for " & strID & ". (Surround what you Type With quotation marks To make it a String.)","Set Assignment Value","""Type Something Here""") For Each Cmd In Cmds If Cmd.TypeDescription = "Assignment" Then Set FCCmd = Cmd.FlowControlCommand If FCCmd.GetLeftSideOfExpression = strID Then FCCmd.SetRightSideOfAssignment VarCommentValue End If End If Next Cmd End Sub |