hexagon logo

Script to pull nominal and tols

I am attempting to have a script create a csv file for later use. What I would like is to gain the output_id, and for each respective axis it reports obtain the nom, ptol, mtol.
Currently I have modified some script and what I found is when I have a location/tp output the output_id appears with 0,0,0. Then in the next 'instance' the output_id = 0 and I get the appropriate nom, ptol, mtol value. Almost every other output style (in legacy) will pull the output_id, nom, ptol, mtol without a gap. Here is the code I am using so far:

Dim Axs As String, Nom As String, Oid As String, Uptol As String, Lowtol As String

Part_S = ""
i = 0
For Each Cmd In DmisCommands
If Cmd.IsDimension Then
k = k + 1
Set dcmd = Cmd.dimensioncommand
Ax_s = Cmd.TypeDescription
O_id = CStr(dcmd.ID)
No_m = CStr(dcmd.Nominal)
Up_tol = CStr(dcmd.Plus)
Low_tol = CStr(dcmd.Minus)

If Ax_s = "Datum Definition" Then
GoTo Skip
End If

If Ax_s = "Dimension Position" Or Ax_s = "Dimension Location" Then
O_id_h = O_id
Mult_i = "True"
i = i+1
Else
Mult_i = "False"
i = 0
End If

If Mult_i = "False" Then
If k = 1 Then
Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
End If
If k > 1 Then
Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
End If
End If
If Mult_i = "True" Then
If k = 1 Then
Part_S = O_id_h
End If
If k > 1 Then
Part_S = Part_S & "," & O_id_h & "," & No_m & "," & Up_tol & "," & Low_tol
End If
End If

Skip:
End If
Next Cmd
Part_S = SerNum & "," & Part_S

Private Sub MakeStatusFile()
Open INFOPath For Append As #1
Print #1, Part_S
Close #1
Exit Sub
End Sub


For example the following output will appear as "LOC_FORM",0,0,0,,"5.4756","4.0000","0.002",,"0","5.0000","0":
DIM LOC_FORM= LOCATION OF CIRCLE CIR_A1 UNITS=IN ,$
GRAPH=OFF TEXT=OFF MULT=10.00 OUTPUT=BOTH HALF ANGLE=NO
AX MEAS NOMINAL +TOL -TOL DEV OUTTOL
D 5.47560 5.47560 4.00000 0.00200 0.00000 0.00000 #---
RN 0.00000 0.00000 5.00000 0.00000 0.00000 0.00000 #---
END OF DIMENSION LOC_FORM


