hexagon logo

CSV output in subprogram

I have been running the csvoutput script for years. for the first time I am trying to use it in a subprogram, but the script is written in such a way that it only pulls from the "active program".
does any one know how to modify the script so it pulls from the subprogram?
or does anyone have a script that will accomplish this?

the script i am using is below:

Sub main
'Delare variable For file Name To Write To
Dim strFileName As String
'connect To PCD program
Dim ObjApp As Object
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
'Declare variables used For gather Output info
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 StrDimDeviation As String
Dim StrDimOutOfTol As String
'Declare variable For creating CSV text like
Dim StrOutputLine As String
Dim txtFileNameVar As Object




Set txtFileNameVar = objPart.GetVariableValue("FILENAME2")

'Build And assign file Name
strFileName = ObjApp.ActivePartProgram.Path & txtFileNameVar.StringValue
Open strFileName For Output As #1
For Each ObjCmd In ObjCmds
If ObjCmd.IsDimension Then
If Not (ObjCmd.DimensionCommand.IsLocationAxis Or ObjCmd.DimensionCommand.IsTruePosAxis) Then
StrDimID = ObjCmd.DimensionCommand.ID
StrDimFeature = ObjCmd.DimensionCommand.Feat1
End If
StrDimType = FncCmdType(ObjCmd.Type)
StrDimNominal = CStr(ObjCmd.DimensionCommand.Nominal)
StrDimUTol = CStr(ObjCmd.DimensionCommand.Plus)
StrDimLTol = CStr(ObjCmd.DimensionCommand.Minus)
StrDimDeviation = CStr(ObjCmd.DimensionCommand.Deviation)
StrDimOutOfTol = CStr(ObjCmd.DimensionCommand.OutTol)
If StrDimType <> "TPDM" Then
StrDimMeasure = CStr(ObjCmd.DimensionCommand.Measured)
Else
StrDimMeasure = CStr(ObjCmd.DimensionCommand.Deviation)
End If
If Not (StrDimType = "Start_Loc" Or StrDimType = "Start_TP") Then
StrOutputLine = StrDimID + "," + StrDimFeature + "," + StrDimType + "," + StrDimNominal + "," + StrDimUTol + "," + StrDimLTol + "," + StrDimMeasure + "," + StrDimDeviation + "," + StrDimOutOfTol
Print #1, StrOutputLine
End If
End If
Next
Close #1
' MsgBox("File save complete")
End Sub

Function FncCmdType(ByVal intCmdTypeFunc As Double) As String
Dim StrFunCmd As String
Select Case intCmdTypeFunc
Case 1200 'start of TP dimension
StrFunCmd = "Start_TP"
Case 1201 'End of TP dimension
StrFunCmd = "End_TP"
Case 1000 'start of location dimension
StrFunCmd = "Start_Loc"
Case 1001 'End of location dimension
StrFunCmd = "End_Loc"
Case 1002 'x location
StrFunCmd = "X"
Case 1003 'y locatio
StrFunCmd = "Y"
Case 1004 'z location
StrFunCmd = "Z"
Case 1005 'diameter location
StrFunCmd = "D"
Case 1006 'radius location
StrFunCmd = "R"
Case 1007 'angle location
StrFunCmd = "A"
Case 1008 't vector location
StrFunCmd = "T"
Case 1011 'vector location
StrFunCmd = "V"
Case 1012 'length location
StrFunCmd = "L"
Case 1017 'height location
StrFunCmd = "H"
Case 1009 'polar raduis location
StrFunCmd = "PR"
Case 1010 'polar angle location
StrFunCmd = "PA"
Case 1013 'pin diameter location
StrFunCmd = "PD"
Case 1014 'deviation along report vector
StrFunCmd = "RT"
Case 1015 'surface deviation
StrFunCmd = "S"
Case 1016 'surface deviation along report vector
StrFunCmd = "RS"
Case 1100 'straightness
StrFunCmd = "STRT"
Case 1101 'roundness
StrFunCmd = "RND"
Case 1102 'flatness
StrFunCmd = "FLAT"
Case 1103 'perpendicularity
StrFunCmd = "PERP"
Case 1104 'parallelism
StrFunCmd = "PARA"
Case 1105 'profile of surface
StrFunCmd = "SPRF"
Case 1118 'profile of Line
StrFunCmd = "LPRF"
Case 1106 '3d distance
StrFunCmd = "DIST"
Case 1107 '2d distance
StrFunCmd = "DIST"
Case 1108 '3d angle
StrFunCmd = "ANGL"
Case 1109 '2d angle
StrFunCmd = "ANGL"
Case 1110 'runout
StrFunCmd = "RNOT"
Case 1111 'concentricity
StrFunCmd = "CONC"
Case 1112 'angularity
StrFunCmd = "ANTY"
Case 1113 'keyin
StrFunCmd = "KEY"
Case 1202 'TP x location
StrFunCmd = "TPX"
Case 1203 'TP y location
StrFunCmd = "TPY"
Case 1204 'TP z location
StrFunCmd = "TPZ"
Case 1205 'datum(?) diameter
StrFunCmd = "TPDD"
Case 1206 'diameter of feature
StrFunCmd = "TPDF"
Case 1207 'TP polar radius location
StrFunCmd = "TPPR"
Case 1208 'TP polar angle location
StrFunCmd = "TPPA"
Case 1209 'TP location
StrFunCmd = "TPDM"
Case 1115 'symmetry
StrFunCmd = "SYMT"
Case 1114 'Coaxiality
StrFunCmd = "COAX"
Case Else 'Everything Else
StrFunCmd = "UNKN"
End Select
FncCmdType = StrFunCmd
End Function