hexagon logo

Help with OLE Automation

Now that I have information in a way that imports and exports the information correctly, I have been tasked with creating an OLE to automatically import the data into the SPC software. I have one that sort of works (as in opens the program, logs in, opens the right collection plan, etc) and I can get put in static information, but I am unsure how to call the information out of PC DMIS to have it be placed in the spots we need in the SPC software being used.

Has anyone else done this? Can anyone explain to me how find the variable and the measurement output in PC DMIS? I am using version 4.2 if that helps any.

Thanks so much.
Parents
  • So, as if I wasn't challenged enough by the legacy dimensions Rolling eyes, I decided to take a different route and start working on some of the FCF dimensions, since we only have 2 parts (at least so far) that use them. So, once again, parts of my code work and seem to work well, but the FCF portion does not.

    Begin VB.Form Form1
    	caption		= "Visual Basic OLE Client for WinSPC"
    	ClientHeight	= 4485
    	ClientLeft	= 60
    	ClientTop	= 630
    	ClientWidth	= 6150
    	LinkTopic	= "Form1"
    	ScaleHeight 	= 4485
    	ScaleWidth	= 6150
    	Begin VB.TextBox Text1
    		Height 		= 4455
    		Left 		= 0
    		MultiLine	= -1 'True
    		ScrollBars	= 2 'Vertical
    		TabIndex	= 0
    		Top		= 0
    		Width		= 6135
    	End	
    	Begin VB.Menu RunMenu
    	Caption		= "&Run"
    	End
    	End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredID = True
    Attribute VB_Expose = False
    
    Sub Main 
    'PCDMIS commands
    Dim ObjApp As Object
    Dim ObjCmds As Object
    Dim ObjCmd As Object
    Dim ObjPart As Object
    Dim ObjDimCmd As Object
    Dim lngNumCmds As Long
    Set ObjApp = CreateObject("PCDLRN.Application")
    Set ObjPart = ObjApp.ActivePartProgram
    Set ObjCmds = ObjPart.Commands
    
                Dim StrDimID As String
    	Dim StrDimFeature As String
    	Dim StrDimType As String
    	Dim StrDimNominal As String
    	Dim StrDimUTol As String
    	Dim StrDimLTol As String
    	Dim StrDimMeasure As String
    	Dim StrDimDiameter As String
                Dim DimName As String
                Dim DimMeas As String 
    	Dim MeasZ As String
                Dim StrC1 As Double 
                Dim MyReading1 As Double
        	Dim MyReading2 As Double
    	Dim MyReading3 As Double
    	Dim MyReading4 As Double
    	Dim MyReading5 As Double
    	Dim MyReading6 As Double
    
    For Each ObjCmd In ObjCmds
    If ObjCmd.IsComment Then
        If ObjCmd.CommentCommand.CommentType = PCD_COMMENT_INPUT Then 
          If ObjCmd.ID = "C1" Then
            StrC1 = ObjCmd.CommentCommand.Input
          End If
        End If
      End If
    
    If ObjCmd.IsDimension Then
    Set ObjDimCmd = ObjCmd.DimensionCommand
    StrDimID = ObjDimCmd.ID
    StrDimFeature = ObjDimCmd.Feat1
    StrDimType = ObjDimCmd.AxisLetter
    StrDimNominal = ObjDimCmd.Nominal
    StrDimUTol = ObjDimCmd.Plus
    StrDimLTol = ObjDimCmd.Minus
    StrDimMeasure = ObjDimCmd.Measured
    ElseIf ObjCmd.IsFeature Then
    StrDimID = ObjCmd.FeatureCommand.ID
    StrDimDiameter = ObjCmd.FeatureCommand.MeasDiam
    MeasZ = ObjCmd.GetText(MEAS_Z,0)
    ElseIf (ObjCmd = FEATURE_CONTROL_FRAME) Then
      DimName = ObjCmd.ID
      DimMeasure = ObjCmd.GetFieldValue(LINE2_MEAS, 0)
      StrDimNominal = ObjCmd.GetFieldValue(LINE2_NOMINAL, 0)
      StrDimDev = ObjCmd.GetFieldValue(LINE2_DEV, 0)
      StrDimAct = StrDimNominal + StrDimDev 
    End If 
    
    If StrDimID = "CIR1- DIA UNDER GROOVE" Then MyReading1 = StrDimDiameter
    If DimName = "CIRC1 ROUNDNESS" Then MyReading2 = StrDimAct
    If StrDimID = "CIR2- DIA OF GROOVE" Then MyReading3 = StrDimDiameter
    If DimName = "CIR2- DIA OF GROOVE" Then MyReading4 = StrDimAct
    If StrDimID = "CIR3- DIA ABOVE GROOVE" Then MyReading5 = StrDimDiameter
    If DimName = "CIR3- DIA ABOVE GROOVE" Then MyReading6 = StrDimAct 
    Next 
    
    Dim dc As Object 
    Dim CollectionPlanID As Object
    Dim Username As String
    Dim Password As String
    
    'Open WinSPC and Collection Plan
    Set dc = CreateObject("WinSPC.DataCollectionAuto")
    dc.Visible = True
    dc.RunHeadless = False
    While dc.ReadyForLogin = "F"
    Wend
    dc.UserName = "1675 CMM"
    dc.Password = "1675"
    
    dc.CollectionPlanID = 8549
    	dc.TagIndex = 0
    	dc.TagValue = "P162610"
    	dc.TagIndex = 1
    	dc.TagValue = StrC1
    	dc.CurrentStep = 0
    	dc.Value = MyReading1
    	dc.CurrentStep = 1
    	dc.Value = MyReading2
    	dc.CurrentStep = 2
    	dc.Value = MyReading3
    	dc.CurrentStep = 3
    	dc.Value = MyReading4
    	dc.CurrentStep = 4
    	dc.Value = MyReading5
    	dc.CurrentStep = 5
    	dc.Value = MyReading6
    
      dc.CollectionPlanID = 0
      dc.UserName = " "
      Set dc = Nothing
    
    End Sub


    I found, and I can't remember where, a sample of what I used here somewhere on this forum. But once again, I can't seem to get it to work. Slight smile Any thoughts?
