iLogic rule for changing frame member part numbers

iLogic rule for changing frame member part numbers

Anonymous
Not applicable
1,266 Views
3 Replies
Message 1 of 4

iLogic rule for changing frame member part numbers

Anonymous
Not applicable

Hi there,

I am looking for a code to change the part numbers of all assembly members generated by the frame generator. Parts with the same length and family should have the same number. (Same as in BOM Parts). I must be able to enter the first part number, all others should be consecutive to the one I've entered.

For example: all frame members are 50x5 equal angle, 1 is 500mm, 2 are 1000mm, 1 is 600mm. The part numbers should begin with 1000. In this case, I should get 1000, 1001 and 1002 for the four parts. I do not want to have four part numbers.

I am hopeless with iLogic, Maybe someone can help me.

Accepted solutions (1)
1,267 Views
3 Replies
Replies (3)
Message 2 of 4

Curtis_Waguespack
Consultant
Consultant

Hi @Anonymous 

 

Give this a try. 

 

I found most of this code at this link authored by @petestrycharske :

 

Inventor Tips & Tricks - Methods for Controlling Frame Generator Filenames and Part Numbers (d3tech.net)

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Document
Dim oDocInt As DocumentInterest
Dim msg As String = "" 
Dim oList As New ArrayList
Dim oFrameParts As ObjectCollection 
oFrameParts = ThisApplication.TransientObjects.CreateObjectCollection() 

For Each oDoc In oAsmDoc.AllReferencedDocuments
    If oDoc.DocumentInterests.HasInterest("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _ 
       AndAlso oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject _
       AndAlso oDoc.IsModifiable _ 
       AndAlso oAsmDoc.ComponentDefinition.Occurrences.AllReferencedOccurrences(oDoc).Count > 0 
	   Logger.Info(oDoc.DisplayName)
	   
	   For Each oDocInt In oDoc.DocumentInterests 
		   	Logger.Info(oDocInt.Name)
			If oDocInt.Name = "FrameMemberDoc" Then
				'get stock number iprop
				Dim invDesignInfo As PropertySet
				oStockNumber = _
					oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value
				'add document to collection
				oFrameParts.Add(oDoc)
				'add stock number to list if not already in it
				If oList.Contains(oStockNumber) = False Then
					oList.Add(oStockNumber)
				End If
			End If
     	Next
    End If
Next

'compare documents in collection
'to the list of FG member sizes (stock numbers)
'and set part numbers
i = 1000
For Each oItem In oList
	j = i
	For Each oDoc In oFrameParts
		
		If oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = oItem Then
			oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = j + 1
			j = j +1
		End If			
	Next
	i = i + 1000
Next
	

 

 

 

EESignature

Message 3 of 4

Curtis_Waguespack
Consultant
Consultant

@Anonymous 

 

Just in case you get back to this before I do ( tomorrow) I remembered after I posted this that I forgot to include the part length in this... so currently as written two parts with the same stock number and part length are getting different part numbers... I’ll revisit this tomorrow to account for length.

EESignature

0 Likes
Message 4 of 4

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@Anonymous 

 

see this version for results such as this:

Curtis_W_0-1623329364259.png

 

 

Sub Main 

'''[ change these three varaibles to format the part number

'using prefix, part numbers are: FG-1000, FG-1001, FG-1002
'not using prefix, part numbers are: 1000, 1001, 1002
'set bUsePrefix to true if using a prefix
'set bUsePrefix to false if not using a prefix
bUsePrefix = False 		
oStartingPartNumber = 1000
oPrefix = "FG-"
''']

	
Dim oAsmDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oDoc As Document
Dim oDocInt As DocumentInterest
Dim msg As String = "" 
Dim oList As New ArrayList
Dim oFrameParts As ObjectCollection 
oFrameParts = ThisApplication.TransientObjects.CreateObjectCollection() 


For Each oDoc In oAsmDoc.AllReferencedDocuments
    If oDoc.DocumentInterests.HasInterest _
			("{AC211AE0-A7A5-4589-916D-81C529DA6D17}") _ 
       AndAlso oDoc.DocumentType = _
	   		DocumentTypeEnum.kPartDocumentObject _
       AndAlso oAsmDoc.ComponentDefinition.Occurrences. _
	   		AllReferencedOccurrences(oDoc).Count > 0 
	   
	   For Each oDocInt In oDoc.DocumentInterests 
		  	'Logger.Info(oDocInt.Name)
			If oDocInt.Name = "FrameMemberDoc" Then	
				
				'get member from function
				oMember = Get_IProps(oDoc)
				
				'add document to collection
				oFrameParts.Add(oDoc)
				'add Member size to list if not already in it
				If oList.Contains(oMember) = False Then
					oList.Add(oMember)
				End If
			End If
     	Next
    End If
Next

'compare documents in the collection
'to the list of FG member sizes (stock numbers x G_L)
'and set part numbers

i = oStartingPartNumber
oList.Sort
For Each oItem In oList
	Logger.Info("oItem " & oItem)
	For Each oDoc In oFrameParts	
		
		Dim invDesignInfo As PropertySet	
		invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")
		
		'get member from function
		oMember = Get_IProps(oDoc)	
		
		If oMember = oItem Then
			'set description to use combined stocknumber and length
			invDesignInfo.Item("Description").Value = oMember
			'get part number
			oPN = invDesignInfo.Item("Part Number")
			'set part number
			If bUsePrefix = True Then
				oPN.Value = oPrefix & i 
			Else
				oPN.Value = i 
			End If
			Continue For
		End If 			
	Next
	i = i + 1
Next

End Sub

Function Get_IProps(oDoc As Document)
	
	Dim invDesignInfo As PropertySet
	Dim invCustomInfo As PropertySet
		
	'get iprop sets
	invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")
	invCustomInfo = oDoc.PropertySets.Item("User Defined Properties")
	'get iprop values
	oStockNumber = invDesignInfo.Item("Stock Number").Value
	oLength = invCustomInfo.Item("G_L").Value
	'combine iprops
	oMember = oStockNumber & " x " & oLength
	
	'return value 
	Return oMember
	
End Function

 

EESignature