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.
...then set the command object to either featurecommand or dimensioncommand (depending on the current commands type)
...then access the properties for that commandtype (featurecommand / dimensioncommand)
'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
StrDimDiameter = ObjCmd.GetText (MEAS_DIAM, 0)
MeasZ = ObjCmd.GetText (DIM_MEASURED, 0)
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
End If
If I run this like I have it above, then I don't get an error of an unrecognized DimensionCommand, but I still get the zero (I am guessing null) reading for the StrDimDiameter and MeasZ variables. To add in the feature commands, do I write it out like above and do an if ObjCmd.IsFeature then StrDimID = ObjDimCmd.ID, etc?
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
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
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.FeatureCommand.MeasHeight
End If
So, we are one step closer to getting this to work as desired. With this I now have diameters, and all measurements with an AX of M (had that before). So my guess is either I labeled the variables that get the measz variable included or that the measz variable has a feature command of measlength and not measheight.
I so appreciate your patience and all the help. I don't think I could have done this with out it. If I ever make it to Sweden, I will buy you a drink (coffee, soda, beer, whatever your preference). And you never know, since that is on my list of places to travel. My family is from there, many generations ago.
Thanks! No need for a beverage - just post
your code here so others can learn and benefit from it.
As a sidenote, I don't think the
MeasHeight will give you what you are looking for, though.
If you are looking for the measured Z-value, you should use this instead:
MeasZ = ObjCmd.GetText(MEAS_Z, 0)
The code can (probably will) error out if it encounter a feature command that does not have a
MeasDiam or
MeasHeight property,
but you'll probably notice that.
For some reason, this does not like it when I try to reply with the quote.
This is what I have learned:
MeasHeight returns a zero, but the MeasLenght returns a value, even if that is a false value. LOL. So there is some progress. To try to get the correct value in there, I even tried ObjCmd.FeatureCommand.DimMeasured, but that also returned a zero. So no surprises there.
At the same time, I have tried the bit of code that you suggested above, and I always get a return of zero.
So, is there anything else you would suggest? I will keep combing the help section and the book, but I am just taking shots in the dark.
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
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 MeasZ 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
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)
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 OD" Then MyReading4 = StrDimDiameter
If StrDimID = "CIR7- SNOUT ID" 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- ON STEP" Then MyReading9 = MeasZ
If StrDimID = "POINT2- ON STEP" Then MyReading10 = MeasZ
If StrDimID = "POINT3- ON STEP" Then MyReading11 = MeasZ
If StrDimID = "POINT4- ON STEP" Then MyReading12 = MeasZ
If StrDimID = "DIST1" Then MyReading13 = StrDimMeasure
If StrDimID = "CONC1" Then MyReading14 = StrDimMeasure
If StrDimID = "CONC2" Then MyReading15 = StrDimMeasure
If StrDimID = "PLANE5- TOP SURFACE OF BAFFLE" Then MyReading16 = MeasZ
Next
After this you place the MyReading# variables in the locations or the other program that you need the information in.
Why the MeasZ statement works when it is in the functioncommand block and not in the dimension command block or just after the for each objcmd in objcmds statement I don't know. It doesn't make sense to me. But we now have a functional way to export information from PCDMIS and place specific information in specific places.
The MEAS_Z statement works only when it encounters a command with a measured Z-value. Dimensions does not have this.
Also, the best BASIC reference I have used is a file called "automationobjects.chm". Easier to search, look and read than the occasional helpfile/PDF.
I can't seem to find it again though.
OK, now that I know that, it makes sense, but I didn't know before.
Now, that we have a working output method...I have a new task.
We have comment boxes in the PCDMIS program where the operator types in information such as clock number and job number. Would I get that data in a similar fashion to the MEAS_Z method?
The absolutely easiest thing would be to name those comment boxes to a specific name, say CLOCKNR and JOBNR.
You would then enumerate through the commands like you just did, but looking for a command of the comment type.
When a comment command has been found, you check the ObjCmd.ID if it matches CLOCKNR or JOBNR if it does, then you have found your comment/s.
Then fetch the comment input value, can't say off the top of my head (not at work now) how to do it, but it is feasible.