iLogic partslist expand children

Anonymous

iLogic partslist expand children

Anonymous
Not applicable

 

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)

Captura1.JPGCaptura2.JPG

Thanks in advance!

0 Likes
Reply
Accepted solutions (1)
828 Views
4 Replies
Replies (4)

clutsa
Collaborator
Collaborator
Accepted 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.

If I've helped you, please help me by supporting this idea.
Mass Override for Each Model State

Custom Glyph Icon for iMates

Anonymous
Not applicable

Thanks man!!

Works like a charm.

0 Likes

dominiek_vanwest
Advocate
Advocate

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

0 Likes

Jacob__with__a__k
Enthusiast
Enthusiast

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!

0 Likes

Type a product name