hexagon logo

my solution to .CSV output

Since it has come up a few times I thought I would share my solution to outputting data to a .csv file. I originally wrote this in VB express but I have converted it and tested it in 3.7's basic script editor and it works.

The output will be formatted as such: Dimension name, feature name, measured axis, nominal, + tolerance, - tolerance, measurement.

LOC1,LIN1,Y,-0.415,0.5,0.5,-0.40984622932167

Any other work that I need to do with the data I do in Excel after I import the file.

The data will output to the c:\ in a file named PCD Output.csv but with a little tweaking you can change this as you like.

I have done a lot more with this in VBE, but as far as the basics go it get's the job done.


There is a function call in the program but that makes it too long for a single post so you will need to get that from the next post.
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]Sub main[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      'Delare variable for file name to write to[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim strFileName As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      'connect to PCD program[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim ObjApp As Object[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim ObjPP As Object[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim ObjCmds As Object[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim ObjCmd As Object[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim ObjPart As Object[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim lngNumCmds As Long[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Set ObjApp = CreateObject("PCDLRN.Application")[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Set ObjPart = ObjApp.ActivePartProgram[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Set ObjCmds = ObjPart.Commands[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      set lngNumCmds = ObjCmds.Count[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      'Declare variables used for gather output info[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimID As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimFeature As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimType As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimNominal As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimUTol As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimLTol As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrDimMeasure As String[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      'Declare variable for creating CSV text like[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Dim StrOutputLine As String[/COLOR][/SIZE]
 
[SIZE=2][COLOR=#0000ff]              'Build and assign file name[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      strFileName = "C:\PCD output.txt"[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Open strFileName For Output As #1[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      For Each ObjCmd In ObjCmds[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]          If ObjCmd.IsDimension Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              If Not (ObjCmd.DimensionCommand.IsLocationAxis Or ObjCmd.DimensionCommand.IsTruePosAxis) Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]                  StrDimID = ObjCmd.DimensionCommand.ID[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]                  StrDimFeature = ObjCmd.DimensionCommand.Feat1[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              StrDimType = FncCmdType(ObjCmd.Type)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              StrDimNominal = CStr(ObjCmd.DimensionCommand.Nominal)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              StrDimUTol = CStr(ObjCmd.DimensionCommand.Plus)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              StrDimLTol = CStr(ObjCmd.DimensionCommand.Minus)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              If StrDimType <> "TPDM" Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]                  StrDimMeasure = CStr(ObjCmd.DimensionCommand.Measured)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]                  StrDimMeasure = CStr(ObjCmd.DimensionCommand.Deviation)[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              If Not (StrDimType = "Start_Loc" Or StrDimType = "Start_TP") Then[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]                  StrOutputLine = StrDimID + "," + StrDimFeature + "," + StrDimType + "," + StrDimNominal + "," + StrDimUTol + "," + StrDimLTol + "," + StrDimMeasure[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]                  print #1, StrOutputLine[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]              End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]          End If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Next[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      Close #1[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]      MsgBox("File save complete")[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End Sub[/COLOR][/SIZE]
[/COLOR][/SIZE]
Parents
  • It's not a dimension type, it's just a command of type = FEATURE_CONTROL_FRAME, and then just plain tables of data - no meaningful member names or anything. You'll need to verify the count of ten different tables, and decide what to do with them.

    Const LINE1_SIZE_TABLE = 1
    Const LINE2_POSITION_TABLE = 2
    Const LINE3_POSITION_TABLE = 3
    Const DATUM_SHIFT_TABLE = 4
    Const SUMMARY_TABLE = 5
    Const NOT_USED = 6
    Const LINE2_ORIENTATION_TABLE = 7
    Const LINE3_ORIENTATION_TABLE = 8
    Const LINE2_BASIC_DIMENSION_TABLE = 9
    Const LINE3_BASIC_DIMENSION_TABLE = 10


    with code like the following for each table type. Yech!

    '
    ' LINE2_BASIC_DIMENSION_TABLE --> most simple FCF dimensions, one Or more features
    '
      If cmd.GetFieldValue(RPT_DIMENSION_TABLES, LINE2_BASIC_DIMENSION_TABLE) = 1 Then
    
        For i = 1 To cmd.GetDataTypeCount(LINE2_FEATNAME)
          elValueType = cmd.GetFieldValue(LINE2_FEATNAME, i)
          elAct = cmd.GetFieldValue(LINE2_MEAS, i)
          elNom = cmd.GetFieldValue(LINE2_NOMINAL, i)
          elDev = cmd.GetFieldValue(LINE2_DEV, i)
          elMtol = cmd.GetFieldValue(LINE2_MINUSTOL, i)
          elPtol = cmd.GetFieldValue(LINE2_PLUSTOL, i)
          elOutTol = cmd.GetFieldValue(LINE2_OUTTOL, i)
          elStarted = 1
          PrintLine(fNum)
        Next i
      End If


    'Just' look through the code of the PCD2EXCEL wizard - all I know is what I found there (and in the type library - can be viewed in VBA in Excel).
Reply
  • It's not a dimension type, it's just a command of type = FEATURE_CONTROL_FRAME, and then just plain tables of data - no meaningful member names or anything. You'll need to verify the count of ten different tables, and decide what to do with them.

    Const LINE1_SIZE_TABLE = 1
    Const LINE2_POSITION_TABLE = 2
    Const LINE3_POSITION_TABLE = 3
    Const DATUM_SHIFT_TABLE = 4
    Const SUMMARY_TABLE = 5
    Const NOT_USED = 6
    Const LINE2_ORIENTATION_TABLE = 7
    Const LINE3_ORIENTATION_TABLE = 8
    Const LINE2_BASIC_DIMENSION_TABLE = 9
    Const LINE3_BASIC_DIMENSION_TABLE = 10


    with code like the following for each table type. Yech!

    '
    ' LINE2_BASIC_DIMENSION_TABLE --> most simple FCF dimensions, one Or more features
    '
      If cmd.GetFieldValue(RPT_DIMENSION_TABLES, LINE2_BASIC_DIMENSION_TABLE) = 1 Then
    
        For i = 1 To cmd.GetDataTypeCount(LINE2_FEATNAME)
          elValueType = cmd.GetFieldValue(LINE2_FEATNAME, i)
          elAct = cmd.GetFieldValue(LINE2_MEAS, i)
          elNom = cmd.GetFieldValue(LINE2_NOMINAL, i)
          elDev = cmd.GetFieldValue(LINE2_DEV, i)
          elMtol = cmd.GetFieldValue(LINE2_MINUSTOL, i)
          elPtol = cmd.GetFieldValue(LINE2_PLUSTOL, i)
          elOutTol = cmd.GetFieldValue(LINE2_OUTTOL, i)
          elStarted = 1
          PrintLine(fNum)
        Next i
      End If


    'Just' look through the code of the PCD2EXCEL wizard - all I know is what I found there (and in the type library - can be viewed in VBA in Excel).
Children
No Data