& Construction

Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
& Manufacturing

Professional CAD/CAM tools built on Inventor and AutoCAD
Integrated BIM tools, including Revit, AutoCAD, and Civil 3D
Professional CAD/CAM tools built on Inventor and AutoCAD
Hello. I was wondering if anyone could help me with this.
Below is the code I use to create an .IDW, create a partslist and export the partslist as EXCEL.
I need to know if I can expand all children before exporting it.
SyntaxEditor Code Snippet
v_RutaYNombre= ThisDoc.PathAndFileName(False) Dim v_DocReferencia As Document = ThisApplication.ActiveDocument Dim v_Plano As DrawingDocument = ThisApplication.Documents.Add(kDrawingDocumentObject, "V:\Templates\Templates 2017\INOXPASER\INOXPASER MECANIZADO ISO2768m2017.idw", True) Dim v_Hoja As Sheet = v_Plano.ActiveSheet Dim v_GeoTrans As TransientGeometry = ThisApplication.TransientGeometry v_Opciones = ThisApplication.TransientObjects.CreateNameValueMap v_ManagerEstilos = v_Plano.StylesManager v_EstiloLista = v_ManagerEstilos.PartsListStyles.Item("BOM") v_Plano = ThisApplication.ActiveDocument v_Plano.SaveAs(v_RutaYNombre & "BOM.idw",False) v_VistaSuperior = v_Hoja.DrawingViews.AddBaseView(v_DocReferencia,v_GeoTrans.CreatePoint2d(-15,0 ),.25,ViewOrientationTypeEnum.kTopViewOrientation,DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle,,,) v_Marco= v_Hoja.Border v_ListaPiezas = v_Hoja.PartsLists.Add(v_VistaSuperior, v_Marco.RangeBox.MaxPoint,PartsListLevelEnum.kStructuredAllLevels) v_Hoja.PartsLists(1).Style = v_EstiloLista v_Opciones.Value("AutoFitColumnWidth") = True v_ListaPiezas.Export(ThisDoc.Path & "\BOM.xls", PartsListFileFormatEnum.kMicrosoftExcel,v_Opciones) v_Plano.Close My.Computer.FileSystem.DeleteFile(v_RutaYNombre & "BOM.idw")
I'm posting 2 images:
1 As the partslist comes with my code
1 As it should be (with all levels expanded)
Thanks in advance!
Solved! Go to Solution.
Here's a sample of what you could do.
Dim app As Inventor.Application = ThisApplication Dim doc As DrawingDocument = app.ActiveDocument Dim oSheet As Sheet = doc.ActiveSheet Dim partslist As PartsList = oSheet.PartsLists(1) Dim oRow As PartsListRow Dim FirstRowCount As Integer = partslist.PartsListRows.Count Dim LastRowCount As Integer = 0 Do Until FirstRowCount = LastRowCount FirstRowCount = partslist.PartsListRows.Count For Each oRow In partslist.PartsListRows Try oRow.Expanded = True Catch ex As Exception End Try Next LastRowCount = partslist.PartsListRows.Count Loop
I know you have parts of my code already in your code but you get the idea.
Thanks man!!
Works like a charm.
The code from @clutsa works but if you have a big partslist it can take a while.
I've tried with my code below, which works a bit faster (as it goes through each line of the partslist only once).
Dim app As Inventor.Application = ThisApplication
Dim doc As DrawingDocument = app.ActiveDocument
Dim oSheet As Sheet = doc.ActiveSheet
Dim oPartsList As PartsList = oSheet.PartsLists(1)
Dim oRow As PartsListRow
Dim i As Integer
Do Until i = oPartsList.PartsListRows.Count + 1
On Error Resume Next
oPartsList.PartsListRows(i).Expanded = True
i = i + 1
Loop
However, it still doesn't work fast enough.
I have a partslist with 470 rows and my code takes about 1min15s to execute.
If I would do it manually (open partslist -> select column +/- -> right click -> Expand All Children) it takes only 5-10s.
Is there a way to improve speed of this?
I've also tried with Defer Updates and turn off visibility of Inventor but those didn't help.
Thanks in advance,
Dominiek
Hi,
just here to pitch my version of this solution:
same idea but it avoids throwing and catching a bunch of errors if the rows cannot be expanded
also a failsafe because I will never ever trust loops
and a bit of logging for testing
'expand all Dim oRow As PartsListRow Dim i As Integer = 0 Dim count As Integer = oPartslist.PartsListRows.Count Do i = i + 1 Try If oPartslist.PartsListRows(i).Expandable If Not oPartslist.PartsListRows(i).Expanded oPartslist.PartsListRows(i).Expanded = True Logger.Trace("row" & i & " (of " & count & ") expanded") Else Logger.Trace("row" & i & " (of " & count & ") already expanded") End If count = oPartslist.PartsListRows.Count Else Logger.Trace("row" & i & " (of " & count & ") part") End If Catch Logger.Trace("row" & i & " (of " & count & ") error") End Try If i > 500 Logger.Error("loop expand partslist stopped (" & iLogicVb.RuleName & " in " & ThisDoc.Document.DisplayName & ")") Exit Do End If Loop While i <= count
so yes, a bit more code but it's more stable and faster so worth it
this took 3 seconds for a parts list of 142 rows (expanded) with 12 assemblies that needed to be expanded
Happy coding!
How to buy
Privacy | Do not sell or share my personal information | Cookie preferences | Report noncompliance | Terms of use | Legal | © 2025 Autodesk Inc. All rights reserved
Type a product name