I want to use the code to automatically import DMS file allows CMM automatic measurement, but a lot of problems when running:
1, I created a program, perform VB code automatic import DMS file after the probe into a Test 1, the tip becomes a blank. The DMS imported content can not recognize the probe calls; (Picture 1)
2, when manually import DMS file have dialog box, there is the option , or how to use VB6 code to control these options; (Picture 2)
3, I create a new program, when automate the import DMS, PC-DMIS pop error "Could not Open File". How to solve it. (Picture 3)
4, how to use VB6 code to start and create a new program file on PC-DMIS CAD 4.2;
5, the attachment is my code and materials, to help me check what went wrong, thank you! I use the version of the PC-DMIS CAD 4.2. I was inexperienced, I hope there is code directly advise. Thank you!
Test Note that you need to Name.txt files on the D drive, dms folder is also placed in the D drive.



VB code
Dim DmisApp As PCDLRN.Application
Dim DmisPart As PCDLRN.PartProgram
Dim DmisParts As PCDLRN.PartPrograms
Dim DmisCmd As PCDLRN.Command
Dim DmisCmds As PCDLRN.Commands
Dim DmisProbes As PCDLRN.Probes
Dim DmisProbe As PCDLRN.probe
Dim DmisTips As PCDLRN.Tips
Dim DmisTip As PCDLRN.Tip
Sub part1()
Set DmisApp = CreateObject("PCDLRN.Application")
If DmisApp Is Nothing Then
Exit Sub
End If
Set DmisPart = DmisApp.ActivePartProgram
Set DmisCmds = DmisPart.Commands
CommandCount = DmisCmds.Count
Set DmisCmd = DmisCmds.Item(CommandCount)
DmisCmds.InsertionPointAfter DmisCmd
Set DmisCmd = DmisCmds.Add(GET_PROBE_DATA, True)
retval = DmisCmd.PutText("D2-95", FILE_NAME, 0)
Set DmisCommand = DmisCmds.Add(SET_ACTIVE_TIP, True)
retval = DmisCmd.PutText("T1A0B0", ID, 0)
retval = DmisCmd.PutText("0", TIP_I, 0)
retval = DmisCmd.PutText("0", TIP_J, 0)
retval = DmisCmd.PutText("1", TIP_K, 0)
retval = DmisCmd.PutText("0", THEO_ANGLE, 0)
Dim ELfileName As String
Dim fn As Integer
fn = FreeFile
Open "D:\Name.txt" For Input As fn
Do While Not EOF(fn)
Input #fn, ELfileName
DoEvents
Loop
Close fn
Set DmisCmds = DmisPart.Commands
Dim DmsFlieName As String
Dim ma, mb As String
mb = InStr(ELfileName, "-")
ma = Left(ELfileName, mb - 1)
DmsFlieName = "D:\dms\" & ELfileName & ".dms"
'(((DmsFlieName = "E:\cmm3\CMM_PROG\" & ma & "\" & ELfileName & "." & "dms")))
' MsgBox DmsFlieName
If Dir(DmsFlieName) <> "" Then
Else
MsgBox "电极DMS程序没有找到", vbRetryCancel, "DMS导入"
End If
DmisPart.Import ("D:\dms\" & ELfileName & ".dms")
'((( DmisPart.Import ("E:\cmm3\CMM_PROG\" & ma & "\" & ELfileName & "." & "dms") )))
DmisPart.AsyncExecute
Dim featName As String
Dim measX, measY, measZ, theoX, theoY, theoZ, I, J, K, T As Double
Dim devX, devY, devZ As Double
For Each DmisCmd In DmisCmds
If DmisCmd.IsDCCFeature Then
featName = DmisCmd.ID
measX = DmisCmd.GetText(MEAS_X, 0)
measY = DmisCmd.GetText(MEAS_Y, 0)
measZ = DmisCmd.GetText(MEAS_Z, 0)
theoX = DmisCmd.GetText(THEO_X, 0)
theoY = DmisCmd.GetText(THEO_Y, 0)
theoZ = DmisCmd.GetText(THEO_Z, 0)
I = DmisCmd.GetText(TARG_I, 0)
J = DmisCmd.GetText(TARG_J, 0)
K = DmisCmd.GetText(TARG_K, 0)
devX = Round(measX - theoX, 3)
devY = Round(measY - theoY, 3)
devZ = Round(measZ - theoZ, 3)
T = Round(devX * I + devY * J + devZ * K, 3)
Dim prgfile As String
prgfile = "D:\结果输出\" & ELfileName & ".txt"
Open prgfile For Append As fn
Print #fn, "位置" & featName & " AX: X," & measX & ", " & theoX & ", " & devX & ", " & vbCrLf & _
"位置" & featName & " AX: Y," & measY & ", " & theoY & ", " & devY & ", " & vbCrLf & _
"位置" & featName & " AX: Z," & measZ & ", " & theoZ & ", " & devZ & ", " & vbCrLf & _
"位置" & featName & " AX: T," & " , , " & T
Close fn
End If
Next
End Sub
Private Sub Command1_Click()
part1
DmisPart.RefreshPart
End Sub
dms
$$DMISLAYER
DMISMN/'D',3.00
SNSET/APPRCH, 2.0
SNSET/RETRCT, 2.0
SNSET/SEARCH, 2.0
SNSET/DEPTH, 0.0
SNSET/CLRSRF, 2.0
SNSLCT/SA(T1A0B0)
DID(a3_FILE) = DEVICE/STOR, '3R SYSTEM B:a3'
OPEN/DID(a3_FILE), PCS
RECALL/DA(a3), DID(a3_FILE)
CLOSE/DID(a3_FILE)
DMESW/COMAND, '安全平面/Z 正, 500.0, Z 正, 500.0, 开'
WKPLAN/XYPLAN
TEXT/OPER,'Are you Ready'
MODE/AUTO, PROG, MAN
FEDRAT/POSVEL,PCENT,0.2
GOTO/41.3204,12.5291,63.9600
F(PT1)=FEAT/POINT, CART, 41.3204,12.5291,58.9600,0.0000,0.0000,1.0000
MEAS/POINT, F(PT1), 1
PTMEAS/CART, 41.3204,12.5291,58.9600,0.0000,0.0000,1.0000
ENDMES
OUTPUT/FA(PT1)
MODE/AUTO, PROG, MAN
FEDRAT/POSVEL,PCENT,1.0
F(PT2)=FEAT/POINT, CART, 41.2925,8.6769,58.3370,0.0000,-0.6088,0.7934
MEAS/POINT, F(PT2), 1
PTMEAS/CART, 41.2925,8.6769,58.3370,0.0000,-0.6088,0.7934
ENDMES
OUTPUT/FA(PT2)
MODE/AUTO, PROG, MAN
F(PT3)=FEAT/POINT, CART, 41.2435,6.8524,53.9350,-0.0000,-0.9659,0.2588
MEAS/POINT, F(PT3), 1
PTMEAS/CART, 41.2435,6.8524,53.9350,-0.0000,-0.9659,0.2588
ENDMES
OUTPUT/FA(PT3)
MODE/AUTO, PROG, MAN
F(PT4)=FEAT/POINT, CART, 41.2239,5.0279,49.5330,-0.0000,-0.6088,0.7934
MEAS/POINT, F(PT4), 1
PTMEAS/CART, 41.2239,5.0279,49.5330,-0.0000,-0.6088,0.7934
ENDMES
OUTPUT/FA(PT4)
MODE/AUTO, PROG, MAN
F(PT5)=FEAT/POINT, CART, 41.2327,-3.0000,48.9100,-0.0000,-0.0000,1.0000
MEAS/POINT, F(PT5), 1
PTMEAS/CART, 41.2327,-3.0000,48.9100,-0.0000,-0.0000,1.0000
ENDMES
OUTPUT/FA(PT5)
GOTO/INCR, 16.0500, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/37.7213,-5.9243,63.9600
F(PT6)=FEAT/POINT, CART, 39.7209,-5.9243,46.3600,-0.9998,-0.0000,0.0175
MEAS/POINT, F(PT6), 1
PTMEAS/CART, 39.7209,-5.9243,46.3600,-0.9998,-0.0000,0.0175
ENDMES
OUTPUT/FA(PT6)
GOTO/INCR, 18.6000, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/41.2239,-9.8103,63.9600
F(PT7)=FEAT/POINT, CART, 41.2239,-11.0279,49.5330,-0.0000,0.6088,0.7934
MEAS/POINT, F(PT7), 1
PTMEAS/CART, 41.2239,-11.0279,49.5330,-0.0000,0.6088,0.7934
ENDMES
OUTPUT/FA(PT7)
MODE/AUTO, PROG, MAN
F(PT8)=FEAT/POINT, CART, 41.2435,-12.8524,53.9350,-0.0000,0.9659,0.2588
MEAS/POINT, F(PT8), 1
PTMEAS/CART, 41.2435,-12.8524,53.9350,-0.0000,0.9659,0.2588
ENDMES
OUTPUT/FA(PT8)
GOTO/INCR, 11.0250, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/41.3204,-18.5291,63.9600
F(PT9)=FEAT/POINT, CART, 41.3204,-18.5291,58.9600,0.0000,0.0000,1.0000
MEAS/POINT, F(PT9), 1
PTMEAS/CART, 41.3204,-18.5291,58.9600,0.0000,0.0000,1.0000
ENDMES
OUTPUT/FA(PT9)
MODE/AUTO, PROG, MAN
F(PT10)=FEAT/POINT, CART, -38.5204,-18.5291,58.9600,0.0000,0.0000,1.0000
MEAS/POINT, F(PT10), 1
PTMEAS/CART, -38.5204,-18.5291,58.9600,0.0000,0.0000,1.0000
ENDMES
OUTPUT/FA(PT10)
GOTO/INCR, 6.0000, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/-38.4435,-10.9206,63.9600
F(PT11)=FEAT/POINT, CART, -38.4435,-12.8524,53.9350,-0.0000,0.9659,0.2588
MEAS/POINT, F(PT11), 1
PTMEAS/CART, -38.4435,-12.8524,53.9350,-0.0000,0.9659,0.2588
ENDMES
OUTPUT/FA(PT11)
MODE/AUTO, PROG, MAN
F(PT12)=FEAT/POINT, CART, -38.4239,-11.0279,49.5330,-0.0000,0.6088,0.7934
MEAS/POINT, F(PT12), 1
PTMEAS/CART, -38.4239,-11.0279,49.5330,-0.0000,0.6088,0.7934
ENDMES
OUTPUT/FA(PT12)
MODE/AUTO, PROG, MAN
F(PT13)=FEAT/POINT, CART, -38.4327,-3.0000,48.9100,-0.0000,-0.0000,1.0000
MEAS/POINT, F(PT13), 1
PTMEAS/CART, -38.4327,-3.0000,48.9100,-0.0000,-0.0000,1.0000
ENDMES
OUTPUT/FA(PT13)
GOTO/INCR, 16.0500, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/-34.9213,-0.0757,63.9600
F(PT14)=FEAT/POINT, CART, -36.9209,-0.0757,46.3600,0.9998,-0.0000,0.0175
MEAS/POINT, F(PT14), 1
PTMEAS/CART, -36.9209,-0.0757,46.3600,0.9998,-0.0000,0.0175
ENDMES
OUTPUT/FA(PT14)
GOTO/INCR, 18.6000, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/-38.4239,3.8103,63.9600
F(PT15)=FEAT/POINT, CART, -38.4239,5.0279,49.5330,-0.0000,-0.6088,0.7934
MEAS/POINT, F(PT15), 1
PTMEAS/CART, -38.4239,5.0279,49.5330,-0.0000,-0.6088,0.7934
ENDMES
OUTPUT/FA(PT15)
MODE/AUTO, PROG, MAN
F(PT16)=FEAT/POINT, CART, -38.4435,6.8524,53.9350,-0.0000,-0.9659,0.2588
MEAS/POINT, F(PT16), 1
PTMEAS/CART, -38.4435,6.8524,53.9350,-0.0000,-0.9659,0.2588
ENDMES
OUTPUT/FA(PT16)
GOTO/INCR, 11.0250, 0, 0, 1
MODE/AUTO, PROG, MAN
GOTO/-38.5204,12.5291,63.9600
F(PT17)=FEAT/POINT, CART, -38.5204,12.5291,58.9600,0.0000,0.0000,1.0000
MEAS/POINT, F(PT17), 1
PTMEAS/CART, -38.5204,12.5291,58.9600,0.0000,0.0000,1.0000
ENDMES
OUTPUT/FA(PT17)
GOTO/INCR, 6.0000, 0, 0, 1
GOTO/INCR, 70, 0, 0, 1
GOTO/INCR, 205, 0.577, 0.577, 0.577
ENDFIL