Reply
  • So, as if I wasn't challenged enough by the legacy dimensions Rolling eyes, I decided to take a different route and start working on some of the FCF dimensions, since we only have 2 parts (at least so far) that use them. So, once again, parts of my code work and seem to work well, but the FCF portion does not.

    Begin VB.Form Form1
    	caption		= "Visual Basic OLE Client for WinSPC"
    	ClientHeight	= 4485
    	ClientLeft	= 60
    	ClientTop	= 630
    	ClientWidth	= 6150
    	LinkTopic	= "Form1"
    	ScaleHeight 	= 4485
    	ScaleWidth	= 6150
    	Begin VB.TextBox Text1
    		Height 		= 4455
    		Left 		= 0
    		MultiLine	= -1 'True
    		ScrollBars	= 2 'Vertical
    		TabIndex	= 0
    		Top		= 0
    		Width		= 6135
    	End	
    	Begin VB.Menu RunMenu
    	Caption		= "&Run"
    	End
    	End
    Attribute VB_Name = "Form1"
    Attribute VB_GlobalNameSpace = False
    Attribute VB_Creatable = False
    Attribute VB_PredeclaredID = True
    Attribute VB_Expose = False
    
    Sub Main 
    'PCDMIS commands
    Dim ObjApp As Object
    Dim ObjCmds As Object
    Dim ObjCmd As Object
    Dim ObjPart As Object
    Dim ObjDimCmd As Object
    Dim lngNumCmds As Long
    Set ObjApp = CreateObject("PCDLRN.Application")
    Set ObjPart = ObjApp.ActivePartProgram
    Set ObjCmds = ObjPart.Commands
    
                Dim StrDimID As String
    	Dim StrDimFeature As String
    	Dim StrDimType As String
    	Dim StrDimNominal As String
    	Dim StrDimUTol As String
    	Dim StrDimLTol As String
    	Dim StrDimMeasure As String
    	Dim StrDimDiameter As String
                Dim DimName As String
                Dim DimMeas As String 
    	Dim MeasZ As String
                Dim StrC1 As Double 
                Dim MyReading1 As Double
        	Dim MyReading2 As Double
    	Dim MyReading3 As Double
    	Dim MyReading4 As Double
    	Dim MyReading5 As Double
    	Dim MyReading6 As Double
    
    For Each ObjCmd In ObjCmds
    If ObjCmd.IsComment Then
        If ObjCmd.CommentCommand.CommentType = PCD_COMMENT_INPUT Then 
          If ObjCmd.ID = "C1" Then
            StrC1 = ObjCmd.CommentCommand.Input
          End If
        End If
      End If
    
    If ObjCmd.IsDimension Then
    Set ObjDimCmd = ObjCmd.DimensionCommand
    StrDimID = ObjDimCmd.ID
    StrDimFeature = ObjDimCmd.Feat1
    StrDimType = ObjDimCmd.AxisLetter
    StrDimNominal = ObjDimCmd.Nominal
    StrDimUTol = ObjDimCmd.Plus
    StrDimLTol = ObjDimCmd.Minus
    StrDimMeasure = ObjDimCmd.Measured
    ElseIf ObjCmd.IsFeature Then
    StrDimID = ObjCmd.FeatureCommand.ID
    StrDimDiameter = ObjCmd.FeatureCommand.MeasDiam
    MeasZ = ObjCmd.GetText(MEAS_Z,0)
    ElseIf (ObjCmd = FEATURE_CONTROL_FRAME) Then
      DimName = ObjCmd.ID
      DimMeasure = ObjCmd.GetFieldValue(LINE2_MEAS, 0)
      StrDimNominal = ObjCmd.GetFieldValue(LINE2_NOMINAL, 0)
      StrDimDev = ObjCmd.GetFieldValue(LINE2_DEV, 0)
      StrDimAct = StrDimNominal + StrDimDev 
    End If 
    
    If StrDimID = "CIR1- DIA UNDER GROOVE" Then MyReading1 = StrDimDiameter
    If DimName = "CIRC1 ROUNDNESS" Then MyReading2 = StrDimAct
    If StrDimID = "CIR2- DIA OF GROOVE" Then MyReading3 = StrDimDiameter
    If DimName = "CIR2- DIA OF GROOVE" Then MyReading4 = StrDimAct
    If StrDimID = "CIR3- DIA ABOVE GROOVE" Then MyReading5 = StrDimDiameter
    If DimName = "CIR3- DIA ABOVE GROOVE" Then MyReading6 = StrDimAct 
    Next 
    
    Dim dc As Object 
    Dim CollectionPlanID As Object
    Dim Username As String
    Dim Password As String
    
    'Open WinSPC and Collection Plan
    Set dc = CreateObject("WinSPC.DataCollectionAuto")
    dc.Visible = True
    dc.RunHeadless = False
    While dc.ReadyForLogin = "F"
    Wend
    dc.UserName = "1675 CMM"
    dc.Password = "1675"
    
    dc.CollectionPlanID = 8549
    	dc.TagIndex = 0
    	dc.TagValue = "P162610"
    	dc.TagIndex = 1
    	dc.TagValue = StrC1
    	dc.CurrentStep = 0
    	dc.Value = MyReading1
    	dc.CurrentStep = 1
    	dc.Value = MyReading2
    	dc.CurrentStep = 2
    	dc.Value = MyReading3
    	dc.CurrentStep = 3
    	dc.Value = MyReading4
    	dc.CurrentStep = 4
    	dc.Value = MyReading5
    	dc.CurrentStep = 5
    	dc.Value = MyReading6
    
      dc.CollectionPlanID = 0
      dc.UserName = " "
      Set dc = Nothing
    
    End Sub


    I found, and I can't remember where, a sample of what I used here somewhere on this forum. But once again, I can't seem to get it to work. Slight smile Any thoughts?
Children
No Data