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.
  • So here is my latest attempt at getting that measured plane's output out of the PCDMIS brain and into the WinSPC one.
    	'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
          set lngNumCmds = ObjCmds.Count
          
         
    
        	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 StrDimPlane As String
    	Dim MeasZ As String
    	Dim Clock As String
    	Dim Part As String
    	Dim DimMeas As Double
    	Dim MyComment 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
    	Dim MyReading7 As Double
    	Dim MyReading8 As Double
    	Dim MyReading9 As Double
    	Dim MyReading10 As Double
    	Dim MyReading11 As Double
    	Dim MyReading12 As Double
    	Dim MyReading13 As Double
    	Dim MyReading14 As Double
    	Dim MyReading15 As Double
    	Dim MyReading16 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.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
    StrDimID = ObjDimCmd.ID
    StrDimFeature = ObjDimCmd.Feat1
    StrDimType = ObjCmd.Type
    StrDimNominal = ObjDimCmd.Nominal
    StrDimUTol = ObjDimCmd.Plus
    StrDimLTol = ObjDimCmd.Minus
    StrDimMeasure = ObjDimCmd.Measured
    If (StrDimType = "DIMENSION_START_LOCATION" Or StrDimType = "DIMENSION_Z_LOCATION") Then 
    StrDimPlane=ObjCmd.GetText(DIM_MEASURED,0)
    End If
    ElseIf ObjCmd.IsFeature Then
    StrDimID = ObjCmd.FeatureCommand.ID
    StrDimDiameter = ObjCmd.FeatureCommand.MeasDiam
    MeasZ = ObjCmd.GetText(MEAS_Z,0)
    
    End If
    
    		     
        If StrDimID = "CIR2- OUTER CIRCLE ABOVE STEP" Then MyReading1 = StrDimDiameter
        If StrDimID = "ROUNDNESS CIRC2" Then MyReading2 = StrDimMeasure
        If StrDimID = "CIR3- RADIUS OF STEP ON OUTER EDGE" Then MyReading3 = StrDimDiameter
        If StrDimID = "CIR6- OUTER CIRCLE BELOW STEP" Then MyReading4 = StrDimDiameter
        If StrDimID = "ROUNDNESS CIRC6" Then MyReading5 = StrDimMeasure
        If StrDimID = "CONC1" Then MyReading6 = StrDimMeasure
        If StrDimID = "CONC2" Then MyReading7 = StrDimMeasure
        If StrDimID = "POINT 1Z" Then MyReading8 = StrDimMeasure
        If StrDimID = "POINT 2Z" Then MyReading9 = StrDimMeasure
        If StrDimID = "POINT 3Z" Then MyReading10 = StrDimMeasure
        If StrDimID = "POINT 4Z" Then MyReading11 = StrDimMeasure
        If StrDimID = "PLANE4 Z" Then MyReading12 = StrDimMeasure
        If StrDimID = "PLANE5- COMBINATION OF POINT 1 2 3 4 ON STEP" Then MyReading13 = MeasZ
        If StrDimID = "POINT5Z" Then MyReading14 = MeasZ
        If StrDimID = "POINT6Z" Then MyReading15 = MeasZ
        If StrDimID = "POINT7Z" Then MyReading16 = MeasZ
        If StrDimID = "POINT8Z" Then MyReading17 = MeasZ
    	Next
    

    from everything I have read, this should work, but of course so far most of the stuff I have tried should work. Smiley. So frustrated.
  • I have a general question. Are you trying to capture every dimension in the program for spc, or selected dimensions only?

    Will try to comment on the code later.
  • I have a general question. Are you trying to capture every dimension in the program for spc, or selected dimensions only?

    Will try to comment on the code later.

    It depends on the program for the part. There are many features in the program that I am not trying to capture, but there are also many that I am. And that of course depends upon the part specifications themselves and what is necessary to measure to ensure that it is functional.

    And I know that is pretty much a non answer, but it does really depend upon the part and then how the PCDMIS program is written. And to be honest, there isn't much consistency because there have been a lot of fingers in the PCDMIS pie. If there was consistency, this would be so much easier.
  • I am questioning something with the plane4 spec that I want to pull out. Now, If I pull it out as a feature and the MEAS_Z command, I get about 1/2 of the whole reading which should be .51. Now this part has a step in it that goes from the bottom to .25. The measurement I get out of PCDMIS is enough to add in that .25 step and come up with that .51 as a whole.

    So my question is, is this a common thing with PCDMIS, or is this dependent on how whoever programmed this part into the system?
  • I am questioning something with the plane4 spec that I want to pull out. Now, If I pull it out as a feature and the MEAS_Z command, I get about 1/2 of the whole reading which should be .51. Now this part has a step in it that goes from the bottom to .25. The measurement I get out of PCDMIS is enough to add in that .25 step and come up with that .51 as a whole.

    So my question is, is this a common thing with PCDMIS, or is this dependent on how whoever programmed this part into the system?


    I would not recommend getting the data from the feature. It could be measured in one alignment and reported in another. This could explain what you are seeing. Everything you need is available in the dimensioncmd object. (Provided you are not using xact gdt)
  • But if I use a dimension command object, I get zero. So, I have to use something.
  • But if I use a dimension command object, I get zero. So, I have to use something.


    That's because your code is incorrect.

    There are a lot of problems in the last code you posted, and I apologize, but I just can't spend the time required to explain/discuss. To do so accurately, I would have to do it from work (with pcdmis in front of me), and that is not what they pay me to do.

    You may want to look into QC-Calc RealTime. This is a package that absolutely excels at collecting data from all types of measuring equipment, and then exporting in formats that can be used by other softwares (including WinSPC). "From QC-Calc to WinSPC in 2 seconds flat" according to their website. It is very inexpensive as well. Using this tool, no scripting would be required, but very minor modifications to part programs would be necessary. (STATS/ON or XMLSTATS/ON depending on your pc-dmis version).

    http://www.prolinksoftware.com/specific.aspx?type=rt
    http://www.prolinksoftware.com/product_article.aspx?id=170

    Edit: one last thought - if you consider the path you are currently on, you are looking at having a custom import script for each program, or in the best case, a generic script with some sort of text files containing the mapping between pcdmis tolerances and WinSPC. This is all time consuming setup and maintenance over time. QC-Calc should be an easy sell to management.
  • I hope that this is the link, because either this site is the slowest loading site or the internet here is slower than molassas. Anyway, anyone taken this course and it is actually useful?
    http://hexagon.inquisiqr3.com/catalog/course.asp?id=23788&cid=6317

    A useful class is 60 bucks well spent, but one so general that I have the same information free is definitely not.
  • That's because your code is incorrect.

    There are a lot of problems in the last code you posted, and I apologize, but I just can't spend the time required to explain/discuss. To do so accurately, I would have to do it from work (with pcdmis in front of me), and that is not what they pay me to do.

    You may want to look into QC-Calc RealTime. This is a package that absolutely excels at collecting data from all types of measuring equipment, and then exporting in formats that can be used by other softwares (including WinSPC). "From QC-Calc to WinSPC in 2 seconds flat" according to their website. It is very inexpensive as well. Using this tool, no scripting would be required, but very minor modifications to part programs would be necessary. (STATS/ON or XMLSTATS/ON depending on your pc-dmis version).

    http://www.prolinksoftware.com/specific.aspx?type=rt
    http://www.prolinksoftware.com/product_article.aspx?id=170

    Edit: one last thought - if you consider the path you are currently on, you are looking at having a custom import script for each program, or in the best case, a generic script with some sort of text files containing the mapping between pcdmis tolerances and WinSPC. This is all time consuming setup and maintenance over time. QC-Calc should be an easy sell to management.


    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.
  • 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...