RENUMBER IF PART IS PURCHASED

RENUMBER IF PART IS PURCHASED

valentin_azamfirei
Participant Participant
659 Views
6 Replies
Message 1 of 7

RENUMBER IF PART IS PURCHASED

valentin_azamfirei
Participant
Participant

Is it possible to renumber, in an assembly, only the parts that have Part Structure as Purchased. Starting from 500, let's say. If so, could you please help me?

 

I have something like this untill now and it renumbers everypart with 500 and so on:

Sub main() 
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM
Dim oBOMView As BOMView = oBOM.BOMViews.Item(1)'Model Data 
Call IsPurchased(oBOMView.BOMRows, 0)
End Sub

Sub IsPurchased(Rows As BOMRowsEnumerator, indent As Integer)
For Each oBOMRow As BOMRow In Rows
	If oBOMRow.BOMStructure = 51973 Then
		Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
		Dim oBOMView As BOMView = oADoc.ComponentDefinition.BOM.BOMViews(2)
		oBOMView.Renumber(500, 5)	
	Else
		If Not oBOMRow.ChildRows Is Nothing Then
	        Call IsPurchased(oBOMRow.ChildRows, indent + 1)
	    End If
	End If
Next
End Sub
  

 

0 Likes
Accepted solutions (1)
660 Views
6 Replies
Replies (6)
Message 2 of 7

daltonNYAW9
Advocate
Advocate
Accepted solution

Renumbering BOM's is tricky for some reason. What I do is set all the row's I want changed to a set item number. Then I either lock all other rows or add the rows I want changed to a collection. Then finally renumber.

Sub main()
Dim doc As AssemblyDocument = ThisDoc.Document
Dim oAssyDef As AssemblyComponentDefinition = doc.ComponentDefinition
Dim oBOM As BOM = oAssyDef.BOM
Dim oBOMView As BOMView = oBOM.BOMViews.Item(2)'structured
Call IsPurchased(oBOMView.BOMRows, 0)
End Sub

Sub IsPurchased(Rows As BOMRowsEnumerator, indent As Integer)
	Dim PurchasedRows As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	For Each oBOMRow As BOMRow In Rows
		If oBOMRow.BOMStructure = 51973 Then
			PurchasedRows.Add(oBOMRow)
			oBOMRow.ItemNumber = 6969
		End If
	Next
	Rows.Item(1).Parent.Renumber(500, 5, PurchasedRows)
End Sub

Also, I dont think you can renumber "Child rows" in the structural rows tab. They will have the "500.1, 500.2, etc" or change the "." to anther character. If you want to renumber all the sub assemblies in an assembly you will have to do it another way.

0 Likes
Message 3 of 7

valentin_azamfirei
Participant
Participant

thanks. works like a charm

Message 4 of 7

valentin_azamfirei
Participant
Participant
quick question... what is "oBOMRow.ItemNumber = 6969"? 6969 to be more exactly
0 Likes
Message 5 of 7

daltonNYAW9
Advocate
Advocate

It sets all the item numbers to a high value that will never get used. It throws the numbering off if you dont do this, idk why. 

0 Likes
Message 6 of 7

valentin_azamfirei
Participant
Participant

And if i would like to search for a text in the Description Tab like "SHeetMetal" then it would be something like this?

 

Sub IsSheetMetal(Rows As BOMRowsEnumerator, indent As Integer)
	Dim Description As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	For Each oBOMRow As BOMRow In Rows
		If oBOMRow.BOMStructure = "SheetMetal" Then
			Description.Add(oBOMRow)
			
		End If
	Next
	Rows.Item(1).Parent.Renumber(100, 5, Description)

End Sub
0 Likes
Message 7 of 7

daltonNYAW9
Advocate
Advocate

You can check if a file is a sheet metal by its sub type
https://adndevblog.typepad.com/manufacturing/2013/01/inventor-document-sub-types.html

If oBOMRow.ComponentDefinitions(1).Document.SubType.ToString = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"

 

0 Likes