- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi!
I need to change the BOM structure at all parts that contains "BQ" in the filenamn to Reference.
I know it exist a lot of information for that here, but I can´t get it to work.
This works, but only if it is no subassemblys.
ThisDoc.Document.ComponentDefinition.BOM.BOMViews(1).BOMRows(1).BOMStructure = 51972
On Error Resume Next
'Define the open document
Dim oDoc As Document
oDoc = ThisDoc.Document
If Not ThisApplication.ActiveDocument.DocumentType = kAssemblyDocumentObject Then
Return
End If
Dim docFile As Document 'Look at all of the files referenced in the open document
For Each docFile In ThisDoc.Document.AllReferencedDocuments
ThisApplication.Documents.Open(docFile.FullFileName, True) 'open the indexed file: true opens the file normaly, false opens the file programatically without generating the graphics
auto = iLogicVb.Automation 'run rule in the drawing document
If docFile.FullFileName.Contains("BQ") 'without extension. Om filnamnet innehåller "BQ" gäller följnade:
k = docFile.FullFileName 'k = Sökväg och filnamn
n = InStrRev(k, "\", - 1) ' n =87
j = k.Length ' j = längden på filnamnet med sökväg = 107
a = k.substring(k.Length - (j - n)) 'a = Filnamnet med filändelse (.ipt)
iProperties.Value(a, "Project", "Stock Number") = "LISEGA" 'Ändrar Stock number till "LISEGA"
langd = Len (a) 'langd = längden på filnamnet inklusive filändelse (.ipt)
name = a.Substring(0, (langd - 4)) ' Filnamnet - filändelsen, de 4 sista tecknen (.ipt)
p = InStr(a, " ") 'p = antal tecken i filnamnet fram till mellanrum.
u = InStr(a, "_") 'u = antal tecken i filnamnet fram till _ understreck.
'Ändrar iProperties/Project till de tecknen fram till mellanrum eller _understreck eller i filnamnet eller till filnamnet.
If p < 2 And u > 2 Or p > 14 And u > 2 Then 'Om det inte finns mellanslag eller om det är mer än 14 tecken fram till mellanslaget Och det finns _understreck
iProperties.Value(a, "Project", "Project") = a.Substring(0, u - 1) 'i = antal tecken i filnamnet fram till _ understreck.
Else If p >= 2 And p <= 14 Then 'Om det är mer än 1 och mindre än 15 tecken fram till mellanslag, det normala
iProperties.Value(a, "Project", "Project") = a.Substring(0, p - 1) 'without extension. Ändrar Project/Project till filnamnet fram till första mellanslaget
Else If langd > 15 Then 'Om det är mer än 12 tecken fram till mellanslaget eller det inte finns mellanslag och det inte finns _ och filnamnet är längre än 15 tecken.
iProperties.Value(a, "Project", "Project") = a.Substring(0, 12) 'without extension. Ändrar Project/Project till filnamnets 12 första tecken.
Else 'Om det inte finns mellanslag eller _understreck i filnamnet och filnamnet är kortare än 14 tecken.
iProperties.Value(a, "Project", "Project") = name 'Ändrar Project/Project till filnamnet utan de 4 sista tecknen (.ipt)
End If
iProperties.Value(a, "Summary", "Keywords") = iProperties.Value(a, "Project", "Project") 'Ändrar Summery/Keywords till Project/Project'
'THIS IS THE PROBLEM:==========================================================================================================
'THIS WORKS, BUT ONLY IF THERE IS NOT A SUBASSEMBLY =========================================================
ThisDoc.Document.ComponentDefinition.BOM.BOMViews(1).BOMRows(1).BOMStructure = 51972 'Ändrar BOM structure till Reference
'I HAVE TRYED MANY DIFFERENT COMMANDS:
docFile.Document.ComponentDefinition.BOM.BOMViews(1).BOMRows(1).BOMStructure = 51972 'Ändrar BOM structure till Reference
doc = ThisDoc.Document
def = doc.ComponentDefinition
thebom = def.BOM
thebomview= thebom.BOMViews(1)
thebomrow = thebomview.BOMRows(1)
thebomrow.BOMStructure = 51972 'kReferenceBOMStructure
k.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
BOMStructure = BOMStructureEnum.kReferenceBOMStructure
ThisDoc.Document.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
docFile.FullFileName.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
oCompOcc = Component.InventorComponent(k)
oCompOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
oCompOcc = Component.InventorComponent(a)
oCompOcc.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
BOMStructure = 51972
compOcc = ThisDoc.Document
compOcc.Definition.BOMStructure = 51972
a.Definition.BOMStructure = 51972
doc = ThisDoc.Document 'This line only needs to appear once in the rule
vPart = Component.InventorComponent(docFile.FullFileName) 'This line is only required once per virtual part
vPart.BOMStructure = BOMStructureEnum.kReferenceBOMStructure 'Sets BOM Structure to Reference (Remove from BOM)
vPart = Component.InventorComponent(a) 'This line is only required once per virtual part
vPart.BOMStructure = BOMStructureEnum.kReferenceBOMStructure 'Sets BOM Structure to Reference (Remove from BOM)
'==================================================================================================================
iProperties.Material(a) = "S235JRG2" 'Ändrar materialet till S235JRG2
InventorVb.DocumentUpdate() 'Uppdaterar filen, ibland måste man uppdatera för att ändringarna ska slå fast
iProperties.Value(a, "Project", "Part Number") = a 'Ändrar Project/Part Number till filnamnet
End If
'ThisDoc.Save 'Saves the file, don´t know the different of "ThisDoc.Save" and "docFile.Save".
docFile.Save
docFile.Close
Next
iLogicVb.UpdateWhenDone = True
'JOPE 2015-10-05
Solved! Go to Solution.