edit BOM.SetPartNumberMergeSettings on other assembly

edit BOM.SetPartNumberMergeSettings on other assembly

jaimievandamme1
Participant Participant
385 Views
4 Replies
Message 1 of 5

edit BOM.SetPartNumberMergeSettings on other assembly

jaimievandamme1
Participant
Participant

Hello everyone,

 

i would like a way to make a copy of my assem via ilogic and then change the .BOM.SetPartNumberMergeSettings(false) in that copy and save it back. the change must be made in the copy and not in the assem by turning this parameter off before saving and turning him back on after saving.

 

i have the save part already.

 

tnx,

 

Try

iLogicVb.RunRule("update view rep drawing")

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim FName As String = oDoc.FullFileName
Dim FNP As Integer = InStrRev(FName, "\", -1)
Dim oPath As String = Left(FName, FNP)
'Dim oNewName As String = InputBox("Enter New File Name", "Save as", "Name")
Dim oNewName As String = "samenstelling_voor_partslist"

' If the user closes the input box, then stop the function
If oNewName = vbNullString Then Exit Sub

Dim oType As String
Select Case oDoc.DocumentType
Case kPartDocumentObject:     oType = ".ipt"
Case kAssemblyDocumentObject: oType = ".iam"
Case kDrawingDocumentObject:  oType = ".idw"
End Select

oDoc.SaveAs(oPath & oNewName & oType, True)
iLogicVb.UpdateWhenDone = True

Catch
	
end try

 

0 Likes
Accepted solutions (1)
386 Views
4 Replies
Replies (4)
Message 2 of 5

JhoelForshav
Mentor
Mentor
Accepted solution

Just adding to your code without really testing it myself. Are you looking for something like this?

Try

iLogicVb.RunRule("update view rep drawing")

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim FName As String = oDoc.FullFileName
Dim FNP As Integer = InStrRev(FName, "\", -1)
Dim oPath As String = Left(FName, FNP)
'Dim oNewName As String = InputBox("Enter New File Name", "Save as", "Name")
Dim oNewName As String = "samenstelling_voor_partslist"

' If the user closes the input box, then stop the function
If oNewName = vbNullString Then Exit Sub

Dim oType As String
Select Case oDoc.DocumentType
Case kPartDocumentObject:     oType = ".ipt"
Case kAssemblyDocumentObject: oType = ".iam"
Case kDrawingDocumentObject:  oType = ".idw"
End Select

oDoc.SaveAs(oPath & oNewName & oType, True)
'Open the copied document hidden
Dim NewDoc As AssemblyDocument = ThisApplication.Documents.Open(oPath & oNewName & oType, False)
'Set PartNumberMergeSettings
NewDoc.ComponentDefinition.BOM.SetPartNumberMergeSettings(False)
'Save the document
NewDoc.Save()
'Close the document
NewDoc.Close
iLogicVb.UpdateWhenDone = True

Catch

End Try
0 Likes
Message 3 of 5

jaimievandamme1
Participant
Participant

works like a charm.

 

thank you verry mutch.

Message 4 of 5

jaimievandamme1
Participant
Participant

i want to renummber the BOM. i have try:

 

NewDoc.ComponentDefinition.BOM.RenumberItemsSequentially(True)

after the 

NewDoc.ComponentDefinition.BOM.SetPartNumberMergeSettings(False)

 

but it do not work. do you have any idea?

 

tnx 

0 Likes
Message 5 of 5

JhoelForshav
Mentor
Mentor

Hi @jaimievandamme1 

 

You can renumber the BOM views "Structured" and "Parts Only". I dont know which one you want to renumber but I added code to renumber both. The arguments In the method BOMView.Renumber are startvalue and increment value.

 

Try

iLogicVb.RunRule("update view rep drawing")

Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition

Dim oDoc As Inventor.Document = ThisApplication.ActiveDocument
Dim FName As String = oDoc.FullFileName
Dim FNP As Integer = InStrRev(FName, "\", -1)
Dim oPath As String = Left(FName, FNP)
'Dim oNewName As String = InputBox("Enter New File Name", "Save as", "Name")
Dim oNewName As String = "samenstelling_voor_partslist"

' If the user closes the input box, then stop the function
If oNewName = vbNullString Then Exit Sub

Dim oType As String
Select Case oDoc.DocumentType
Case kPartDocumentObject:     oType = ".ipt"
Case kAssemblyDocumentObject: oType = ".iam"
Case kDrawingDocumentObject:  oType = ".idw"
End Select

oDoc.SaveAs(oPath & oNewName & oType, True)
'Open the copied document hidden
Dim NewDoc As AssemblyDocument = ThisApplication.Documents.Open(oPath & oNewName & oType, False)

'Set a parameter for holding BOM object
Dim newDocBOM As BOM = NewDoc.ComponentDefinition.BOM

'Set PartNumberMergeSettings
newDocBOM.SetPartNumberMergeSettings(False)

'----Renumber Structured View--------
newDocBOM.StructuredViewEnabled = True
newDocBOM.BOMViews(2).Renumber(1, 1)
'------------------------------------

'----Renumber Parts Only View--------
newDocBOM.PartsOnlyViewEnabled = True
newDocBOM.BOMViews(3).Renumber(1, 1)
'------------------------------------

'Save the document
NewDoc.Save()
'Close the document
NewDoc.Close
iLogicVb.UpdateWhenDone = True

Catch

End Try
0 Likes