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.
  • Random questions (related to easier ways to learn the pcdmis type library). Do you have a acess to an offline seat of pc-dmis? If so, do you have access to vb6 or excel on that computer?


    I just got pcdmis installed as an offline on my computer this morning and I do have excel, but not vb6.
  • 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?
  • I just got pcdmis installed as an offline on my computer this morning and I do have excel, but not vb6.


    This is good. You can use VB in Excel to do all your development/debugging and more importantly, learn the pcdmis type library. You can set breakpoints, watches, step through your code line-by-line. While in debug mode, you can hover the mouse over a variable name and a tooltip will popup showing the contents. It's very powerful - I'd recommend picking up a book on VBA to help learn about the programming interface. Be sure to check out the Object Browser - you can set it to show only the pc-dmis objects and it's a great way to get a feel for the object hierarchy.

    You'll need to set a reference to the pc-dmis type library in your project (Tools/References - scroll WAY down to the "p's" and check the pc-dmis library)
    Add a module (Insert/Module) and paste your code into the module window (minus the form stuff)
    Lastly, change Object declarations to the 'real' object type - like this:
    Dim ObjApp as Application
    Dim ObjPart as PartProgram
    Dim ObjCmds as Commands
    Dim ObjCmd as Command
    Dim ObjDimCmd as DimensionCommand
    etc...
    


    Once you're all finished debugging and are "production-ready" you'll have to change the declarations back to "Object" for use as pc-dmis script.

    I really think that going this route will help you learn/understand the pc-dmis objects.
  • This is good. You can use VB in Excel to do all your development/debugging and more importantly, learn the pcdmis type library. You can set breakpoints, watches, step through your code line-by-line. While in debug mode, you can hover the mouse over a variable name and a tooltip will popup showing the contents. It's very powerful - I'd recommend picking up a book on VBA to help learn about the programming interface. Be sure to check out the Object Browser - you can set it to show only the pc-dmis objects and it's a great way to get a feel for the object hierarchy.

    You'll need to set a reference to the pc-dmis type library in your project (Tools/References - scroll WAY down to the "p's" and check the pc-dmis library)
    Add a module (Insert/Module) and paste your code into the module window (minus the form stuff)
    Lastly, change Object declarations to the 'real' object type - like this:
    Dim ObjApp as Application
    Dim ObjPart as PartProgram
    Dim ObjCmds as Commands
    Dim ObjCmd as Command
    Dim ObjDimCmd as DimensionCommand
    etc...
    


    Once you're all finished debugging and are "production-ready" you'll have to change the declarations back to "Object" for use as pc-dmis script.

    I really think that going this route will help you learn/understand the pc-dmis objects.


    Thank you, I will definitely do it. Anything to make this easier. Slight smile There are days that I just want to beat my head against the wall.

    Add: Thank you so much, I have just started playing with it, and already I can see how useful this is. I wish I knew about this earlier. Slight smile Fun, I now have new toys.
  • Thank you, I will definitely do it. Anything to make this easier. Slight smile There are days that I just want to beat my head against the wall.

    Add: Thank you so much, I have just started playing with it, and already I can see how useful this is. I wish I knew about this earlier. Slight smile Fun, I now have new toys.


    You're welcome. And enjoy the new toy!
  • Yikes - don't do this! You have nested loops that scan through the entire program. So, if the program has 10,000 commands, you are going to scan through the entire program 10,000 times. Use one technique or the other, not both.


    +1

    Good find, DJAMS!
  • Alright, I am still stuck in my holding pattern, but hope that you can answer my question.

    In the files for PCDMIS to Excel, the basic files there use a different format than here on the forum. For example: DIM_Fields(DIM_MeasIndx) = DIM_MEASURED and for FCF's example: LS_Fields(FULL_MeasIndx)= LINE1_MEAS

    Why are they using this format and we are using all sorts of different commands?
  • Alright, so to try to figure out some of my problems, I have been using this code to see what it actually gives me before I try to manipulate it.
    Dim App As Object
    Dim Part As Object
    Dim Cmds As Object
    Dim Cmd As Object
    Dim MyID As String
    Dim MyNom As String
    Dim MyDev As String
    Dim MyAx As String
    Dim Meas As String 
    Sub Main()
    Set App = CreateObject("PCDLRN.Application")
    Set Part = App.ActivePartProgram
    Set Cmds = Part.Commands
    
    For Each Cmd In Cmds
    If Cmd.IsDimension Then
    MyID = Cmd.DimensionCommand.ID
    Meas = Cmd.DimensionCommand.Measured
    MyAx = Cmd.DimensionCommand.AxisLetter
    MsgBox MyID & Meas & MyAx
    End If
    Next
    End Sub


    And on some of my variables, like Diameters and Planes, I have a 0 or a blank after the name then the measurement and the axis letter. So previously when I would import it, I would pull in that blank as the measurement hence giving me a zero in the space that I wanted the information in. Does anyone know what would cause that or maybe have an idea on how to compensate for it?

    And I probably should add that if you run the above script with just the ID varialbe, after every diameter or plane, there is a blank message box, so I am not sure that the blank is part of the ID, but it is for some reason giving it to me.
  • So, now I have learned that this is happening because there is an ID associated with a DIMENSION_START_LOCATION or a DIMENSION_START_TRUE_POSITION, but not with a DIMENSION_Z_LOCATION or DIMENSION_TRUE_Z_POSITION (for example). Has anyone created a loop that allows me to take the ID from the first command type and apply it to the second command type since that one doesn't have its own ID?

    And I thought I had one listed in this thread somewhere, but I can't find it. Although I know it looped everything back to the first ID available in the program, there was something there that may be able to be altered and used to actually function as desired.
  • So here is something that I tried, but so far it is not working.

    Dim App As Object
    Dim Part As Object
    Dim Cmds As Object
    Dim Cmd As Object
    Dim MyID As String
    Dim MyNom As String
    Dim MyDev As String
    Dim MyAx As String
    Dim Meas As String
    Dim NewID As String
    Dim n As Integer
    Dim c As String
    Sub Main()
    Set App = CreateObject("PCDLRN.Application")
    Set Part = App.ActivePartProgram
    Set Cmds = Part.Commands

    For Each Cmd In Cmds
    If Cmd.IsDimension Then
    MyID = Cmd.DimensionCommand.ID
    If MyID = " " Then
    n = Command.Count - 1
    MyID = Cmd.DimensionCommand.ID(n)
    End If
    MyNom = "ID ="
    MsgBox MyNom & MyID
    End If
    Next
    End Sub

    The thought behind this was that if I was scanning forward in the program it would be command.count +1 so backward would be command.count - 1 and that should give me the previous id, maybe.