Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating Feature Based Pattern

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
felix.cortes5K3Y2
686 Views, 2 Replies

Creating Feature Based Pattern

Hi Forum,

 

I am trying to create a pattern of a part inside an assembly based off a rectangular part feature from another part but can't seem to get the code to work. Here's what I have written so far:

 

 

	
	Dim BrowserName As String = "SERPENTINE SHOE" 'the part that needs to be pattern
	Dim PatternBrowserName As String = BrowserName & "S" 'name of pattern that will be made
	Dim FeatureName As String = "Shoe Pattern" 'name of the feature
	Dim RefPartName As String = "SERPENTINE SPREADER FOR SHOE" 'name of the part with the feature
	
	Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
	Dim oAsmComp As AssemblyComponentDefinition = oAsm.ComponentDefinition
	Dim oOcc As ComponentOccurrence
	Dim oOccPattern As OccurrencePattern
	Dim PartExists As Boolean = False
	Dim PatternExists As Boolean = False 
	Dim oPattern As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
	Dim n As Integer = 1
	Dim RefExists As Boolean = False
	Dim oPartDoc As PartDocument
	Dim oPartComp As PartComponentDefinition
	Dim oFeat As PartFeature
	
	For Each oOcc In oAsmComp.Occurrences
		If oOcc.Name = BrowserName Then
			PartExists = True
			oPattern.Add(oAsmComp.Occurrences.Item(n))
		Else If oOcc.Name = RefPartName Then
			RefExists = True
			oPartDoc = ThisApplication.Documents.Open(oOcc.ReferencedDocumentDescriptor.FullDocumentName, False)
			oPartComp = oPartDoc.ComponentDefinition
			oFeat = oPartComp.Features.RectangularPatternFeatures.Item(FeatureName)
		End If 
		n = n + 1
	Next
	
	'[ adds pattern into the assembly
		Dim oOccPtrns As OccurrencePatterns = oAsmComp.OccurrencePatterns
		Dim oPtrn As OccurrencePattern
		oPtrn = oOccPtrns.AddFeatureBasedPattern(oPattern, oFeat)
		oPtrn.Name = PatternBrowserName
	']


Best,

Felix

2 REPLIES 2
Message 2 of 3

Hi @felix.cortes5K3Y2 

You'll need to create a proxy for your partfeature in order to use it in the assembly. If you just go through the parts componentdefinition to get this pattern feature, there's no way of knowing which feature to use if there are multiple occurrences of the same part in your assembly. I hope this makes sense. So what you need to do is create a proxy through the specific occurrence containing the feature pattern that you want to use.

 

I've made some minor changes to the code, the main thing though is that it's now creating a proxy object of the partfeature pattern. Hope this helps 🙂

 

Dim BrowserName As String = "SERPENTINE SHOE" 'the part that needs to be pattern
Dim PatternBrowserName As String = BrowserName & "S" 'name of pattern that will be made
Dim FeatureName As String = "Shoe Pattern" 'name of the feature
Dim RefPartName As String = "SERPENTINE SPREADER FOR SHOE" 'name of the part with the feature

Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAsmComp As AssemblyComponentDefinition = oAsm.ComponentDefinition
Dim oOccPattern As OccurrencePattern
Dim PartExists As Boolean = False
Dim PatternExists As Boolean = False
Dim oPattern As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
Dim RefExists As Boolean = False
Dim oPartComp As PartComponentDefinition
Dim oFeat As PartFeature
Dim oFeatProx As Object
For Each oOcc As ComponentOccurrence In oAsmComp.Occurrences
	If oOcc.Name = BrowserName Then
		PartExists = True
		oPattern.Add(oOcc)
	Else If oOcc.Name = RefPartName Then
	RefExists = True
	oPartComp = oOcc.Definition
	oFeat = oPartComp.Features.RectangularPatternFeatures.Item(FeatureName)
	oOcc.CreateGeometryProxy(oFeat, oFeatProx)
	End If
Next
If RefExists AndAlso PartExists
	'[ adds pattern into the assembly
	Dim oOccPtrns As OccurrencePatterns = oAsmComp.OccurrencePatterns
	Dim oPtrn As OccurrencePattern = oOccPtrns.AddFeatureBasedPattern(oPattern, oFeatProx)
	oPtrn.Name = PatternBrowserName
	']
End If
Message 3 of 3

Thanks Joel, I wouldn't have been able to guess that!

 

Best,

Felix

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report