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.
  • Even using this method, I get a null reading. I used something like this Dim MeasZ As String then under my declaration it was MeasZ = ObjCmd.GetText (MEAS_Z, 0) In my If statments it went somthing like this

    If StrDimID = "POINT1" Then MyReading9 = StrDimMeasure

    And I have tried POINT1, POINT1 Z, AND POINT1- ON STEP as the variable. Nothing on any of those.

    I have done this for the MEAS_DIAM call out as well and still a null reading. That is using CIRC2 DIA, CIRC2, CIR2, and CIR2- OUTER CIRCLE ABOVE STEP as the variables as well.

    What am I doing wrong? I just can't think of anything else to do.

    Is this maybe because I am changing a String variable into a Double variable (StrDimMeasure is a String and MyReading# is a Double)? And why would it work on some and not others?
  • If the code on the previous page is what you are working with, then it seems you have forgotten this:

    If StrDimID.IsDimension Then
    Set ObjDimCmd = StrDimID.DimensionCommand


    You never cast the object type.

    Instead you are directly setting properties:

    If ObjCmd.IsDimension Then
    StrDimID = ObjCmd.DimensionCommand.ID


    You seem to do this for the featurecommand as well (else if).

    I don't know if this causes it to display null, but worth a try.
  • 'Declare variables
    Sub main
    Dim PartObj As Object
    Dim CPObj As Object
    Dim DCObj As Object
    Dim DBObj As Object
    Dim UserName As String
    Dim Password As String
    Dim sPart As String
    Dim sVar1 As String
    Dim sVar2 As String
    Dim sCollPlan As String
    Dim PartID As Long
    Dim Var1ID As Long
    Dim Var2ID As Long
    Dim CollPlanID As Long
    Dim Step1ID As Long
    Dim Step2ID As Long
    Dim CollectionPlanID As Object
    Dim dc As Object
    Dim ObjApp As Object

    'PCDMIS commands
    Dim ObjPP As Object
    Dim ObjCmds As Object
    Dim ObjCmd As Object
    Dim ObjPart 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 StrDimActual As String
    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.IsDimension Then
    StrDimDiameter = ObjCmd.GetText (MEAS_DIAM, 0)
    MeasZ = ObjCmd.GetText (MEAS_Z, 0)
    StrDimID = ObjCmd.DimensionCommand.ID
    StrDimFeature = ObjCmd.DimensionCommand.Feat1
    StrDimType = ObjCmd.DimensionCommand.AxisLetter
    StrDimNominal = ObjCmd.DimensionCommand.Nominal
    StrDimUTol = ObjCmd.DimensionCommand.Plus
    StrDimLTol = ObjCmd.DimensionCommand.Minus
    StrDimMeasure = ObjCmd.DimensionCommand.Measured
    End If

    So this is what I have for declarations, is the dimension command declared by Set ObjCmds = ObjPart.Commands? And doesn't the second section clarify what I wanted?
  • Try this:

    Dim ObjDimCmd as Object
    ...
    ...
    ...
    For Each ObjCmd In ObjCmds
    If ObjCmd.IsDimension Then
    
    Set ObjDimCmd = ObjCmd.DimensionCommand
    
    StrDimDiameter = ObjDimCmd.GetText (MEAS_DIAM, 0)
    MeasZ = ObjDimCmd.GetText (MEAS_Z, 0)
    StrDimID = ObjDimCmd.DimensionCommand.ID
    StrDimFeature = ObjDimCmd.DimensionCommand.Feat1
    StrDimType = ObjDimCmd.DimensionCommand.AxisLetter
    StrDimNominal = ObjDimCmd.DimensionCommand.Nominal
    StrDimUTol = ObjDimCmd.DimensionCommand.Plus
    StrDimLTol = ObjDimCmd.DimensionCommand.Minus
    StrDimMeasure = ObjDimCmd.DimensionCommand.Measured
    End If
  • Thank you. I did what you suggested and it comes back with a block not set or with block not set error. I thought that the Set ObjDimCmd = Obj.Cmd.DimensionCommand did that? Is that not right?

    Here is the code I currently have, maybe it is something that I did and I just can't figure it out.

    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





    'Declare variables
    Sub main
    Dim PartObj As Object
    Dim CPObj As Object
    Dim DCObj As Object
    Dim DBObj As Object
    Dim UserName As String
    Dim Password As String
    Dim sPart As String
    Dim sVar1 As String
    Dim sVar2 As String
    Dim sCollPlan As String
    Dim PartID As Long
    Dim Var1ID As Long
    Dim Var2ID As Long
    Dim CollPlanID As Long
    Dim Step1ID As Long
    Dim Step2ID As Long
    Dim CollectionPlanID As Object
    Dim dc As Object


    '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
    Set ObjDimCmd = ObjCmds.DimensionCommand


    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 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
    Set ObjDimCmd = ObjCmds.DimensionCommand
    StrDimDiameter = ObjDimCmd.GetText (MEAS_DIAM, 0)
    MeasZ = ObjDimCmd.GetText (DIM_MEASURED, 0)
    If ObjCmd.IsDimension Then
    StrDimID = ObjDimCmd.DimensionCommand.ID
    StrDimFeature = ObjDimCmd.DimensionCommand.Feat1
    StrDimType = ObjDimCmd.DimensionCommand.AxisLetter
    StrDimNominal = ObjDimCmd.DimensionCommand.Nominal
    StrDimUTol = ObjDimCmd.DimensionCommand.Plus
    StrDimLTol = ObjDimCmd.DimensionCommand.Minus
    StrDimMeasure = ObjDimCmd.DimensionCommand.Measured
    End If




    If StrDimID = "CIR2- OUTER CIRCLE ABOVE STEP" Then MyReading1 = StrDimDiameter
    If StrDimID = "CIR2 ROUNDNESS" Then MyReading2 = StrDimMeasure
    If StrDimID = "CIR3- RADIUS OF STEP OUTER EDGE" Then MyReading3 = StrDimDiameter
    If StrDimID = "CIR4- SNOUT ID" Then MyReading4 = StrDimDiameter
    If StrDimID = "CIR7- SNOUT OD" Then MyReading5 = StrDimDiameter
    If StrDimID = "CIR8- SMALL PORT INSIDE SNOUT" Then MyReading6 = StrDimDiameter
    If StrDimID = "CIR6- OUTER CIRCLE UNDER STEP" Then MyReading7 = StrDimDiameter
    If StrDimID = "CIRC6 ROUNDNESS" Then MyReading8 = StrDimMeasure
    If StrDimID = "POINT1 Z" Then MyReading9 = MeasZ
    If StrDimID = "POINT2 Z" Then MyReading10 = MeasZ
    If StrDimID = "POINT3 Z" Then MyReading11 = MeasZ
    If StrDimID = "POINT4 Z" Then MyReading12 = MeasZ
    If StrDimID = "DIST1" Then MyReading13 = StrDimMeasure
    If StrDimID = "CONC1" Then MyReading14 = StrDimMeasure
    If StrDimID = "CONC2" Then MyReading15 = StrDimMeasure
    If StrDimID = "PLANE5 Z" Then MyReading16 = MeasZ
    Next
  • For Each ObjCmd In ObjCmds
    
    [COLOR="#008000"]StrDimDiameter = ObjDimCmd.GetText (MEAS_DIAM, 0)
    MeasZ = ObjDimCmd.GetText (DIM_MEASURED, 0)[/COLOR]If ObjCmd.IsDimension Then
    
    [COLOR="#FF0000"]Set ObjDimCmd = ObjCmds.DimensionCommand[/COLOR]
    
    StrDimID = ObjDimCmd.DimensionCommand.ID
    StrDimFeature = ObjDimCmd.DimensionCommand.Feat1
    StrDimType = ObjDimCmd.DimensionCommand.AxisLetter
    StrDimNominal = ObjDimCmd.DimensionCommand.Nominal
    StrDimUTol = ObjDimCmd.DimensionCommand.Plus
    StrDimLTol = ObjDimCmd.DimensionCommand.Minus
    StrDimMeasure = ObjDimCmd.DimensionCommand.Measured
    End If


    You cast it as a DimensionCommand regardless of what command you have found.
    In the code above, I have moved the set below the IsDimension check.

    The green marked code also does the same, not all commands holds these properties.
    You want to pull the MEAS_DIAM and DIM_MEASURED regardless of what kind of command
    you are at (could be an alignment or comment or...). So, first you must iterate through
    all the commands and check what commandtype you have and based on that, grab whatever
    properties that specific commandtype holds. Check the code I sent you, there you will see
    how to check for the different types.
  • Thank you, that does make sense. I have changed it and am going to try it now and cross my fingers. Slight smile
  • OK, so I tried it and now it gives me an error that DimensionCommand is an unknown? What is it trying to tell me? Do I need to declare that? I have not seen anything that declares it before.
  • Note that in the code shown in vpt's post, you are accessing the OBjDimCmd object (green lines) before setting it (red line).

    You should use ObjCmd, not ObjDimCmd, in the green lines.
  • Thank you, I will change those. Would that cause the error in the lines below?