Hi @WCrihfield ,
Thanku for your reply..
yes that is not full code.. I didn't post the full code since I thought it would make the post longer.
Below is my full code..
Sub main()
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
MessageBox.Show("Please run this rule from the assembly file.", "iLogic")
Exit Sub
End If
Dim TemplateFolder As String = ThisApplication.DesignProjectManager.ActiveDesignProject.TemplatesPath
Dim ExcelTemplate As String = TemplateFolder &"\EDT_T-PA25-DT200_BoM.xltx"
If System.IO.File.Exists(ExcelTemplate) = False Then
MessageBox.Show("Cannot locate the BoM Excel Template. Make sure it is saved under the " _
& "name 'EDT_T-PA25-DT200_BoM' in the current project template folder" & vbNewLine _
& vbNewLine & vbNewLine & vbNewLine &"Click OK to open the Template folder", "BoM Excel template unavailable")
Shell("explorer.exe " & TemplateFolder, vbNormalFocus)
Exit Sub
End If
Dim MissingList As Collection = New Collection
Choice = InputRadioBox("Select the BoM type", "Phase BoM", "KIT BoM", True, Title := "Export BoM")
oPath = ThisDoc.Path
oName = ThisDoc.FileName(False) 'without extension
Dim oDate As String = Now().ToString("yyMMdd-HHmm_")
oDate = oDate.Replace(":", "") ' & " - " & TypeString
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oBOM As BOM
oBOM = oDoc.ComponentDefinition.BOM
oBOM.StructuredViewEnabled = True
oBOM.StructuredViewFirstLevelOnly = False
Dim oBOMView As BOMView
xlApp = CreateObject("Excel.Application")
'comment out or change to false
'in order to not show Excel
xlApp.Visible = False
workspace = ThisDoc.WorkspacePath()
xlWorkbook = xlApp.Workbooks.Open(ExcelTemplate)
Dim row As Integer
row = 4
If Choice Then
'get target folder path
oFolder = oPath & "\" & oDate & oName & " Phase BOM"
oBOMView = oBOM.BOMViews.Item("Structured")
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
xlWorksheet = xlWorkbook.Worksheets("KITs List")
xlWorksheet.Activate
Call QueryBOMRowProperties(oBOMView.BOMRows, xlApp, xlWorkbook, xlWorksheet, row)
Else
xlApp.DisplayAlerts = False
xlWorkbook.Worksheets("KITs List").Delete
xlApp.DisplayAlerts = True
'get target folder path
oFolder = oPath & "\" & oDate & oName & " KIT BOM"
End If
row = 4
Dim iBOM As BOM
iBOM = oDoc.ComponentDefinition.BOM
iBOM.PartsOnlyViewEnabled = True
Dim iBOMView As BOMView
iBOMView = iBOM.BOMViews.Item("Parts Only")
ThisApplication.CommandManager.ControlDefinitions.Item("AppUpdateMassPropertiesCmd").Execute
xlWorksheet = xlWorkbook.Worksheets("Parts List")
xlWorksheet.Activate
iBOMView.Sort("Part Number", True)
iBOMView.Renumber(1,1)
Dim ibRow As BOMRow
ibRows = iBOMView.BOMRows
For Each ibRow In ibRows
If ibRow.ComponentDefinitions.Item(1).Type = "100675072" Then
Dim VirtualDoc As ComponentDefinition = ibRow.ComponentDefinitions.Item(1)
Dim docPropertySet As PropertySet
docPropertySet = VirtualDoc.PropertySets.Item("Design Tracking Properties")
customprop = VirtualDoc.PropertySets.Item(“Inventor User Defined Properties”)
xlWorksheet.Range("A" & row).Value = docPropertySet.Item("Part Number").Value
xlWorksheet.Range("B" & row).Value = docPropertySet.Item("Description").Value
xlWorksheet.Range("C" & row).Value = docPropertySet.Item("Material").Value
Try
xlWorksheet.Range("D" & row).Value = customprop.Item("Finish Spec Code").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Finish")
End Try
Try
xlWorksheet.Range("E" & row).Value = customprop.Item("MaxL").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-MaxL")
End Try
Try
xlWorksheet.Range("F" & row).Value = customprop.Item("Width").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Width")
End Try
Try
xlWorksheet.Range("G" & row).Value = customprop.Item("Thickness").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Thickness")
End Try
xlWorksheet.Range("H" & row).Value = ibRow.ItemQuantity
Else
Dim rDoc As Document
rDoc = ibRow.ComponentDefinitions.Item(1).Document
Dim docPropertySet As PropertySet
docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")
customprop = rDoc.PropertySets.Item(“Inventor User Defined Properties”)
xlWorksheet.Range("A" & row).Value = docPropertySet.Item("Part Number").Value
xlWorksheet.Range("B" & row).Value = docPropertySet.Item("Description").Value
xlWorksheet.Range("C" & row).Value = docPropertySet.Item("Material").Value
Try
xlWorksheet.Range("D" & row).Value = customprop.Item("Finish Spec Code").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Finish")
End Try
Try
xlWorksheet.Range("E" & row).Value = customprop.Item("MaxL").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-MaxL")
End Try
Try
xlWorksheet.Range("F" & row).Value = customprop.Item("Width").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Width")
End Try
Try
xlWorksheet.Range("G" & row).Value = customprop.Item("Thickness").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Thickness")
End Try
xlWorksheet.Range("H" & row).Value = ibRow.TotalQuantity
xlWorksheet.Range("I" & row).Value = ibRow.ComponentDefinitions.Item(1).Document.ComponentDefinition.MassProperties.Mass
End If
row = row + 1
Next
Dim Message As String = ""
'For Each iList As String In MissingList
' Message = Message & iList & vbNewLine
'Next
'If MissingList.Count = 0 Then
'Else
'MessageBox.Show(Message & vbNewLine & "Click OK to copy the List to clipboard", _
'"The rule didn't run on these " & MissingList.Count & " Read Only Parts")
'Clipboard.SetText(Message)
'End If
'get target folder path
xlWorksheet1 = xlWorkbook.Worksheets("Cover")
xlWorksheet1.Activate
xlWorksheet1.Range("BD21").Value = iProperties.Value("Project", "Part Number")
xlWorksheet2 = xlWorkbook.Worksheets("Verification")
xlWorksheet2.Activate
xlWorksheet2.Range("B4").Value = Now().ToString("dd/MM/yy")
'Check for the folder and create it if it does not exist
If Not System.IO.Directory.Exists(oFolder) Then
System.IO.Directory.CreateDirectory(oFolder)
End If
Dim Filename As String = oFolder & "\" & oName & ".xlsx"
'If you want to save the workbook in a specified name
xlWorkbook.SaveAs(Filename)
xlWorkbook.Close
xlApp.Quit
'Show the folder
MessageBox.Show("New Files Created in: " & vbLf & oFolder, "iLogic")
'Open the folder containing the new files
Shell("explorer.exe " & oFolder, vbNormalFocus)
End Sub
Private Sub QueryBOMRowProperties(oBOMRows As BOMRowsEnumerator,ByVal xlApp As Object, ByVal xlWorkbook As Object, ByVal xlWorksheet As Object, ByRef row As Integer)
Dim i As Long
For i = 1 To oBOMRows.Count
Dim bRow As BOMRow
bRow = oBOMRows.Item(i)
Dim rDoc As Document
rDoc = bRow.ComponentDefinitions.Item(1).Document
Dim MissingList As Collection = New Collection
Dim docPropertySet As PropertySet
docPropertySet = rDoc.PropertySets.Item("Design Tracking Properties")
customprop = rDoc.PropertySets.Item(“Inventor User Defined Properties”)
SummaryPropertySet = rDoc.PropertySets.Item("Summary Information")
xlWorksheet.Range("B" & row).Value = bRow.ItemNumber
xlWorksheet.Range("C" & row).Value = docPropertySet.Item("Part Number").Value
xlWorksheet.Range("D" & row).Value = docPropertySet.Item("Description").Value
Try
xlWorksheet.Range("E" & row).Value = customprop.Item("Frame Height").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Frame Height")
End Try
Try
xlWorksheet.Range("F" & row).Value = customprop.Item("Frame Width").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Frame Width")
End Try
Try
xlWorksheet.Range("G" & row).Value = customprop.Item("MaxL").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-MaxL")
End Try
xlWorksheet.Range("H" & row).Value = bRow.ItemQuantity
'xlWorksheet.Range("H" & row).Value = docPropertySet.Item("Material").Value
Try
xlWorksheet.Range("I" & row).Value = customprop.Item("Finish Spec Code").Value
Catch
MissingList.Add(docPropertySet.Item("Part Number").Value & "-Finish")
End Try
'Try
'xlWorksheet.Range("A" & row).Value = customprop.Item("Phase Number").Value
'Catch
'MissingList.Add(docPropertySet.Item("Part Number").Value & "-Phase Number")
'End Try
xlWorksheet.Range("J" & row).Value = bRow.ComponentDefinitions.Item(1).Document.ComponentDefinition.MassProperties.Mass
row = row + 1
If Not bRow.ChildRows Is Nothing Then
Call QueryBOMRowProperties(bRow.ChildRows, xlApp, xlWorkbook, xlWorksheet, row)
End If
Next
End Sub
I went through your reply but i am not very well versed with iLogic programming, is there any chance you could help me through a code representation ?