hexagon logo

Trying to change the expression of an IF_GOTO...

IF_GOTO/TYPE==1,GOTO = CS1
GOTO/PROBLEM

We are using a trace field which is put into a variable "TYPE" to ensure that we are using the correct program at the correct machine. (We have a hodge-podge of different machine/probe types. TIGO, LSPS, SP25.)

The reason is that the probe options are different per machine type, so we use a trace field to ensure that the user is running the right version of the program.

In any case, the above code is in all of our programs in a particular department. (That department has up until now, only run SP25 probes, but they will be getting LSPS probes soon.)

Therefore, I want to automate the ability to take an existing SP25 program and convert it to LSPS. 

I will need to change the OPTIONPROBE settings, but that comes later. 

My first problem is how to change the above code to read:

IF_GOTO/TYPE==3,GOTO = CS1

Here's part of the code from my basic script:

Set App = CreateObject("PCDLRN.Application")
Set Part = App.ActivePartProgram
strCrntName = Part.FullName

dmis_version_string = App.VersionString


If UCase(dmis_version_string) <> "2020 R2" Then
MsgBox "It's not running in 2020."
Exit Sub
End If

Set DmisCommands = Part.Commands
command_count = DmisCommands.Count
Set DmisCommand = DmisCommands.Item(command_count)
DmisCommands.InsertionPointAfter DmisCommand

For Each DmisCommand In DmisCommands
    '74 = FlowControlCmd
    If DmisCommand.Type = 74 Then
   

        'here's where I need to change the FlowControlCmd's expression.

    End If

...Code continues on from here...

I know that I need to convert the generic DMISCommand to a FlowControlCmd object, but I don't know how to do this. 

Then how to I change the expression?

Parents
  • Dim App As Object
    Dim Part As Object
    Dim Flow As Object
    
    Set App = CreateObject("PCDLRN.Application")
    Set Part = App.ActivePartProgram
    strCrntName = Part.FullName
    
    dmis_version_string = App.VersionString
    
    If UCase(dmis_version_string) <> "2020 R2" Then
    MsgBox "It's not running in 2020."
    Exit Sub
    End If
    
    Set DmisCommands = Part.Commands
    Set Flow = DmisCommands.FlowControlCommand 'Set flow here
    command_count = DmisCommands.Count
    Set DmisCommand = DmisCommands.Item(command_count)
    DmisCommands.InsertionPointAfter DmisCommand
    
    For Each DmisCommand In DmisCommands
        '74 = FlowControlCmd
        If DmisCommand.Type = 74 Then
       
    
            'here's where I need To change the FlowControlCmd's expression.
    

    Have you tried this? Dim Flow as Object(or whatever variable you want) and then set it further down? Or Dim/Set the Type As Object, and Type = DmisCommand.Type

    I may need more information on what direction you are trying to go with this if any of these ideas don't help.

Reply
  • Dim App As Object
    Dim Part As Object
    Dim Flow As Object
    
    Set App = CreateObject("PCDLRN.Application")
    Set Part = App.ActivePartProgram
    strCrntName = Part.FullName
    
    dmis_version_string = App.VersionString
    
    If UCase(dmis_version_string) <> "2020 R2" Then
    MsgBox "It's not running in 2020."
    Exit Sub
    End If
    
    Set DmisCommands = Part.Commands
    Set Flow = DmisCommands.FlowControlCommand 'Set flow here
    command_count = DmisCommands.Count
    Set DmisCommand = DmisCommands.Item(command_count)
    DmisCommands.InsertionPointAfter DmisCommand
    
    For Each DmisCommand In DmisCommands
        '74 = FlowControlCmd
        If DmisCommand.Type = 74 Then
       
    
            'here's where I need To change the FlowControlCmd's expression.
    

    Have you tried this? Dim Flow as Object(or whatever variable you want) and then set it further down? Or Dim/Set the Type As Object, and Type = DmisCommand.Type

    I may need more information on what direction you are trying to go with this if any of these ideas don't help.

Children
  • Ok, I got it. Here's the final code:

    (The bold lines are what I needed.)

    Sub main()
    Dim App As Object
    Dim Part As Object
    Dim strCrntName As String
    Dim dmis_version_string As String
    Dim DmisCommands As Object
    Dim DmisCommand As Object
    Dim command_count As Integer
    Dim current_speed As Integer
    Dim flow_control_command As Object
    Dim option_probe_object As Object

    Set App = CreateObject("PCDLRN.Application")
    Set Part = App.ActivePartProgram
    strCrntName = Part.FullName

    dmis_version_string = App.VersionString


    If UCase(dmis_version_string) <> "2020 R2" Then
        MsgBox "It's not running in 2020."
        Exit Sub
    End If

    Set DmisCommands = Part.Commands
    command_count = DmisCommands.Count
    Set DmisCommand = DmisCommands.Item(command_count)
    DmisCommands.InsertionPointAfter DmisCommand

    For Each DmisCommand In DmisCommands
    '74 = FlowControlCmd
    If DmisCommand.Type = 74 Then
    Set flow_control_command = DmisCommand.FlowControlCommand
    If Not flow_control_command Is Nothing Then
    If flow_control_command.Expression = "Type==1" Then
    flow_control_command.Expression = "Type==3"
    End If
    End If
    End If

    '111 = OPTIONPROBE object
    If DmisCommand.Type = 111 Then
    Set option_probe_object = DmisCommand.OptionProbeCommand
    If Not option_probe_object Is Nothing Then
    option_probe_object.MaxForce = 0.096
    option_probe_object.LowForce = 0.019
    option_probe_object.UpperForce = 0.072
    option_probe_object.TriggerForce = 0.033
    option_probe_object.ScanOffsetForce = 0.06
    option_probe_object.ReturnSpeed = .4
    End If
    End If

    Next

    End Sub