hexagon logo

Update assignment with Excel(vba)

Hello – Taking a stab at running DMIS from excel. Below is a test bed I am working on mostly copied from posts here. I am running it in an excel command button at the moment. When running scripts in DMIS itself, I can pass info back to assignments pretty easily. The same code doesn’t seem to be working in VBA for passing info back to an assignment. Or do I have something silly wrong? In the code below I can see that I get the “looking at commands” comment to pop up for the number of commands in the DMIS program (tiny program so it pops up about 11 times). But it doesn’t seem to recognize any commands as assignments. The intent here is to use excel, not visual basic 6.
PC-DMIS CAD++ version 2013MR1



Private Sub CommandButton1_Click()

' Launch PC-Dmis by creating the app object
Dim App As Object
Set App = CreateObject("PCDLRN.Application")
If Not App.WaitUntilReady(300) Then
    MsgBox "Machine did not initialize, Exiting"
Exit Sub
End If

'if you get here, the machine initialized successfuly
' Ask the App object for the partprograms object
Dim Parts As Object
Set Parts = App.PartPrograms
App.Visible = True
App.SetActive
App.Maximize
' Ask the Partprograms object to display the file
' open dialog and return the opened part program object
Dim Part As Object
' Set Part = Parts.Open("c:\tmp\lot.prg", "CMM1")
Set Part = Parts.Open("c:\tmp\lot.prg", "OFFLINE")
App.Visible = True
App.SetActive
App.Maximize


Dim Act_Part As Object
Set Act_Part = App.ActivePartProgram
Dim Cmds As Object
Dim Cmd As Object
Set Cmds = Act_Part.Commands
Dim lot_number As String

lot_number = "0025"

For Each Cmd In Cmds
    MsgBox "did i get here - looking at commands"
    If Cmd.Type = ASSIGNMENT Then
        MsgBox "did i get here - found assign command"
        If Cmd.GetText(DEST_EXPR, 0) = "LOTNUM" Then
            bln = Cmd.PutText("""" + lot_number + """", SRC_EXPR, 0)
            Cmd.ReDraw
        End If
    End If
Next Cmd




' Execute the opened part program
'Part.Execute
' Close the part program
'Part.Close
' Quit the Application (shut down PC-Dmis)
'App.Quit
End Sub


Thanks