Not applicable
02-10-2015
04:42 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all, I'm trying to reproduce BOM structured view in an .txt file. Struggling with iLogic, and thank to internet, I'm now able to export an indented list of parts based on assembly tree order (note that I do not repeat a part or assembly if it is present more than one time for the specific level).
Now I'm facing the problem to calculate quantity of each part in my txt BOM. What is difficult for me is to sum the quantity of a part or assembly only at a specified level, without considering upper or lower levels. Does anybody could help me?
Hereafter my code (I know that probably could be better, any suggestion is REALLY REALLY REALLY welcome )
SyntaxEditor Code Snippet
Public Module GlobalVariables 'bom contiene i nomi delle parti Public bom As New ArrayList() 'livelli contiene i valori di liv per ciascuna parte considerata (serve per l'indentatura del file) Public livelli As New ArrayList() 'liv � il livello a cui si trova la parte/assieme Public liv As Integer 'cont contatore per il numero di parti nell'assieme Public cont As Integer End Module Public Sub Main Dim oTopAss As AssemblyDocument oTopAss = ThisApplication.ActiveDocument Dim oEachRefDoc As Document 'definisce il nome dell assieme proncipale CurFileName = oTopAss.fullFileName 'defines backslash as the subdirectory separator Dim strCharSep As String = System.IO.Path.DirectorySeparatorChar 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) liv=0 'aggiunge il nome dell'assieme proncipale alla lista GlobalVariables.bom.add(ShortName) cont=1 'aggiunge alla variabile livelli il valore del livello zero per l'assieme principale GlobalVariables.livelli.add(liv) liv=1 'ciclo sulle parti/assiemi di livello 1 For Each oEachRefDoc In oTopAss.ReferencedDocuments Dim oSubAssFullPath As String oSubAssFullPath = oEachRefDoc.FullFileName 'definisce il nome dell assieme/parte trattata CurFileName = oSubAssFullPath 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'aggiunge al bom il nome della parte GlobalVariables.bom.add(ShortName) cont=cont+1 'aggiunge alla variabile livelli il valore del livello a cui si trova la parte GlobalVariables.livelli.add(liv) 'verifica se la parte � un assieme e fa partire la funzione ricorsiva If TypeOf oEachRefDoc Is AssemblyDocument Then liv=liv+1 recurseSubAss(oEachRefDoc) End If Next 'crea il file di testo oWrite = System.IO.File.CreateText("c:\prova" & ".txt") oWrite.WriteLine("bom") oWrite.Close() For i=0 To cont-1 'scrive nel file di testo Dim oAppend As System.IO.StreamWriter oFile = "c:\prova" & ".txt" oAppend = IO.File.AppendText(oFile) oAppend.WriteLine(Space( GlobalVariables.livelli(i) * 3) & GlobalVariables.bom(i)) oAppend.Flush() oAppend.Close() 'ThisDoc.Launch(oFile) Next End Sub Public Sub recurseSubAss(ByVal oParentDoc As AssemblyDocument) Dim oAssDef As AssemblyComponentDefinition oAssDef = oParentDoc.ComponentDefinition Dim oEachRefDoc As Document For Each oEachRefDoc In oParentDoc.ReferencedDocuments Dim oSubAssFullPath As String oSubAssFullPath =oEachRefDoc.FullFileName 'definisce il nome dell assieme/parte trattata CurFileName = oSubAssFullPath 'find the postion of the last backslash in the path FNamePos = InStrRev(CurFileName, "\", -1) 'get the file name with the file extension Name = Right(CurFileName, Len(CurFileName) - FNamePos) 'get the file name (without extension) ShortName = Left(Name, Len(Name) - 4) 'aggiunge al bom il nome della parte GlobalVariables.bom.add(ShortName) cont=cont+1 'aggiunge alla variabile livelli il valore del livello a cui si trova la parte GlobalVariables.livelli.add(liv) If TypeOf oEachRefDoc Is AssemblyDocument Then liv=liv+1 recurseSubAss(oEachRefDoc) End If Next liv=liv-1 End Sub
Solved! Go to Solution.
