Need to Assign BOM Structure data for Children in Assembly

Need to Assign BOM Structure data for Children in Assembly

RoyWickrama_RWEI
Advisor Advisor
508 Views
2 Replies
Message 1 of 3

Need to Assign BOM Structure data for Children in Assembly

RoyWickrama_RWEI
Advisor
Advisor

I have a rule where I use to edit part numbers in assembly.

I also need to assign the BOM structure data: but this part (to assign BOM structure) is not right.

I request some one help me get this rule fixed.

 

Sub main
Dim oAsmDoc As AssemblyDocument 
oAsmDoc = ThisApplication.ActiveDocument 
Dim oDoc As Document         
Dim oRefFile As FileDescriptor
Dim xx As Integer = 1

For Each oDoc In oAsmDoc.AllReferencedDocuments  
'	Dim oDoc As Document = ThisApplication.ActiveDocument
	oDoc.DisplayName = ""
	oDT_PropSet = oDoc.PropertySets.Item("Design Tracking Properties")
	'oSI_PropSet = docFile.PropertySets.Item("Inventor Summary Information")
	'oDSI_PropSet = docFile.PropertySets.Item("Inventor Document Summary Information")
	'oUD_PropSet = docFile.PropertySets.Item("Inventor User Defined Properties")
		oPN_Doc = oDT_PropSet.Item("Part Number").Value
		Dim oPN_List As New ArrayList
		oPN_List.Add(oPN_Doc)		'oDT_PropSet.Item("Part Number").Value)
		oLFN = oDoc.DisplayName		'(False)
		'oFFN = oDoc.FullfileName(True)		'(False)
		'specify word splitting characters "space" and "dash"
		Dim Separators() As Char = {" "c, "-"c, "."c} 
		Sentence = oLFN
		Words = Sentence.Split(Separators)
		i = 0
		For Each wrd In Words
			If Words(i) = "ipt" Then
			Else If Words(i) = "iam" Then
			Else
				oPN_List.Add(Words(i))
			End If
		'MessageBox.Show("Word Index #" & i & " = " & Words(i))
		i += 1
		Next
		
	'oPN_List.Add("Other")
	oPN_List.Add("Exit")
	L_oPN_X:
	oPN_X = InputListBox("Prompt", oPN_List, oPN_Doc, Title := "PART NUMBER", ListName := "Select - Part Number")
	If oPN_X = "" Then GoTo L_oPN_X
	If oPN_X = "Exit" Then Exit Sub
	oPN_X_Edit = InputBox("Edit/Accept", "PART NUMBER", oPN_X)
	iProperties.Value(oLFN, "Project", "Part Number") = oPN_X_Edit

	Dim oList_BOM_Structure As New ArrayList
	oReference = "kReference"
	oPhantom = "kPhantom"
	oNormal = "kNormal"
	oPurchased = "kPurchased"
	If oDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then oCurrBOM = oPurchased
	If oLFN.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oCurrBOM = oReference
	If oLFN.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Then oCurrBOM = oNormal
	If oLFN.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then oCurrBOM = oPhantom
	oList_BOM_Structure.Add(oCurrBOM)	
	oList_BOM_Structure.Add(oReference)
	oList_BOM_Structure.Add(oPhantom)
	oList_BOM_Structure.Add(oNormal)
	oList_BOM_Structure.Add(oPurchased)
	oBOM_Structure_Selected = InputListBox("Prompt", oList_BOM_Structure, oList_BOM_Structure(0), Title := "SELECT BOM STRUCTURE", ListName := "BOM STRUCTURE")

	If oBOM_Structure_Selected = oReference Then oDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	If oBOM_Structure_Selected = oPhantom Then oDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	If oBOM_Structure_Selected = oNormal Then oDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
	If oBOM_Structure_Selected = oPurchased Then oDoc.Document.ComponentDefinition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure

xx += 1
Next oDoc

InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
End Sub




 

0 Likes
509 Views
2 Replies
Replies (2)
Message 2 of 3

RoyWickrama_RWEI
Advisor
Advisor

I refined a little bit. Referred to some help from the forum.

Now, I need to access all the documents. Currently, if goes through the 1st level only.

I will add some codes to filter the checked out document only, etc.

 

 

 

 

Sub main
Dim oAsmCompDef As AssemblyComponentDefinition
oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
'Iterate through all of the occurrences
Dim oOccurrence As ComponentOccurrence
For Each oOccurrence In oAsmCompDef.Occurrences
	Dim oList_BOM_Structure As New ArrayList
	oReference = "kReference"
	oPhantom = "kPhantom"
	oNormal = "kNormal"
	oPurchased = "kPurchased"
	If oOccurrence.Definition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure Then oCurrBOM = oPurchased
	If oOccurrence.Definition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure Then oCurrBOM = oReference
	If oOccurrence.Definition.BOMStructure = BOMStructureEnum.kNormalBOMStructure Then oCurrBOM = oNormal
	If oOccurrence.Definition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure Then oCurrBOM = oPhantom

	oList_BOM_Structure.Add(oOccurrence.Name)
	oList_BOM_Structure.Add(oCurrBOM)	
	oList_BOM_Structure.Add(oReference)
	oList_BOM_Structure.Add(oPhantom)
	oList_BOM_Structure.Add(oNormal)
	oList_BOM_Structure.Add(oPurchased)
	L_oBOM_Structure_Selecte:
	oBOM_Structure_Selected = InputListBox(oOccurrence.Name, oList_BOM_Structure, oList_BOM_Structure(1), Title := "SELECT BOM STRUCTURE", ListName := "BOM STRUCTURE")

	If oBOM_Structure_Selected = oList_BOM_Structure(0) Then GoTo L_oBOM_Structure_Selecte:
	If oBOM_Structure_Selected = oReference Then oOccurrence.Definition.BOMStructure = BOMStructureEnum.kReferenceBOMStructure
	If oBOM_Structure_Selected = oPhantom Then oOccurrence.Definition.BOMStructure = BOMStructureEnum.kPhantomBOMStructure
	If oBOM_Structure_Selected = oNormal Then oOccurrence.Definition.BOMStructure = BOMStructureEnum.kNormalBOMStructure
	If oBOM_Structure_Selected = oPurchased Then oOccurrence.Definition.BOMStructure = BOMStructureEnum.kPurchasedBOMStructure

Next oOccurrence

InventorVb.DocumentUpdate()
iLogicVb.UpdateWhenDone = True
End Sub

 

 

 

 

2020-07-25 13_09_56-Window.png

 

0 Likes
Message 3 of 3

RoyWickrama_RWEI
Advisor
Advisor

The rule is getting better.

Need some refinements: skip fasteners, checked-in documents, so on.

I appreciate receiving help. Thanks.

2020-07-26 16_49_43-Window.png

Prefixes are created in the numbering system.

fgpa: Frame generator phantom assembly

fgsk: Frame generator sketch

sk: Sketch

p: Part

A: Assembly

.....

 

0 Likes