Set A Variable in PC-DMIS with a textbox in VB.Net

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Set A Variable in PC-DMIS with a textbox in VB.Net

    Hi guys,

    I have taken on the task of automating our CMM operations, and so far I have been able to push through some of my issues but I am stumped on this one. All I want to do is have the VB program output whatever is written in a textbox into a variable on PC-Dmis.

    Thanks for the help.
    Matt
    Global Advantage 5 7 5
    PC-DMIS v2014SP1

  • #2
    You need to connect to PC-DMIS through COM/OLE (in your VB app) and then fetch the value using GetVariableValue().

    I believe the necessary sources/steps for this is available in this section.
    PC-DMIS CAD++ 2o19 R1 SP4

    Comment


    • #3
      Thanks vpt

      So I keep getting a Type Mismatch error. Here is the vb code
      Code:
      Private Sub VarSet()
              Dim PCDPart As Object
              PCDPart = PCDApp.ActivePartProgram
              Dim JOBNO As Object
              JOBNO = PCDPart.GetVariableValue("JOBNO")
              Dim I As Object
              If Not JOBNO Is Nothing Then
                  JOBNO.LongValue = TextBox3.Text
                  PCDPart.SetVariableValue("JOBNO", JOBNO)
              Else
                  MsgBox("Could Not Find JOBNO Variable")
              End If
      
              endForm()
          End Sub
      And here is what I am trying to set in PC-DMIS
      Code:
      ASSIGN/JOBNO=0
      Thanks for the help guys.
      Last edited by MATT890; 10-29-2014, 09:19 AM.
      Global Advantage 5 7 5
      PC-DMIS v2014SP1

      Comment


      • #4
        .LongValue is expecting a floating point number like 3.1415926536, but you are trying to transfer text. You should use .StringValue instead.

        And I would suggest ASSIGN/JOBNO="" in the PP, so that the type is correct (I don't think that is necessary, but it helps you remembering what's expected).
        AndersI
        SW support - Hexagon Metrology Nordic AB

        Comment


        • #5
          I changed .LongValue to .StringValue and now the program runs through, but the variable doesn't change value. I also tried it with no number in the assignment, and that didn't work.
          Global Advantage 5 7 5
          PC-DMIS v2014SP1

          Comment


          • #6
            This is a snippet of code the way I do it in VB6 -

            For Each Cmd In Cmds
            If Cmd.TypeDescription = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
            bln = Cmd.PutText("1234", SRC_EXPR, 0)
            End If
            Next Cmd

            Comment


            • #7
              ^Don's method doesn't require a program execution where setvariablevalue requires the execution of the program to read and modify variable values.

              Comment


              • #8
                Is Cmds Dim'd as Cmds As PCDLRN.Commands or something else? If that is correct Im getting an "Expression is of type 'PCDLRN.Commands', which is not a collection type" error.

                Here is the whole program:
                Code:
                Imports PCDLRN
                Imports System
                Imports System.IO
                Imports System.Text
                Imports Microsoft.Office.Interop.Excel
                Imports System.Threading
                
                
                Public Class Form1
                
                    Dim PCDApp As PCDLRN.Application
                    Dim pcdpartprograms As PCDLRN.PartPrograms
                    Dim pcdActivePart As PCDLRN.PartProgram
                    Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
                    Dim Cmds As PCDLRN.Commands
                    Dim Cmd As PCDLRN.Command
                
                
                
                
                    
                        'Loads PC-DMIS and Opens the Part Program based on inputs
                    Public Sub PCDLoad()
                
                        Dim fname As String
                        fname = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & " - " & TextBox2.Text & ".PRG"
                        PCDApp = CreateObject("PCDLRN.Application")
                        PCDApp.WaitUntilReady(60)
                        Threading.Thread.Sleep(2000)
                        pcdpartprograms = PCDApp.PartPrograms
                        PCDApp.Visible = True
                        PCDApp.SetActive()
                        PCDApp.Maximize()
                        pcdpartprograms.CloseAll()
                        pcdpartprograms.Open(fname, "Machine1")
                        VarSet()
                
                    End Sub
                
                
                    Public Sub VarSet()
                        Dim PCDPart As Object
                        pcdActivePart = PCDApp.ActivePartProgram
                        Cmds = pcdActivePart.Commands
                        For Each Cmd In Cmds
                            If Cmd.TypeDescription = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                                retval = Cmd.PutText("1234", SRC_EXPR, 0)
                            End If
                        Next Cmd
                
                        endForm()
                    End Sub
                
                
                    'Loads the Set-up Sheet if one is available, Then Loads PCDLoad Sub
                    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                        Dim path As String = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & ".xlsx"
                        If SetupSheet = True Then
                            If System.IO.File.Exists(path) Then
                                Process.Start("excel.exe", String.Format("/r {0}{1}{0}", """", path))
                            Else
                                MessageBox.Show("No Set-Up Sheet Available")
                            End If
                        End If
                        PCDLoad()
                    End Sub
                
                    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
                        Me.Close()
                    End Sub
                
                    Private Sub endForm()
                        Me.Close()
                
                    End Sub
                
                    'Set-Up Sheet Code
                    Private SetupSheet As Boolean
                    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
                        If CheckBox1.Checked = True Then
                            SetupSheet = True
                        Else
                            SetupSheet = False
                        End If
                    End Sub
                
                
                End Class
                The red bit is what is hanging things up.
                Last edited by MATT890; 10-29-2014, 10:51 AM.
                Global Advantage 5 7 5
                PC-DMIS v2014SP1

                Comment


                • #9
                  Originally posted by MATT890 View Post
                  Is Cmds Dim'd as Cmds As PCDLRN.Commands or something else? If that is correct Im getting an "Expression is of type 'PCDLRN.Commands', which is not a collection type" error.

                  Here is the whole program:
                  Code:
                  Imports PCDLRN
                  Imports System
                  Imports System.IO
                  Imports System.Text
                  Imports Microsoft.Office.Interop.Excel
                  Imports System.Threading
                  
                  
                  Public Class Form1
                  
                      Dim PCDApp As PCDLRN.Application
                      Dim pcdpartprograms As PCDLRN.PartPrograms
                      Dim pcdActivePart As PCDLRN.PartProgram
                      Dim WithEvents AppEvents As PCDLRN.ApplicationObjectEvents
                      Dim Cmds As PCDLRN.Commands
                      Dim Cmd As PCDLRN.Command
                  
                  
                  
                  
                      
                          'Loads PC-DMIS and Opens the Part Program based on inputs
                      Public Sub PCDLoad()
                  
                          Dim fname As String
                          fname = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & " - " & TextBox2.Text & ".PRG"
                          PCDApp = CreateObject("PCDLRN.Application")
                          PCDApp.WaitUntilReady(60)
                          Threading.Thread.Sleep(2000)
                          pcdpartprograms = PCDApp.PartPrograms
                          PCDApp.Visible = True
                          PCDApp.SetActive()
                          PCDApp.Maximize()
                          pcdpartprograms.CloseAll()
                          pcdpartprograms.Open(fname, "Machine1")
                          VarSet()
                  
                      End Sub
                  
                  
                      Public Sub VarSet()
                          Dim PCDPart As Object
                          pcdActivePart = PCDApp.ActivePartProgram
                          Cmds = pcdActivePart.Commands
                  
                  
                          For Each Cmd In Cmds
                          Set Cmd = Cmds.Item(cnt)
                               If Cmd.Type = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                                  retval = Cmd.PutText("1234", SRC_EXPR, 0)
                              End If
                          Next Cmd
                  
                          endForm()
                      End Sub
                  
                  
                      'Loads the Set-up Sheet if one is available, Then Loads PCDLoad Sub
                      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
                          Dim path As String = "\\hemfile1\share\PartNumber\" & TextBox1.Text & "\Quality\CMM\Program Files\" & TextBox1.Text & ".xlsx"
                          If SetupSheet = True Then
                              If System.IO.File.Exists(path) Then
                                  Process.Start("excel.exe", String.Format("/r {0}{1}{0}", """", path))
                              Else
                                  MessageBox.Show("No Set-Up Sheet Available")
                              End If
                          End If
                          PCDLoad()
                      End Sub
                  
                      Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
                          Me.Close()
                      End Sub
                  
                      Private Sub endForm()
                          Me.Close()
                  
                      End Sub
                  
                      'Set-Up Sheet Code
                      Private SetupSheet As Boolean
                      Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged
                          If CheckBox1.Checked = True Then
                              SetupSheet = True
                          Else
                              SetupSheet = False
                          End If
                      End Sub
                  
                  
                  End Class
                  The red bit is what is hanging things up.
                  See bolded part

                  Comment


                  • #10
                    you may have to call out an object to set the cmd.GetText to and enclose everything in parenthesis.
                    You can also try to call out .type to the equivalent string name.

                    Code:
                    varname = "JOBNO"
                    For Each Cmd In Cmds
                            Set Cmd = Cmds.Item(cnt)
                    If ((Cmd.Type = 195) And (varname = Cmd.GetText(DEST_EXPR, 0))) Then
                                    retval = Cmd.PutText("1234", SRC_EXPR, 0)
                                End If
                            Next Cmd

                    Comment


                    • #11
                      Thanks for the help Don and Rploughe, I think the problem lies with VB.Net and/or the 2014 PCDLRN Object Library.
                      It still gives me that same error on the For Each Cmd in Cmds
                      Global Advantage 5 7 5
                      PC-DMIS v2014SP1

                      Comment


                      • #12
                        Code:
                         Public Sub VarSet()
                                Dim PCDPart,Cmds,Cmd As Object
                                 PCDPart = PCDApp.ActivePartProgram
                                Cmds = PCDPart.Commands
                        
                        
                                For Each Cmd In Cmds
                                   If Cmd.Type = "Assignment" And Cmd.GetText(DEST_EXPR, 0) = "JOBNO" Then
                                        retval = Cmd.PutText("1234", SRC_EXPR, 0)
                                    End If
                                Next Cmd
                        
                                endForm()
                            End Sub
                        See what I bolded. I think it might of been overlooked.

                        Comment


                        • #13
                          So now the DEST_EXPR, retval, and SRC_EXPR commands are saying they are not declared.
                          Global Advantage 5 7 5
                          PC-DMIS v2014SP1

                          Comment


                          • #14
                            Originally posted by MATT890 View Post
                            Thanks for the help Don and Rploughe, I think the problem lies with VB.Net and/or the 2014 PCDLRN Object Library.
                            It still gives me that same error on the For Each Cmd in Cmds
                            I do know that VB.Net has an issue with collections, they are pretty much not recognized. You would need to use something more like

                            For each Cmd in Cmds.Count

                            Comment


                            • #15
                              You can always do (PC-DMIS BASIC, might differ slightly from VB.NET)

                              Code:
                                For I = 1 to Cmds.Count
                                  Set Cmd = Cmds(I)
                                  <do something with Cmd>
                                Next I
                              or

                              Code:
                                Cmd = Cmds[1]
                                while ??some expression testing for not null which I don't remember how it should look??
                                  <do something with cmd>
                                  Cmd = Cmd.Next
                                end while
                              AndersI
                              SW support - Hexagon Metrology Nordic AB

                              Comment

                              Related Topics

                              Collapse

                              Working...
                              X