Creating an custom BOM table with view representations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I hope someone can help me in the right direction.
We use View representations to create (color) variants. And with iLogic we create an BOM with custom table.
The current base of the code is place below. I stripped all the exceptions / renaming based on view representation name, creating tables, etc. because that works fine.
The problem I encounter is that to get the 'associated' view representations of subassemblies I need to activate each view rep. Which means that inventor wants to save all the (sub) files. Also the ones blocked due to the vault.
Is there a way to read all the view representations and their information, without the need to activate?
I found;
Dim DesignInformationString as string = oAssyDoc.DesignViewInfo
It works doesn't need the activation, which is great. But it gives colours, instead of linked design views and their names. It also ignores the assembly layers, and goes straight to the leaf occurences. (I Need the assembly's, unless they are phantom)
Sub Main
'Bestand definities
'[
oAssyDoc = ThisDoc.ModelDocument
oDrawDoc = ThisApplication.ActiveDocument
oAssyDefinition = oAssyDoc.ComponentDefinition
']
EachViewRep
MessageBox.Show(EndResultMessage)
End Sub
'Definities voor gehele rule
Dim oAssyDoc As AssemblyDocument 'het assembly bestand
Dim oDrawDoc As DrawingDocument 'het drawing bestand
Dim oAssyDefinition As ComponentDefinition 'definition van het assembly bestand
Dim ViewRepName As String 'huidige view rep naam
Dim EndResultMessage As String 'bericht op eind van code
Dim CurrentVariantTable As String 'tabel van huidige variant
Dim AddToList As String 'string voor toeveogen infomratie aan lijsten
Dim BOMList As New ArrayList() 'per variant: stuklijst
Dim PhantomAssemblyPart As Boolean 'bijhouden of deze assembly/part phantom is of niet
Dim ModifiableBoolean As Boolean 'controlere of assembly aanpasbaar is
']
Sub EachViewRep
'Definities binnen sub
'[
ViewRepName = "" 'Name van view rep
Dim oViewReps As DesignViewRepresentations 'meerdere view represetnations
Dim oViewRep As DesignViewRepresentation 'een view representation
oViewReps = oAssyDefinition.RepresentationsManager.DesignViewRepresentations
']
'lijst maken met alle view presentations van de varianten
'[
Dim ViewRepList As New ArrayList()
For Each oViewRep In oViewReps
ViewRepName = oViewRep.Name
If ViewRepName.Contains("Materiaal = ")
ViewRepList.Add(ViewRepName)
End If
Next
Dim AmountViewReps As Integer = ViewRepList.Count
']
ViewRepList.Sort 'op alfabetische volgorde
i = 0 'teller voor view reps
While (i < AmountViewReps)
ViewRepName = ViewRepList(i)
'Activate view rep
'[
Try
oAssyDefinition.RepresentationsManager.DesignViewRepresentations.Item(ViewRepName).Activate
Catch
ModifiableBoolean = oAssyDoc.IsModifiable
If ModifiableBoolean = False
Try
oAssyDoc = ThisApplication.Documents.Open(oAssyDoc.FullFileName, False)
oAssyDefinition = oAssyDoc.ComponentDefinition
oViewReps = oAssyDefinition.RepresentationsManager.DesignViewRepresentations
oAssyDefinition.RepresentationsManager.DesignViewRepresentations.Item(ViewRepName).Activate
Catch
MessageBox.Show("Probleem met activeren van:" & vbCrLf & ViewRepName & vbCrLf & vbCrLf & "CONTROLEER stuklijsten!", "ERROR: view representation activate - false", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End Try
Else
MessageBox.Show("Probleem met activeren van:" & vbCrLf & ViewRepName & vbCrLf & vbCrLf & "CONTROLEER stuklijsten!", "ERROR: view representation activate - true", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Try
']
BOMList.Clear()
'Roep de function om BOM list te maken aan & voeg resultaten toe aan het totale overzicht
'[
EachOccurrence(oAssyDoc.ComponentDefinition.Occurrences)
ProcessLists
EndResultMessage = EndResultMessage & vbCrLf & vbCrLf & UCase(ViewRepName) & vbCrLf & CurrentVariantTable
']
i = i + 1
If i = 100 Then
MessageBox.Show("View Reps loop blijft hangen. Mogelijk niet alle tabellen geplaatst.", "ERROR: View representation loop", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit While
End If
End While
']
End Sub
Sub EachOccurrence(oOccs As ComponentOccurrences)
'definities voor deze functie
'[
Dim OccurrenceFullName As String
Dim OccurrencePartNumber As String
Dim OccurrenceViewRep As String
Dim OccurrenceAssembly As Boolean = False
']
'Alle componenten langsgaan
For Each occ In oOccs
'Naam van occurrence in deze assembly
OccurrenceFullName = occ.Name
OccurrenceFullNameSplit = OccurrenceFullName.Split(":")
'onzichtbare onderdelen & onderdelen waarvan om structure afwijkt eruit filteren, en naar lijst voor controle
'[
If occ.Visible = False
Continue For
Else
Try
If occ.Definition.BOMStructure = 51970 OrElse occ.Definition.BOMStructure = 51971 OrElse occ.Definition.BOMStructure = 51973 OrElse occ.Definition.BOMStructure = 51974
Else
Continue For
End If
Catch
Continue For
End Try
End If
']
'Bepaal view rep
'[
Try
OccurrenceViewRep = occ.ActiveDesignViewRepresentation
Catch
OccurrenceViewRep = ""
End Try
']
'Bepaal partnumber
'[
Try
OccurrencePartNumber = occ.Definition.Document.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value
Catch
OccurrencePartNumber = OccurrenceFullNameSplit(0)
End Try
If OccurrencePartNumber = ""
OccurrencePartNumber = OccurrenceFullNameSplit(0)
End If
']
PhantomAssemblyPart = False ' bijhouden of het een phantom assembly of onderdeel is
If occ.Definition.BOMStructure = 51971
'[
'bepalen of het een assembly is
Try
If occ.DefinitionDocumentType = kAssemblyDocumentObject
OccurrenceAssembly = True
Else
OccurrenceAssembly = False
End If
Catch
OccurrenceAssembly = False
End Try
If OccurrenceAssembly = True
'View representation activeren van de sub assembly
OccurrenceViewRep = occ.ActiveDesignViewRepresentation
If OccurrenceViewRep IsNot ""
Try
Dim oDoc As AssemblyDocument = occ.Definition.Document
Dim occDef As ComponentDefinition = oDoc.ComponentDefinition
occDef.RepresentationsManager.DesignViewRepresentations.Item(OccurrenceViewRep).Activate
Call EachOccurrence(oDoc.ComponentDefinition.Occurrences)
Catch
Call EachOccurrence(occ.SubOccurrences)
End Try
Else
Call EachOccurrence(occ.SubOccurrences)
End If
End If
PhantomAssemblyPart = True
']
Else
'Overige onderdelen in stuklijst plaatsen
'[
AddToList = OccurrencePartNumber & ":" & OccurrenceViewRep
BOMList.Add(AddToList)
']
End If
Next
End Sub
Sub ProcessLists
'Strings leegmaken
CurrentVariantTable = ""
'Lists verwerken
'Stuklijst sorteren en optellen
'[
Amount = BOMList.Count
If Amount = 0
Else
BOMList.Sort
TableRows = 0 'starten met 0 rijen
i = 0 'Teller voor positie in de lijst
j = 1 'Teller voor aantal exact zelfde in de lijst
BOMListCurrent = "" 'Eerste is er nog geen current
Dim RevisieCurrent As String = ""
While (i < Amount)
If BOMListCurrent = BOMList(i)
'Als vorige gelijk is aan de huidige, dan aantal 1 omhoog
j = j + 1
Else If i = 0
'Eerste waarde kan nog niet gekeken worden of hij gelijk is met de vorige
BOMListCurrent = BOMList(i)
Else
'Vorige is niet gelijk, dus vorige word toegevoegd aan de lijst & de huidige word de current en begint op teller 1
If CurrentVariantTable = ""
CurrentVariantTable = j & "x;" & BOMListCurrent
'eerste in de table toeveogen met het aantal
Else
CurrentVariantTable = CurrentVariantTable & vbCrLf & j & "x;" & BOMListCurrent
'volgende in de table toevoegen achter de vorige met aantal
End If
j = 1 'teller voor aantal onderdelen gaat weer naar 1
BOMListCurrent = BOMList(i) 'huidige word current
End If
If i = Amount - 1
'Laatste van de rij moet ook toegevoegd worden, die word namelijk niet vergelijken met een volgende
BOMListCurrentSplit = BOMListCurrent.Split(";")
If CurrentVariantTable = ""
CurrentVariantTable = j & ";" & BOMListCurrent
Else
CurrentVariantTable = CurrentVariantTable & vbCrLf & j & "x;" & BOMListCurrent
End If
TableRows = TableRows + 1
End If
i = i + 1
If i = 10000 Then
MessageBox.Show("Vast gelopen in maken stuklijst. Niet complete stuklijst. (" & DocPartNumberChanged & ")", "ERROR: Stuklijst maken", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit While
End If
End While
End If
']
End Sub