So looking this over, and figured I would attempt to help by opening up MY help file and pulling it from there, only to find that it was also missing from my help file...
But, being a curious Jerk, I decided to get my hands dirty figuring it out on my own. Because it was not as easy as I had anticipated, and because JLetch is using the same Inventor version as I am, I decided to make a functional example zip file that contains a small test assembly (with 2 parts), and an iLogic Rule that is commented (hopefully) well enough to explain all of the Component Pattern types that there are.
I know that it isn't the page that you're looking for, but I figured that if anyone else ever attempted to find an example of this, it would help to go on and post it all in one place.
Hope this solves it for ya.
Assembly / Part files are Attached
Below is the iLogic Code that I'm using (*Mind the line breaks, if the text window shrinks) :
Public Sub Main()
' Test to make sure this is being run from an Assembly Document
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
Exit Sub
End If
' Creating the objects that represent our Active Assembly Document
' and our Component Definition object
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition
oCompDef = oDoc.ComponentDefinition
' If we've used this code before, then we want to clear out
' any patterns that we've made thus far.
While oCompDef.OccurrencePatterns.Count > 0
oCompDef.OccurrencePatterns.Item(1).Delete
End While
' Because this is a test, some of the information below will be
' slightly more hard-coded than what you would expect to see in
' production. This test requires no user interaction.
' We need to define our two Components, and the ComponentDefinition
' for the one part that contains the features that we'd like to use
' to build our Associative Feature Assembly Pattern from.
Dim patternOcc As ComponentOccurrence
Dim featureOcc As ComponentOccurrence
Dim oPartCompDef As PartComponentDefinition
' In this test we only use the Rectangular Pattern Feature, though
' I have taken the liberty to establish a few placeholders for
' the Circular Pattern Feature / Proxy, they can be ignored.
' The Proxy Geometry is only used if we end up wanting to create
' an Associative Feature Pattern, however it must exist if we do.
''' *****************************************************************
''' * To read more about Proxies, search for 'Proxies' (without quotes)
''' * in the Index of the Inventor API Help File. You can also find
''' * the page directly by going to the Overview Articles page, and
''' * clicking on Objects in Context - Proxies in the General Concepts
''' * listing.
''' *****************************************************************
Dim oProxyObject As Object
Dim oRectPatternFeature As RectangularPatternFeature
Dim oRectPatternFeatureProxy As RectangularPatternFeatureProxy
Dim oCircPatternFeature As CircularPatternFeature
Dim oCircPatternFeatureProxy As CircularPatternFeatureProxy
' We still need to actually point to our part occurrences, and we
' do so below.
patternOcc = oCompDef.Occurrences.ItemByName("Part2:1")
featureOcc = oCompDef.Occurrences.ItemByName("Part1:1")
' Let's allow the user to choose the Pattern Type.
Dim patternType As String
Dim patternTypes(2) As String
patternTypes(0) = "Rectangular"
patternTypes(1) = "Circular"
patternTypes(2) = "Associative"
patternType = InputListBox("Please select a Pattern Type", patternTypes, patternTypes, Title := "Pattern Selector", ListName := "Pattern Types")
If patternType = "" Then
MessageBox.Show("You didn't select anything! What's wrong with you?", "You've Hurt Inventor's Feelings :(")
Exit Sub
End If
' Feel free to cheat and skip this If / Then statement, if you're
' not ready to learn about / deal with the Associative Feature Pattern
' Type / Proxy Geometry. :D
If patternType = "Associative" Then
' Here we are hard coding it so that it grabs the only feature pattern
' that exists on the part. In this scenario, the oCircPatternProxy is
' never needed.
oPartCompDef = featureOcc.Definition
oRectPatternFeature = oPartCompDef.Features.RectangularPatternFeatures.Item(1)
' Now we need to make our Proxy Geometry!
' Pay attention to this step. We create the proxy using the method that
' is found on the Part Occurrence, which is found inside of the Occurrence
' list in our Assembly! This essentially gives us some geometrical context
' that jives on the Assembly level, rather than pertaining to the specifics
' of the Part Geometry.
Call featureOcc.CreateGeometryProxy(oRectPatternFeature, oRectPatternFeatureProxy)
' Because in the real world, you could end up with either a Circular Pattern Feature
' or a Rectangular, and because I want to end up using only ONE call statement to my
' sub-routine, we will make oProxyObject = the one defined proxy objects out of the
' two (despite the fact that we already know that we're defining only ONE in this
' example.
If Not oCircPatternFeatureProxy Is Nothing Then
oProxyObject = oCircPatternFeatureProxy
Else
oProxyObject = oRectPatternFeatureProxy
End If
End If
' Let's take all of the information gathered above and send it off to a Sub-Routine
' that actually makes the pattern.
Call CreatePattern(patternType, oDoc, patternOcc, oProxyObject)
End Sub
' This Sub requires a String with the user selected Pattern Type, the Assembly our Parts reside in, the Occurrence that we wish to Pattern,
' and the Geometry Proxy that we created if the user decided to create an Associative Feature Pattern.
Public Sub CreatePattern(targetPatternType As String, targetAssembly As AssemblyDocument, targetOcc As ComponentOccurrence, targetProxy As Object)
' Because this test requires no human interaction, we need to state
' the direction of our soon to be made patterns. In this case I have opted
' to use the default Work-Axes to do this.
Dim axisX As WorkAxis
Dim axisY As WorkAxis
Dim axisZ As WorkAxis
' At this point I decided that I would attempt to make a Golden Axe joke because there aren't enough
' Golden Axe references in iLogic Code examples, but it fell a bit flat. Perhaps next time...
Dim goldenAxis As WorkAxis
' This loops through all of the axes in our assembly, and will assign
' our variables above to the appropriate axis.
For Each goldenAxis In targetAssembly.ComponentDefinition.WorkAxes
Select Case goldenAxis.Name
Case "X Axis"
axisX = goldenAxis
Case "Y Axis"
axisY = goldenAxis
Case "Z Axis"
axisZ = goldenAxis
End Select
Next
' Just like how our Associative Feature Pattern requires the Proxy Geometry of the
' feature used to guide the pattern, ALL patterns need a similar reference to the
' occurrences that will be patterned.
'
' This is done much with many of the same intentions as the Proxy stuffs. We can't
' simply tell the assembly that we want to pattern an occurrence, without any context
' of what that occurrence is doing in regards to our Assembly. The ObjectCollection
' is simply an easy way of storing several objects (in this case - Occurrences) in
' one easy to find place.
''' *****************************************************************
''' * To learn more about geometry & the API in Inventor, refer to the following link:
''' * http://modthemachine.typepad.com/files/mathgeometry.pdf
''' *****************************************************************
Dim oObCollection As ObjectCollection
oObCollection = ThisApplication.TransientObjects.CreateObjectCollection
' In this test, we only add one Occurrence.
Call oObCollection.Add(targetOcc)
' Below we create an easy entry point for creating a new Pattern.
Dim oOccPatterns As OccurrencePatterns
oOccPatterns = targetAssembly.ComponentDefinition.OccurrencePatterns
' Based on the user's selection, we'll create a specific type of Pattern.
Select Case targetPatternType
Case "Rectangular"
' Note that this is using the X and Y axis as guides, and shows the range of how math behaves
' for this Pattern Method. Please reference the OccurrencePatterns portion of the Inventor API Help
' file for a full listing and explanation of what each argument pertains to.
' Note : If you wanted to have only a single direction Rectangular Pattern, you would end up
' with something that looks like :
'
' Call oOccPatterns.AddRectangularPattern(oObCollection, axisX, True, 2.54, 3)
Call oOccPatterns.AddRectangularPattern(oObCollection, axisX, True, 2.54, 3, axisY, True, "5 in", "3 ul")
Case "Circular"
' WOW! That's a lot of instances! I did this to show just how Inventor is patterning out
' the elements inside of a Circular Pattern. If you were to use the Angle Measuring tool
' along the outside (or inside) edge of the part, you would see that they differ by the
' angle specified in the Angle Offset field. Play around with the values to see it work!
Call oOccPatterns.AddCircularPattern(oObCollection, axisZ, False, "1 deg", "90 ul")
Case "Associative"
' Because we do a lot of the work ahead of time to make sure that this Pattern works,
' it results in having the simplest of methods. It will result in the patterned elements
' mimicking the pattern of the feature specified way up in the code above.
Call oOccPatterns.AddFeatureBasedPattern(oObCollection, targetProxy)
Case Else
End Select
End Sub
Below is the VBA version of the code above for debugging / stepping (* Difference in code comes down to the Pattern Selection window. There isn't one and it will need to be manually set in the code!!!)
Public Sub PatternTest()
' Test to make sure this is being run from an Assembly Document
If ThisApplication.ActiveDocument.DocumentType <> kAssemblyDocumentObject Then
Exit Sub
End If
' Creating the objects that represent our Active Assembly Document
' and our Component Definition object
Dim oDoc As AssemblyDocument
Set oDoc = ThisApplication.ActiveDocument
Dim oCompDef As AssemblyComponentDefinition
Set oCompDef = oDoc.ComponentDefinition
' If we've used this code before, then we want to clear out
' any patterns that we've made thus far.
While oCompDef.OccurrencePatterns.Count > 0
oCompDef.OccurrencePatterns.Item(1).Delete
Wend
' Because this is a test, some of the information below will be
' slightly more hard-coded than what you would expect to see in
' production. This test requires no user interaction.
' We need to define our two Components, and the ComponentDefinition
' for the one part that contains the features that we'd like to use
' to build our Associative Feature Assembly Pattern from.
Dim patternOcc As ComponentOccurrence
Dim featureOcc As ComponentOccurrence
Dim oPartCompDef As PartComponentDefinition
' In this test we only use the Rectangular Pattern Feature, though
' I have taken the liberty to establish a few placeholders for
' the Circular Pattern Feature / Proxy, they can be ignored.
' The Proxy Geometry is only used if we end up wanting to create
' an Associative Feature Pattern, however it must exist if we do.
' *****************************************************************
' * To read more about Proxies, search for 'Proxies' (without quotes)
' * in the Index of the Inventor API Help File. You can also find
' * the page directly by going to the Overview Articles page, and
' * clicking on Objects in Context - Proxies in the General Concepts
' * listing.
' *****************************************************************
Dim oProxyObject As Object
Dim oRectPatternFeature As RectangularPatternFeature
Dim oRectPatternFeatureProxy As RectangularPatternFeatureProxy
Dim oCircPatternFeature As CircularPatternFeature
Dim oCircPatternFeatureProxy As CircularPatternFeatureProxy
' We still need to actually point to our part occurrences, and we
' do so below.
Set patternOcc = oCompDef.Occurrences.ItemByName("Part2:1")
Set featureOcc = oCompDef.Occurrences.ItemByName("Part1:1")
' Let's allow the user to choose the Pattern Type.
Dim patternType As String
' patternType = "Rectangular"
' patternType = "Circular"
patternType = "Associative"
' Feel free to cheat and skip this If / Then statement, if you're
' not ready to learn about / deal with the Associative Feature Pattern
' Type / Proxy Geometry. :D
If patternType = "Associative" Then
' Here we are hard coding it so that it grabs the only feature pattern
' that exists on the part. In this scenario, the oCircPatternProxy is
' never needed.
Set oPartCompDef = featureOcc.Definition
Set oRectPatternFeature = oPartCompDef.Features.RectangularPatternFeatures.Item(1)
' Now we need to make our Proxy Geometry!
' Pay attention to this step. We create the proxy using the method that
' is found on the Part Occurrence, which is found inside of the Occurrence
' list in our Assembly! This essentially gives us some geometrical context
' that jives on the Assembly level, rather than pertaining to the specifics
' of the Part Geometry.
Call featureOcc.CreateGeometryProxy(oRectPatternFeature, oRectPatternFeatureProxy)
' Because in the real world, you could end up with either a Circular Pattern Feature
' or a Rectangular, and because I want to end up using only ONE call statement to my
' sub-routine, we will make oProxyObject = the one defined proxy objects out of the
' two (despite the fact that we already know that we're defining only ONE in this
' example.
If Not oCircPatternFeatureProxy Is Nothing Then
Set oProxyObject = oCircPatternFeatureProxy
Else
Set oProxyObject = oRectPatternFeatureProxy
End If
End If
' Let's take all of the information gathered above and send it off to a Sub-Routine
' that actually makes the pattern.
Call CreatePattern(patternType, oDoc, patternOcc, oProxyObject)
End Sub
' This Sub requires a String with the user selected Pattern Type, the Assembly our Parts reside in, the Occurrence that we wish to Pattern,
' and the Geometry Proxy that we created if the user decided to create an Associative Feature Pattern.
Public Sub CreatePattern(targetPatternType As String, targetAssembly As AssemblyDocument, targetOcc As ComponentOccurrence, targetProxy As Object)
' Because this test requires no human interaction, we need to state
' the direction of our soon to be made patterns. In this case I have opted
' to use the default Work-Axes to do this.
Dim axisX As WorkAxis
Dim axisY As WorkAxis
Dim axisZ As WorkAxis
' At this point I decided that I would attempt to make a Golden Axe joke because there aren't enough
' Golden Axe references in iLogic Code examples, but it fell a bit flat. Perhaps next time...
Dim goldenAxis As WorkAxis
' This loops through all of the axes in our assembly, and will assign
' our variables above to the appropriate axis.
For Each goldenAxis In targetAssembly.ComponentDefinition.WorkAxes
Select Case goldenAxis.Name
Case "X Axis"
Set axisX = goldenAxis
Case "Y Axis"
Set axisY = goldenAxis
Case "Z Axis"
Set axisZ = goldenAxis
End Select
Next
' Just like how our Associative Feature Pattern requires the Proxy Geometry of the
' feature used to guide the pattern, ALL patterns need a similar reference to the
' occurrences that will be patterned.
'
' This is done much with many of the same intentions as the Proxy stuffs. We can't
' simply tell the assembly that we want to pattern an occurrence, without any context
' of what that occurrence is doing in regards to our Assembly. The ObjectCollection
' is simply an easy way of storing several objects (in this case - Occurrences) in
' one easy to find place.
' *****************************************************************
' * To learn more about geometry & the API in Inventor, refer to the following link:
' * http://modthemachine.typepad.com/files/mathgeometry.pdf
' *****************************************************************
Dim oObCollection As ObjectCollection
Set oObCollection = ThisApplication.TransientObjects.CreateObjectCollection
' In this test, we only add one Occurrence.
Call oObCollection.Add(targetOcc)
' Below we create an easy entry point for creating a new Pattern.
Dim oOccPatterns As OccurrencePatterns
Set oOccPatterns = targetAssembly.ComponentDefinition.OccurrencePatterns
' Based on the user's selection, we'll create a specific type of Pattern.
Select Case targetPatternType
Case "Rectangular"
' Note that this is using the X and Y axis as guides, and shows the range of how math behaves
' for this Pattern Method. Please reference the OccurrencePatterns portion of the Inventor API Help
' file for a full listing and explanation of what each argument pertains to.
' Note : If you wanted to have only a single direction Rectangular Pattern, you would end up
' with something that looks like :
'
' Call oOccPatterns.AddRectangularPattern(oObCollection, axisX, True, 2.54, 3)
Call oOccPatterns.AddRectangularPattern(oObCollection, axisX, True, 2.54, 3, axisY, True, "5 in", "3 ul")
Case "Circular"
' WOW! That's a lot of instances! I did this to show just how Inventor is patterning out
' the elements inside of a Circular Pattern. If you were to use the Angle Measuring tool
' along the outside (or inside) edge of the part, you would see that they differ by the
' angle specified in the Angle Offset field. Play around with the values to see it work!
Call oOccPatterns.AddCircularPattern(oObCollection, axisZ, False, "1 deg", "90 ul")
Case "Associative"
' Because we do a lot of the work ahead of time to make sure that this Pattern works,
' it results in having the simplest of methods. It will result in the patterned elements
' mimicking the pattern of the feature specified way up in the code above.
Call oOccPatterns.AddFeatureBasedPattern(oObCollection, targetProxy)
Case Else
End Select
End Sub
If my solution worked or helped you out, please don't forget to hit the kudos button 🙂iLogicCode Injector:
goo.gl/uTT1IB