I'd like it to be: "LOC_FORM","5.4756","4.0000","0.002","LOC_FORM","0","5.0000","0"
TYIA
  • Hi,

    do you want only legacy Dimension commands or xact too ?

    i think its better you pull out data with pcDmisCommand.getText()

    i think your problem is that the ID field is empty
    in "Dimension Location" like "D", "X" and "RN" and so on, the field for "ID" is empty
    but iam not sure, if this is your problem
  • Currently yes, I'm only asking to obtain legacy, though I would be up to find the naming conventions for the Geotol outputs as well.
    The ID field does wind up empty, and that is what I am asking to correct.
  • Hi,

    i think this should work " ExtractDim.Txt "

    you can change the output pattern to your preferences

    Sub Main()
    ' --- Error ------------------------------------------------------------------------------
    On Error GoTo ErrorHandler
    
    
    ' --- Dim something ------------------------------------------------------------------------------
    Dim retval
    Dim vpcDMIS_App, vpcDMIS_Part, vpcDMIS_Cmds, vpcDMIS_Cmd As Object
    
    Set vpcDMIS_App = CreateObject("PCDLRN.Application")
    Set vpcDMIS_Part = vpcDMIS_App.ActivePartProgram
    Set vpcDMIS_Cmds = vpcDMIS_Part.Commands
    Set vpcDMIS_Cmd = Nothing
    
    Dim bStart As Boolean
    Dim iLoopIndex, iFound As Integer
    Dim sID, sOutput, INFOPath As String
    
    
    
    ' --- save part ------------------------------------------------------------------------------------
    vpcDMIS_Part.Save
    
    
    
    
    ' --- search Commands ------------------------------------------------------------------------------
    iLoopIndex = 0
    iFound = 0
    For Each vpcDMIS_Cmd In vpcDMIS_Cmds
    iLoopIndex = iLoopIndex + 1
    
    
    ' *** user info **************
    vpcDMIS_App.StatusBar = "Script: Cycling through commands. Current command: " & iLoopIndex
    Set vpcDMIS_Cmd = vpcDMIS_Cmds.Item(iLoopIndex)
    
    
    ' *** test for Marked **************
    If vpcDMIS_Cmd.Marked = False Then ' ignore all Marked commands
    GoTo NextLoop
    End If
    
    
    ' *** find DIMENSION_START_LOCATION **************
    If vpcDMIS_Cmd.Type = DIMENSION_START_LOCATION Then
    bStart = True
    sID = vpcDMIS_Cmd.GetText(ID, 0)
    
    GoTo NextLoop
    End If
    
    
    ' *** find DIMENSION_LOCATION **************
    'sOutput = "ID; AX; NOMINAL; +Tol; -Tol; DEV; OUTTOL"
    If bStart And vpcDMIS_Cmd.IsDimension Then
    iFound = iFound + 1
    
    sOutput = sOutput & sID & ";"
    sOutput = sOutput & vpcDMIS_Cmd.GetText(Axis, 0) & ";"
    sOutput = sOutput & vpcDMIS_Cmd.GetText(Nominal, 0) & ";"
    sOutput = sOutput & vpcDMIS_Cmd.GetText(F_PLUS_TOL, 0) & ";"
    sOutput = sOutput & vpcDMIS_Cmd.GetText(F_MINUS_TOL, 0) & ";"
    sOutput = sOutput & vpcDMIS_Cmd.GetText(DIM_DEVIATION, 0) & ";"
    sOutput = sOutput & vpcDMIS_Cmd.GetText(DIM_OUTTOL, 0)
    sOutput = sOutput & Chr(13) & Chr(10)
    GoTo NextLoop
    End If
    
    
    ' *** find DIMENSION_END_LOCATION **************
    If vpcDMIS_Cmd.Type = DIMENSION_START_LOCATION Then
    bStart = False
    sID = ""
    GoTo NextLoop
    End If
    
    
    NextLoop:
    Next vpcDMIS_Cmd
    
    
    ' --- print output --------------------------------------------------------------------------------
    If sOutput <> "" Then
    sOutput = "ID; AX; NOMINAL; +Tol; -Tol; DEV; OUTTOL" & Chr(13) & Chr(10) & sOutput
    
    MsgBox sOutput
    
    'Open INFOPath For Append As #1
    'Print #1, sOutput
    'Close #1
    End If
    
    
    ' --- end -----------------------------------------------------------------------------------------
    ErrorHandler:
    vpcDMIS_App.StatusBar = "Script: " & CStr(iLoopIndex) & " searched commands | Found Dimension: " & CStr(iFound)
    
    
    ' --- free something ------------------------------------------------------------------------------
    Set vpcDMIS_Cmd = Nothing
    Set vpcDMIS_Cmds = Nothing
    Set vpcDMIS_Part = Nothing
    Set vpcDMIS_App = Nothing
    End Sub
    
    
  • your O_id is set to "" if it's a "Dimension Location"
    you need to set it only in start
    i think

    If Cmd.IsDimension Then
    K = K + 1
    Set dcmd = Cmd.DimensionCommand
    Ax_s = Cmd.TypeDescription
    If Cmd.Type = DIMENSION_START_LOCATION Then
    O_id = CStr(dcmd.ID)
    End If
    No_m = CStr(dcmd.Nominal)
    Up_tol = CStr(dcmd.Plus)
    Low_tol = CStr(dcmd.Minus)

    If Ax_s = "Datum Definition" Then
    GoTo Skip
    End If
  • Henniger123, Thank you for your input and for the provided example of what you use.
    This is what I came up with and it is now working without missing information:

    Private Sub PCDMIS_TO_INFO()
    
    Dim Ax_s As String, No_m As String, O_id As String, Up_tol As String, Low_tol As String
    
    Part_S = ""
    k = 0
    For Each Cmd In DmisCommands
    If Cmd.IsDimension Then
    Set dcmd = Cmd.dimensioncommand
    Ax_s = Cmd.TypeDescription
    O_id = CStr(dcmd.ID)
    No_m = CStr(dcmd.Nominal)
    Up_tol = CStr(dcmd.Plus)
    Low_tol = CStr(dcmd.Minus)
    
    If Ax_s = "Datum Definition" Or Ax_s = "Geometric Tolerance Command" Then
    GoTo Skip
    End If
    
    If Part_S = "" Then
    If Ax_s = "Dimension Position" Or Ax_s = "Dimension Location" Then
    'Part_S = O_id
    O_id_h = O_id
    End If
    If O_id = "" Then O_id = O_id_h
    If Ax_s = "X Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Y Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Z Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "PR Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "PA Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "D Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "R Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "T Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Roundness Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "A Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "A/2 Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "L Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "H Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Position X Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Y Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Z Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position PR Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position PA Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position DF Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Diam Location" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Roundness" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Dimension 2d Distance" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension 3d Distance" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension 2d Angle" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension 3d Angle" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Dimension Concentricity" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Coaxiality" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Circularity" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Flatness" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Perpendicularity" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Parallelism" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Total Runout" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Circular Runout" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Dimension Profile of Surface" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Profile of Line" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Angularity" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Symmetry" Then
    Part_S = O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    End If
    
    If Not Part_S = "" Then
    If Ax_s = "Dimension Position" Or Ax_s = "Dimension Location" Then
    'Part_S = O_id
    O_id_h = O_id
    End If
    If O_id = "" Then O_id = O_id_h
    If Ax_s = "X Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Y Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Z Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "PR Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "PA Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "D Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "R Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "T Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Roundness Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "A Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "A/2 Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "L Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "H Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Position X Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Y Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Z Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position PR Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position PA Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position DF Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Diam Location" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Position Roundness" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Dimension 2d Distance" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension 3d Distance" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension 2d Angle" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension 3d Angle" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Dimension Concentricity" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Coaxiality" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Circularity" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Flatness" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Perpendicularity" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Parallelism" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Total Runout" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Circular Runout" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    
    If Ax_s = "Dimension Profile of Surface" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Profile of Line" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Angularity" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    If Ax_s = "Dimension Symmetry" Then
    Part_S = Part_S & "," & O_id & "," & No_m & "," & Up_tol & "," & Low_tol
    End If
    End If
    
    'MsgBox ("Axis name: " & Ax_s)
    Skip:
    End If
    Next Cmd
    Part_S = SerNum & "," & Part_S
    
    End Sub
    


    I guess I'll have to start working on Geotol pulling next.
  • for Geotol you need:

    Public Function GetTextEx( _
    ByVal DataType As ENUM_FIELD_TYPES, _
    ByVal TypeIndex As Long, _
    ByVal Content As String _
    ) As String

    there is a example in this forum or you can use "export as basic"
  • retval = DmisCommand.PutTextEx ("DF", SUMMARY_AXIS, 6, "SEG=1")
    

    Above line of code appears in the exported basic script with a Geotol output that has the size of the feature, "DF" box checked.

    The below code can test a Positional output for the check boxes use.
    If cmd.GetTextEx(SUMMARY_AXIS, 6, "SEG=1") <> "DF" Then
    


    Why do none of the other GeoTol outputs have something like this line when the "DF" box is checked?
    When I Export to Basic and compare the outputs about the "DF" box being checked I can find 4 additional lines:
    Set UAME SIZE Item 1 = #####
    retval = DmisCommand.PutText("#####", UPPER_SIZE, 1)
    Set LOCAL SIZE Item 1 = #####
    retval = DmisCommand.PutText("#####", LOWER_SIZE, 1)
    


    In some efforts I have checked to find these lines, regardless of the "DF" box being un/checked, this information exists.
    I'm trying to determine how to skip the size information when "DF" is not checked.
  • So, I came across a flaw. When using a Geotol command to report Circular Runout, if DF is unchecked, I am still obtaining the diameter evaluation.
    The difference in command output is in the last post, when DF is CHECKED lines with UPPER_SIZE and LOWER_SIZE appear, when UNCHECKED they do not. But I cannot figure out how to 'test' for the line.
    Any suggestions?
  • I'm using a tolerancecommand object and the line "GeoTol.Sizecount>0" to check that.

    Generally the Tolerancecommand interface is well structured and has relatively few and only non-critical bugs as far as I've seen. I would recommend using that over Puttext/gettext as far as possible.
  • What happens if you have a +0/-.01 or +.01/-0? Would this type of tolerancing generate the skip or would it capture the data?