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.
  • Just reading through this whole post for my own interest and I was thinking the same thing about this needing to be done for each and every program. I really have no coding skills. But, if I were looking to make a generic program to grab all this information, the first thing I would do is set some ground rules for the CMM programmers. Tell them that for all dimensions that need to be tracked or added to spc, they must be the only dimensions named a specific way and only that way. This would make your job a little easier. They need to work with you, not cause more issues. I agree though with DJAMS that if it can be done much easier with a purchased software then do it that way. Forgive my intrusion.

    Not an intrusion, and it would be so much easier if there were rules to how these were programmed, and then there would be hope for a general script that could just be input into each one. At this point, I run across something new in each program that I open. So this has been an adventure. Slight smile
  • Here's a script for exporting all legacy dimensions (no FCF) in a program to a CSV formatted text file. Maybe it can give you some ideas?

    Note that some dimensions (LOCATION and POSITION) show up as multiple commands when looping through the program code:

    - a dimension START command (with the name, but no data)
    - one command for each axis that you dimension (X, Y, Z etc.) (with the data, but no name)
    - a dimension END command

    ' ================================================================
    ' The export file format:
    ' FeatType,FeatName,ValueID,Meas,Theo,Dev,-Tol,+Tol,OutTol,Comment
    ' ================================================================
    '
    ' Change history
    '
    ' 2005-11-16       PCDMIS bugs With True position:
    '
    '                  We can have OutTol <> 0 (very small number) even when Deviation = 0, also
    '                  Deviation can be a very small number (looks like conversion artifacts Single <--> Double)
    '
    '                  If Abs(Dev) < 0.00005 Set elDev = 0 Else Set elDev = Deviation
    '                  If Abs(OutTol) < 0.00005 Set elOutTol = 0 Else Set elOutTol = OutTol
    '
    ' 	           True Position can have Nominal = 0, Measured = 0 but Deviation <> 0
    '		   Solved by setting elAct = Nominal + elDev
    '
    '    Note: This script does *not* handle FCF dimensions
    ' ================================================================
    '
    Dim elType As String
    Dim elName As String
    Dim elValueType As String
    Dim elAct As Double
    Dim elNom As Double
    Dim elDev As Double
    Dim elMtol As Double
    Dim elPtol As Double
    Dim elOutTol As Double
    Dim elComment As String
    Dim elStarted As Integer
    
    ' ================================================================
    
    Sub ClearRecord
      elType = "type"
      elName = "name"
      elValueType = "valuetype"
      elAct = 0
      elNom = 0
      elDev = 0
      elMtol = 0
      elPtol = 0
      elOutTol = 0
      elComment = ""
    End Sub
    
    Sub PrintLine(FileNum%)
      If elStarted Then
        Print #FileNum, elType; ","; elName; ","; elValueType; ","; elAct; ","; elNom; ","; elDev; "," ; elMtol; ","; elPtol; ","; elOutTol; ","; elComment
        elStarted = 0
      End If
    End Sub
    
    Sub ExportAsCSV(FileName$)
    
      Dim DmisApp As Object
      Dim DmisPart As Object
      Dim DmisCommands As Object
      Dim DmisCommand As Object
      Dim DmisDimension As Object
    
      Dim ix As Integer
      Dim fNum As Integer
      Dim ID As String
      Dim State As Integer
      Dim DoOutput As Integer
    
      fNum = FreeFile
      Open FileName$ For Output As fNum
      ' 2005-11-17
      Print #fNum, "' FeatType,FeatName,ValueID,Meas,Theo,Dev,-Tol,+Tol,OutTol,Comment"
    	' ----------
      Set DmisApp = CreateObject("PCDLRN.Application")
      Set DmisPart = DmisApp.ActivePartProgram
      Set DmisCommands = DmisPart.Commands
    
      elStarted = 0
      State = 1
    
      For ix = 1 To DmisCommands.Count
    
        Set DmisCommand = DmisCommands(ix)
    
        If DmisCommand.IsDimension Then
    
          Set DmisDimension = DmisCommand.DimensionCommand
    
          Select Case State
    
            Case 1 '  Normal Case
    
                If (DmisDimension.OutputMode <> DIMOUTPUT_NONE) Then
                  DoOutput = 1
                Else
                  DoOutput = 0
                End If
    
                ID = DmisDimension.ID
    
                If (DmisCommand.Type = DIMENSION_TRUE_START_POSITION) Then
                  State = 2
                ElseIf (DmisCommand.Type = DIMENSION_START_LOCATION) Then
                  State = 3
                End If
    
                If (DoOutput = 1) And (State = 1) Then
    
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  Elseif DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00005) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00005) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elComment = ""
                  elStarted = 1
    
                End If
    
            Case 2 '  True Position
    
                If (DoOutput = 1) Then
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  Elseif DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00005) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00005) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elComment = ""
                  elStarted = 1
                End If
    
            Case 3 '  Location
    
                If (DoOutput = 1) Then
                  PrintLine(fNum)
                  ClearRecord
                  elType = DmisCommand.TypeDescription
                  elName = ID
                  ' 2005-11-17
                  If DmisDimension.AxisLetter = "D" Then
                      elValueType = "DIAM"
                  Elseif DmisDimension.AxisLetter = "R" Then
                      elValueType = "RAD"
                  Else
                    elValueType = DmisDimension.AxisLetter
                  End If
                  ' ---------
                  elNom = DmisDimension.Nominal
                  ' 2005-11-16
                  If (Abs(DmisDimension.Deviation) > 0.00005) Then
    	              elDev = DmisDimension.Deviation
                  Else
                  	elDev = 0
                  End If
                  elAct = DmisDimension.Nominal + elDev
                  ' ---------
                  elMtol = -DmisDimension.Minus
                  elPtol = DmisDimension.Plus
                  ' 2005-11-16
                  If (Abs(DmisDimension.OutTol) > 0.00005) Then
    	              elOutTol = DmisDimension.OutTol
                  Else
                  	elOutTol = 0
                  End If
                  ' ---------
                  elComment = ""
                  elStarted = 1
                End If
    
          End Select
    
          Set DmisDimension = Nothing
    
        ElseIf (DmisCommand.Type = DIMENSION_TRUE_END_POSITION) Then
    
          State = 1
    
        ElseIf (DmisCommand.Type = DIMENSION_END_LOCATION) Then
    
          State = 1
    
        End If
    
        Set DmisCommand = Nothing
    
      Next ix
    
      Set DmisCommands = Nothing
      Set DmisPart = Nothing
      Set DmisApp = Nothing
    
      PrintLine(fNum)
    
      Close #fNum
      Print "Klart"
    End Sub
    
    Sub Main(FileName$)
      'ExportAsCSV(FileName$) ' For deployment
      ExportAsCSV("EXPORT.TXT") ' For testing
    End Sub
    


    Adding FCF dimensions to this is non-trivial, and nearly doubles the script size...

    This may seem like a dumb question, but what are FCF dimensions?

    And I see what you mean by looping through. Thanks for posting this as some ideas to try and figure it into what I need.
  • There are 2 styles of reporting dimensions.

    legacy (for lack of a better description, traditional style, x,y,z, diameters etc) and FCF (feature control frame)
  • There are 2 styles of reporting dimensions.

    legacy (for lack of a better description, traditional style, x,y,z, diameters etc) and FCF (feature control frame)


    Thanks.
  • if I were looking to make a generic program to grab all this information, the first thing I would do is set some ground rules for the CMM programmers. Tell them that for all dimensions that need to be tracked or added to spc, they must be the only dimensions named a specific way and only that way.


    No need to complicate things and reinvent existing wheels. Every dimension has a 'print flag' which can be NONE, REPORT, STATS, BOTH. That's the "DmisDimension.OutputMode" that my script above checks (although that script writes to a file everything which doesn't have the flag "NONE", no discrimination between REPORT/STATS/BOTH).

    If/when the programs have this flag correctly set for all dimensions it's easy. Those that are flagged STATS or BOTH are the ones that should be sent on, irrespective of their name.

    The SPC system may place restrictions on names, too, but that shouldn't concern this script.

    (Unless I have completely misunderstood something)

    Edit: Fixed spelling
  • No need to complicate things and reinvent exiting wheels. Every dimension has a 'print flag' which can be NONE, REPORT, STATS, BOTH. That's the "DmisDimension.OutputMode" that my script above checks (although that script writes to a file everything which doesn't have the flag "NONE", no discrimination between REPORT/STATS/BOTH).

    If/when the programs have this flag correctly set for all dimensions it's easy. Those that are flagged STATS or BOTH are the ones that should be sent on, irrespective of their name.

    The SPC system may place restrictions on names, too, but that shouldn't concern this script.

    (Unless I have completely misunderstood something)

    The only restriction on names that I am aware of is that they can't be more than 50 characters long, but the varibles that the information is going into are already prenamed and in existing collection plans. Thanks so much for the help.
  • Still been working on this and have done a lot, but now I have a syntax error that I don't understand. According to the compiler, it is in the block after the end select. I am sure that I am missing something obvious, but I just don't see it right now.
    Sub PCDinfo
    'Gather Information from part program
    Set ObjApp = CreateObject ("PCDLRN.Application")
    Set ObjPart = ObjApp.ActivePartProgram
    Set ObjCmds = ObjPart.Commands
    
    
    State = 1
    
    For ix = 1 To ObjCmds.Count
    Set ObjCmd = ObjCmds(ix)
    
    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.IsComment Then
        If ObjCmd.CommentCommand.CommentType = PCD_COMMENT_INPUT Then 
          If ObjCmd.ID = "C2" Then
            StrC2 = ObjCmd.CommentCommand.Input
          End If
        End If
      End If
    
    If ObjCmd.IsDimension Then
    	Set ObjDimCmd = ObjCmd.DimensionCommand
    	
    	Select Case State
    	
    	Case 1 'Normal case
    		If (ObjDimCmd.OutputMOde <> DIMOUTPUT_NONE) Then
    		    DoOutPut = 1
    		Else 
    		    DoOutPut = 0
    		End If
    		
    		StrDimID = ObjDimCmd.ID
    
    		If (ObjDimCmd.Type = DIMENSION_TRUE_START_POSITION) Then
    		   State = 2
    		ElseIf (ObjDimCmd.Type = DIMENSION_START_LOCATION) Then
    		   State = 3
    		End If
    
    		If (DoOutPut = 1) and (State = 1) Then
    		StrDimType = ObjDimCmd.TypeDescription
    		StrDimValueType = ObjDimCmd.AxisLetter
    		End If
    		StrDimNom = ObjDimCmd.Nominal
    		StrDimDev = ObjDimCmd.Deviation
    		StrDimAct = StrDimNom + StrDimDev
    		
    		
    
    	Case 2 'True Position
    		If (DoOutPut = 1) Then
    		StrDimID = ObjDimCmd.ID
    		StrDimType = ObjDimCmd.TypeDescription
    		StrDimValueType = ObjDimCmd.AxisLetter
    		End If
    		StrDimNom = ObjDimCmd.Nominal
    		StrDimDev = ObjDimCmd.Deviation
    		StrDimAct = StrDimNom + StrDimDev
    		
    		
    
    	Case 3 'Location
    		If (DoOutPut = 1) Then
    		StrDimID = ObjDimCmd.ID
    		StrDimType = ObjDimCmd.TypeDescription
    		StrDimValueType = ObjDimCmd.AxisLetter
    		End If
    		StrDimNom = ObjDimCmd.Nominal
    		StrDimDev = ObjDimCmd.Deviation
    		StrDimAct = StrDimNom + StrDimDev
    		
    		
    	End Select
    
    	If (ObjDimCmd.Type = DIMENSION_TRUE_END_POSITION) Then	
    	  State = 1
    	ElseIf (ObjDimCmd.Type = DIMENSION_END_LOCATION) Then
    	  State = 1
    	End If
    	
    
    	If (StrDimID = "CIRC2 DIA") Then 
    	MyReading1 = StrDimAct
    	End If
    	If (StrDimID = "ROUNDNESS CIRC2") Then 
    	MyReading2 = StrDimAct
    	End If
    	If (StrDimID = "CIRC3 DIA") Then 
    	MyReading3 = StrDimAct
    	End If
    	If (StrDimID = "CIRC6 DIA") Then 
    	MyReading4 = StrDimAct
    	End If
    	If (StrDimID = "ROUNDNESS CIRC6") Then 
    	MyReading5 = StrDimAct
    	End If
    	If (StrDimID = "CONC1") Then 
    	MyReading6 = StrDimAct
    	End If
    	If (StrDimID = "CONC2") Then 
    	MyReading7 = StrDimAct
    	If (StrDimID = "POINT 1Z") Then 
    	MyReading8 = StrDimAct
    	End If
    	If (StrDimID = "POINT 2Z") Then 
    	MyReading9 = StrDimAct
    	End If
    	If (StrDimID = "POINT 3Z") Then 
    	MyReading10 = StrDimAct
    	End If
    	If (StrDimID = "POINT 3Z") Then 
    	MyReading10 = StrDimAct
    	End If
    	If (StrDimID = "PLANE4 Z") Then 
    	MyReading12 = StrDimAct
    	End If
    	If (StrDimID = "PLANE5 Z") Then 
    	MyReading13 = StrDimAct
    	End If
    	If (StrDimID = "POINT5Z") Then 
    	MyReading14 = StrDimAct
    	End If
    	If (StrDimID = "POINT6Z") Then 
    	MyReading15 = StrDimAct
    	End If
    	If (StrDimID = "POINT7Z") Then 
    	MyReading16 = StrDimAct
    	End If
    	If (StrDimID = "POINT8Z") Then 
    	MyReading17 = StrDimAct
    	End If
    
    Next


    Thanks for the help.
  • If (ObjDimCmd.Type = DIMENSION_TRUE_END_POSITION) Then


    Maybe?

    Try
    If (ObjDimCmd.Type = DIMENSION_END_TRUE_POSITION) Then
  • If (ObjDimCmd.Type = DIMENSION_TRUE_END_POSITION) Then


    Maybe?

    Try
    If (ObjDimCmd.Type = DIMENSION_END_TRUE_POSITION) Then

    Thank you, I will try this, and it is probably something rediculously simple as this. Slight smile Everything starts looking the same when you look at it long enough.
  • If (ObjDimCmd.Type = DIMENSION_TRUE_END_POSITION) Then


    Maybe?

    Try
    If (ObjDimCmd.Type = DIMENSION_END_TRUE_POSITION) Then


    Thank you, that did get rid of the error there, but now I get one at the end of the sub. So here is the rest of the code. Again, I just am not sure why that error is there. As near as I can figure it thinks that it should do something else, but what?

    '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 = 8533
    	dc.TagIndex = 0
    	dc.TagValue = "P566290"
    	dc.TagIndex = 1
    	dc.TagValue = StrC2
    	dc.TagIndex = 2
    	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.CurrentStep = 6
    	dc.Value = MyReading7
    	dc.CurrentStep = 7
    	dc.Value = MyReading8
    	dc.CurrentStep = 8
    	dc.Value = MyReading9
    	dc.CurrentStep = 9
    	dc.Value = MyReading10
    	dc.CurrentStep = 10
    	dc.Value = MyReading11
    	dc.CurrentStep = 11
    	dc.Value = MyReading12
    	dc.CurrentStep = 12
    	dc.Value = MyReading13
    	dc.CurrentStep = 13
    	dc.Value = MyReading14
    	dc.CurrentStep = 14
    	dc.Value = MyReading15
    	dc.CurrentStep = 15
    	dc.Value = MyReading16
    	dc.CurrentStep = 16
    	dc.Value = MyReading17
    
    	dc.CollectionPlanID = 0
    	dc.UserName = ""
    	set dc = Nothing
    End Sub

    And the Next command between the variable If statements for the MyReading for the output is gone. It kept giving me an error if it was there.

    Any thoughts?