Sub Main(strVariable As String, reasonVar As String) 'xl Declarations Dim xlApp As Object Dim xlWorkbooks As Object Dim xlWorkbook As Object Dim xlSheet As Object Dim count As Integer 'pcdlrn declarations And Open ppg Dim App As Object Set App = CreateObject("PCDLRN.Application") Dim Part As Object Set Part = App.ActivePartProgram Dim Cmds As Object Set Cmds = Part.Commands Dim Cmd As Object Dim DCmd As Object Dim DcmdID As Object Dim DimID As String Dim fs As Object Dim ReportDim As String Dim CheckDim As String Dim sPuffer As String 'new 06.10.2021 Dim LoopIndex As Integer 'new 06.10.2021 'Check To see If results file exists FilePath = "" '.xlsm And .bas files location DataPath = "" 'report save location Set fs = CreateObject("Scripting.FileSystemObject") ResFileExists = fs.fileexists(DataPath & Part.PartName & " " & strVariable & " " & reasonVar & ".xlsm") 'check program folder For .xlsm file 'Open Excel And Base form Set xlApp = CreateObject("Excel.Application") Set xlWorkbooks = xlApp.Workbooks If ResFileExists = False Then TempFilename = FilePath & "Loop Template Column.xlsm" Else TempFilename = DataPath & Part.PartName & " " & strVariable & " " & reasonVar & ".xlsm" End If Set xlWorkbook = xlWorkbooks.Open(TempFilename) Set xlSheet = xlWorkbook.Worksheets("Sheet1") If ResFileExists = False Then RCount = 6 CCount = 3 xlSheet.Range("B1").Value = Part.PartName xlSheet.Range("E4").Value = Date & " " & Time() xlSheet.Range("D1").Value = strVariable xlSheet.Range("C2").Value = reasonVar For Each Cmd In Cmds 'Eliminate DATDEF's If Cmd.Type <> 1299 Then ' -- Do Dimensions -------------------------------------------------------- If Cmd.IsDimension Then If Cmd.Type = DIMENSION_START_LOCATION Or Cmd.Type = DIMENSION_TRUE_START_POSITION Then Set DcmdID = Cmd.DimensionCommand DimID = DcmdID.ID ReportDim = Cmd.GetText(OUTPUT_TYPE, 0) End If If Cmd.Type <> DIMENSION_START_LOCATION And Cmd.Type <> DIMENSION_END_LOCATION And _ Cmd.Type <> DIMENSION_TRUE_START_POSITION And Cmd.Type <> DIMENSION_TRUE_END_POSITION Then Set DCmd = Cmd.DimensionCommand CheckDim = Cmd.GetText(OUTPUT_TYPE, 0) If CheckDim <> "" Then ReportDim = CheckDim End If If ReportDim = "BOTH" Or ReportDim = "STATS" Then If DCmd.ID = "" Then xlSheet.Cells(RCount, 4).Value = DimID & " . " & DCmd.AxisLetter Else xlSheet.Cells(RCount, 4).Value = DCmd.ID & " . " & "M" End If xlSheet.Cells(RCount, 1).Value = DCmd.Nominal xlSheet.Cells(RCount, 2).Value = DCmd.Plus xlSheet.Cells(RCount, 3).Value = DCmd.Minus 'Measured Or Deviation With check For True Position If DCmd.AxisLetter <> "TP" Then xlSheet.Cells(RCount, 5).Value = DCmd.Measured Else xlSheet.Cells(RCount, 5).Value = DCmd.Deviation End If 'Add Min/Max For Profile dimensions If Cmd.Type = 1118 Or Cmd.Type = 1105 Then RCount = RCount + 1 xlSheet.Cells(RCount, 4).Value = DCmd.ID & "." & "Max" xlSheet.Cells(RCount, 1).Value = DCmd.Nominal xlSheet.Cells(RCount, 2).Value = DCmd.Plus xlSheet.Cells(RCount, 3).Value = DCmd.Minus xlSheet.Cells(RCount, 5).Value = DCmd.Max RCount = RCount + 1 xlSheet.Cells(RCount, 4).Value = DCmd.ID & "." & "Min" xlSheet.Cells(RCount, 1).Value = DCmd.Nominal xlSheet.Cells(RCount, 2).Value = DCmd.Plus xlSheet.Cells(RCount, 3).Value = DCmd.Minus xlSheet.Cells(RCount, 5).Value = DCmd.Min End If RCount = RCount + 1 End If End If 'Cmd.Type <> DIMENSION_START_LOCATION End If 'If Cmd.IsDimension Then ' -- Do FCF -------------------------------------------------------- If Cmd.Type = 184 Then ReportDim = Cmd.GetText(OUTPUT_TYPE, 0) If ReportDim = "BOTH" Or ReportDim = "STATS" Then xlSheet.Cells(RCount, 4).Value = Cmd.GetText(ID, 0) & "." & "FCF" xlSheet.Cells(RCount, 1).Value = "0" xlSheet.Cells(RCount, 2).Value = Cmd.GetText(LINE2_PLUSTOL, 1) xlSheet.Cells(RCount, 3).Value = "0" xlSheet.Cells(RCount, 5).Value = Cmd.GetText(LINE2_DEV, 1) RCount = RCount + 1 End If End If 'Do FCF ' -- Do GDT -------------------------------------------------------- 'new 06.10.2021 If (Cmd.Type = ISO_TOLERANCE_COMMAND) Or (Cmd.Type = ASME_TOLERANCE_COMMAND) Then ReportDim = Cmd.GetText(OUTPUT_TYPE, 0) If ReportDim = "BOTH" Or ReportDim = "STATS" Then LoopIndex = 1 sPuffer = DmisCommand.GetText(REF_ID, LoopIndex) While sPuffer <> "" xlSheet.Cells(RCount, 4).Value = Cmd.GetText(ID, 0) & "." & "GDT [Ref:" & sPuffer & "]" ' id xlSheet.Cells(RCount, 1).Value = "0" ' Nominals xlSheet.Cells(RCount, 2).Value = Cmd.GetText(FORM_TOLERANCE, 1) ' Tol plus xlSheet.Cells(RCount, 3).Value = "0" ' Tol minus xlSheet.Cells(RCount, 5).Value = Cmd.GetTextEx(DIM_DEVIATION, LoopIndex, "SEG=1") ' Meas RCount = RCount + 1 LoopIndex = LoopIndex + 1 sPuffer = DmisCommand.GetText(REF_ID, LoopIndex) Wend End If End If 'Do GDT End If Next Cmd Else 'If ResFileExists = False Then 'Find first Open column. CCount = 5 Found = 0 Do Until Found = 1 CCount = CCount + 1 If xlSheet.Cells(4, CCount).Value = "" Then Found = 1 End If Loop xlSheet.Cells(4, CCount).Value = Date & " " & Time() xlSheet.Cells(5, CCount).Value = " Part " & CCount - 4 'Fill In measured data RCount = 6 For Each Cmd In Cmds 'Eliminate DATDEF's If Cmd.Type <> 1299 Then 'Do Dimensions If Cmd.IsDimension Then If Cmd.Type = DIMENSION_START_LOCATION Or Cmd.Type = DIMENSION_TRUE_START_POSITION Then Set DcmdID = Cmd.DimensionCommand DimID = DcmdID.ID ReportDim = Cmd.GetText(OUTPUT_TYPE, 0) End If If Cmd.Type <> DIMENSION_START_LOCATION And Cmd.Type <> DIMENSION_END_LOCATION And _ Cmd.Type <> DIMENSION_TRUE_START_POSITION And Cmd.Type <> DIMENSION_TRUE_END_POSITION Then Set DCmd = Cmd.DimensionCommand CheckDim = Cmd.GetText(OUTPUT_TYPE, 0) If CheckDim <> "" Then ReportDim = CheckDim End If If ReportDim = "BOTH" Or ReportDim = "STATS" Then 'Measured Or Deviation With check For True Position If DCmd.AxisLetter <> "TP" Then xlSheet.Cells(RCount, CCount).Value = DCmd.Measured Else xlSheet.Cells(RCount, CCount).Value = DCmd.Deviation End If 'Add Min/Max For Profile dimensions If Cmd.Type = 1118 Or Cmd.Type = 1105 Then RCount = RCount + 1 xlSheet.Cells(RCount, CCount).Value = DCmd.Max RCount = RCount + 1 xlSheet.Cells(RCount, CCount).Value = DCmd.Min End If RCount = RCount + 1 End If End If 'Cmd.Type End If 'If Cmd.IsDimension Then ' -- Do FCF -------------------------------------------------------- If Cmd.Type = 184 Then ReportDim = Cmd.GetText(OUTPUT_TYPE, 0) If ReportDim = "BOTH" Or ReportDim = "STATS" Then xlSheet.Cells(RCount, CCount).Value = Cmd.GetText(ID, 0) & "." & "FCF" xlSheet.Cells(RCount, CCount).Value = "0" xlSheet.Cells(RCount, CCount).Value = Cmd.GetText(LINE2_PLUSTOL, 1) xlSheet.Cells(RCount, CCount).Value = "0" xlSheet.Cells(RCount, CCount).Value = Cmd.GetText(LINE2_DEV, 1) RCount = RCount + 1 End If End If ' -- Do GDT -------------------------------------------------------- 'new 06.10.2021 If (Cmd.Type = ISO_TOLERANCE_COMMAND) Or (Cmd.Type = ASME_TOLERANCE_COMMAND) Then ReportDim = Cmd.GetText(OUTPUT_TYPE, 0) If ReportDim = "BOTH" Or ReportDim = "STATS" Then LoopIndex = 1 sPuffer = DmisCommand.GetText(REF_ID, LoopIndex) While sPuffer <> "" xlSheet.Cells(RCount, 4).Value = Cmd.GetText(ID, 0) & "." & "GDT [Ref:" & sPuffer & "]" ' id xlSheet.Cells(RCount, 1).Value = "0" ' Nominals xlSheet.Cells(RCount, 2).Value = Cmd.GetText(FORM_TOLERANCE, 1) ' Tol plus xlSheet.Cells(RCount, 3).Value = "0" ' Tol minus xlSheet.Cells(RCount, 5).Value = Cmd.GetTextEx(DIM_DEVIATION, LoopIndex, "SEG=1") ' Meas RCount = RCount + 1 LoopIndex = LoopIndex + 1 sPuffer = DmisCommand.GetText(REF_ID, LoopIndex) Wend End If End If 'Do GDT End If Next Cmd End If 'If ResFileExists = False Then 'Save And Cleanup Set xlSheet = Nothing SaveName = DataPath & Part.PartName & " " & strVariable & " " & reasonVar & ".xlsm" If ResFileExists = False Then xlWorkbook.SaveAs SaveName Else xlWorkbook.Save End If xlWorkbook.Close Set xlWorkbook = Nothing xlWorkbooks.Close Set xlWorkbooks = Nothing xlApp.Quit Set xlApp = Nothing LabelEnd: End Sub