Community,
Using iLogic in an assembly, I can create a rectangular pattern of a component using Patterns.AddRectangular.
How do you edit the Pattern quantity and spacing after it is created?
So far, my solution has been to delete the pattern, place the component again, and create the pattern again. This can't be the most efficient method. I have not been able to find any iLogic code examples where a pattern is edited, only created. I am sure the editing solution could be applied to a circular pattern in the event I need that in the future.
Thanks for your time and attention. I look forward to the replies.
Regards,
Jerry
Solved! Go to Solution.
Solved by jkorson. Go to Solution.
Solved by Curtis_Waguespack. Go to Solution.
Solved by HermJan.Otterman. Go to Solution.
Hello Jerry,
After You create the pattern you get a RectangularOccurrencePattern, this has properies like RowCount.value and RowOffset.value
Thanks for the reply and the object to search. It is interesting that there are so many "creation" examples in the iLogic editor, but so few examples for "editing" what was has been created.
After a couple hours of searching, I finally found examples that demonstrate how to flip a rectangular pattern.
Thank you @Anonymous and @frederic.vandenplas for posting those solutions.
From these examples and Herm's tips, I should be able to change quantity and spacing of the component rectangular pattern.
Thanks again, all.
Kind regards,
Jerry
When creating the rectangular pattern with Patterns.AddRectangular, I used parameters for the row and column quantity and spacing.
Dim rectPattern = Patterns.AddRectangular( _ "RectPattern2", "WR157_01", _ ColCnt, ColSpc, Nothing, "X Axis", columnNaturalDirection := True, _ rowCount := RowCnt, rowOffset := RowSpc, rowEntityName := "Y Axis", rowNaturalDirection := True)
These evaluated to numbers as shown in the Parameters dialog box.
Is it possible to have created the pattern with the Parameter names instead of their values as the Equation?
Regards,
Jerry
Look at my assembly... 2019
Thanks, @HermJan.Otterman!
Ironically, I developed an almost identical form in between posts. This is very helpful, Herm.
Next, I need to research how to control the name of the pattern, so that it can be searched.
Then, how to change or replace the part (component) being patterned. Although I suspect it may be just a matter of deleting the pattern, place the new component, and then make a new pattern.
Thanks again.
Jerry
Circling back to this request. I discovered some interesting differences or limitations.
When using an iLogic Snippet to create a rectangular pattern, you can reference parameter names, but only their values will be used by the pattern.
Dim oPatt = Patterns.AddRectangular("BackerPattern", "Backer_01", BP_Col_Qty, BP_Col_Spc, Nothing, "X Axis", columnNaturalDirection := True, rowCount := BP_Row_Qty, rowOffset := BP_Row_Spc, rowEntityName := "Y Axis", rowNaturalDirection := True)
Notice the pattern is using the User Parameter values in the equations.
Quoting the parameter names in the iLogic snippet results in errors.
However, if the pattern is created using VB.NET code, you can use parameter names and the equation results are the parameter names.
oPatt = oAsmDef.OccurrencePatterns.AddRectangularPattern(oObjects, oColumnEntity, True, "BP_Col_Spc", "BP_Col_Qty", oRowEntity, True, "BP_Row_Spc", "BP_Row_Qty")
Note the User Parameter names used by the rectangular pattern.
It is also peculiar why the iLogic snippet requires extra text to identify some arguments ( columnNaturalDirection, rowCount, rowOffset, rowEntityName, and rowNaturalDirection) as shown in the example above. Text is not required to identify arguments for columnCount, columnOffset, or columnEntityName
I have attached a part file and the assembly with the iLogic and VB code for others to confirm my results. The rules are suppressed so that they do not automatically run when changing user parameters.
I hope this is helpful for others.
Regards,
Jerry
Hi @JBerns
See the attach 2020 file for an example of how to create and edit the pattern.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Thanks, @Curtis_Waguespack !
I knew there had to be a way to edit the pattern. Thanks for sharing the examples, they were very helpful.
Can you explain why your 'Create' rule works in Inv2020, but not in Inv2019? An error occurs when executing the line to change oPatt.Pattern.ColumnCount.Name.
Error message:
The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Regards,
Jerry
Hi @JBerns ,
I'm not really sure why it would not work in 2019, there might have been something added, but I don't have that version installed to be able to look into it.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Hi @JBerns
On second thought, it looks like maybe they let us grab the pattern via iLogic and use API calls on it after it is obtained, maybe that was made available as part of 2020
I suspect this version will likely work in 2019, the only part that is using ilogic calls in the part that actually creates the pattern, it's using the API to delete the pattern and to name the pattern and parameters.
I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com
Sub Main() sPattName = "BackerPattern" Dim oPatterns As OccurrencePatterns oPatterns = ThisApplication.ActiveDocument.ComponentDefinition.OccurrencePatterns Try oPatterns.Item(sPattName).Delete Catch ex As Exception 'MsgBox("Error: " & ex.Message) End Try Dim oPatt = Patterns.AddRectangular("BackerPattern", "Backer_01", _ 4, 12, Nothing, "X Axis", columnNaturalDirection := True, rowCount := 3, rowOffset := 8, rowEntityName := "Y Axis", rowNaturalDirection := True) Dim oPattern As RectangularOccurrencePattern oPattern = ThisApplication.ActiveDocument.ComponentDefinition.OccurrencePatterns.Item(sPattName) oPattern.Name = sPattName oPattern.ColumnCount.Name = "BP_Col_Qty" oPattern.ColumnOffset.Name = "BP_Col_Spc" oPattern.RowCount.Name = "BP_Row_Qty" oPattern.RowOffset.Name = "BP_Row_Spc" ThisApplication.ActiveView.Fit End Sub
Inventor Forum links: Inventor iLogic , API and Customization Forum | Inventor Ideas Forum | General Inventor Forum
Ackn. Thanks, Curtis.
Using 2019, I have been able to create the pattern with parameter names in the equations. That was most important.
Now with your code, I can modify the pattern as needed.
We hope to switch to 2021 versions soon. Thanks again!
Kind regards,
Jerry
EDIT: I figured out what I was doing wrong, so I will include the original post and explain the solution at the end.
Original post:
I thought the code shared in this thread was exactly what I needed, but I keep getting an error at line 36 (when changing the components used in the pattern to the updated object collection) that says "The parameter is incorrect"
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oChannels As ObjectCollection
oChannels = ThisApplication.TransientObjects.CreateObjectCollection
If oChannels.Count > 0
oChannels.Clear
End If
'add appropriate channels to object collection
Select Num_Splits
Case 0
oChannels.Add("Channel HT")
Case 1
oChannels.Add("Channel H1")
oChannels.Add("Channel 1T")
Case 2
oChannels.Add("Channel H1")
oChannels.Add("Channel 12")
oChannels.Add("Channel 2T")
Case 3
oChannels.Add("Channel H1")
oChannels.Add("Channel 12")
oChannels.Add("Channel 23")
oChannels.Add("Channel 3T")
End Select
Dim oPatt As RectangularOccurrencePattern
'get pattern
oPatt = oDoc.ComponentDefinition.OccurrencePatterns.Item("Channel Pattern")
'change pattern components
oPatt.ParentComponents = oChannels
InventorVb.DocumentUpdate()
Num_Splits is a user parameter that is calculated in another rule and I have verified that the object collection repopulates correctly when that parameter changes.
Solution:
I didn't properly build the object collection revised code below
Dim oDoc As AssemblyDocument
oDoc = ThisApplication.ActiveDocument
Dim oChannels As ObjectCollection
oChannels = ThisApplication.TransientObjects.CreateObjectCollection
If oChannels.Count > 0
oChannels.Clear
End If
'add appropriate channels to object collection
Select Num_Splits
Case 0
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel HT"))
Case 1
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel H1"))
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel 1T"))
Case 2
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel H1"))
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel 12"))
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel 2T"))
Case 3
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel H1"))
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel 12"))
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel 23"))
oChannels.Add(oDoc.ComponentDefinition.Occurrences.ItemByName("Channel 3T"))
End Select
Dim oPatt As RectangularOccurrencePattern
'get pattern
oPatt = oDoc.ComponentDefinition.OccurrencePatterns.Item("Channel Pattern")
'change pattern components
oPatt.ParentComponents = oChannels
InventorVb.DocumentUpdate()
Hi @agrove72Y9W. I think you are missing a keyword in your code.
Try changing this line:
Select Num_Splits
...to this:
Select Case Num_Splits
I assume that 'Num_Splits' is the name of a parameter within the 'local' document, and it has a numeric value? If so, are the Units of that numeric parameter set to Unitless?
Wesley Crihfield
(Not an Autodesk Employee)
So I have a large assembly with several layers of code. The issue I have has to do with updating and running code and the wrong time. The best solution I can come up with is to pull the parameter for the length of a pattern directly from the pattern as the parameter gets updated before the patern and then I get errors because my for loop is no the right length. How do I get ColumnCount out of the existing pattern. Sorry, I am an novice at vb objects.
I tried this:
ToPatternName = "TopLinks"
ToPattern = oDoc.ComponentDefinition.OccurrencePatterns.Item("TopLinks")
ToPattern.Name = ToPatternName
Test5 = ToPattern.ColumnCount
MessageBox.Show(Test5,"Test 5")
But it did not work.
Also this error "The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))" I see when you are trying to change an element in a pattern that does not exist. For example I turn all of the elements in pattern to 'not suppressed', if the element qty is wrong is throws this fault. Also if you try to suppress the first element in a pattern, which is not allowed.
Hi @trevorauman
So it looks like you were nearly there when trying to retrieve the column qty. The error was you were retrieving a parameter object and not a Integer/whole number value.
I found out the issue ("Missing the property called value") not by looking at the error message but by correctly declaring each object and looking at the tool tip description of what that object is by hovering the mouse over the object. This is why it is important to declare objects fully as it really is a help in diving into each object but also in trouble shooting.
The API help is a great place to explore what each method and properties do and also to find some examples.
Link to API help for column count parameter
Link to API Help for column count parameter methods and properties
Working Code:
Dim oDoc As AssemblyDocument = ThisDoc.Document
ToPatternName = "TopLinks"
Dim ToPattern As RectangularOccurrencePattern = oDoc.ComponentDefinition.OccurrencePatterns.Item(ToPatternName)
Dim Test5 As Integer = ToPattern.ColumnCount.Value
MessageBox.Show(Test5,"Test 5")
For anyone in the future that is looking at this post, I found that the iLogic "add rectangular pattern" snippet can only handle an integer or a double (needs to be a value of some sort). What I have found is you can still use the the iLogic snippet and add some additional code to insert the parameter as an expression. See snip below.
Patterns.AddRectangular("BLADE PATTERN",
{"BLADE", "BACK-RIGHT BLADE SCREW", "FRONT-RIGHT BLADE SCREW", "BACK-LEFT BLADE SCREW", "FRONT-LEFT BLADE SCREW" },
Parameter("NO_OF_BLADES"), Parameter("Sb"), "", "Y Axis")
Dim oPattern As RectangularOccurrencePattern
'Find pattern through API
oPattern = ThisApplication.ActiveDocument.ComponentDefinition.OccurrencePatterns.Item("BLADE PATTERN")
'Change the Column count expression to a parameter
oPattern.ColumnCount.Expression = Parameter.Param("NO_OF_BLADES").Name
'Change the column offset expression to a parameter
oPattern.ColumnOffset.Expression = Parameter.Param("Sb").Name
Just as an additional example, using the Inventor API method for creating a rectangular occurrence pattern (OccurrencePatterns.AddRectangularPattern), we can actually name the ModelParameters that this new pattern will create for those numerical values (column offset, column count, row offset, row count). Then, you could either control those named ModelParameters directly later, or if the named UserParameters for those values already existed before the pattern was created, you could specify those parameter names directly in into those specifications when creating the pattern, instead of having to do so afterwards. This is because it allows us to specify either a numerical value directly, or we can specify a String. And the String can not only include both the numerical value and the units of the value, but it can also contain the name we want to assign to the parameter that gets created. And since this is a String, instead of a numerical value with units after it, we can just specify the name of other existing UserParameters (or ModelParameters) into String values. Of course we can also change their names and or values / expressions after the pattern has been created, by accessing the Parameter objects associated with those specifications of the feature, as suggested earlier above, and below is one possible example of that, which goes with my following examples.
oNewOccPatt.ColumnCount.Name = "mColumnCount"
oNewOccPatt.ColumnCount.Expression = "ColumnCount"
Below is the Inventor API example which names the ModelParameters as they are being created.
Dim oPickedOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
If oPickedOcc Is Nothing Then Return
Dim oADef As AssemblyComponentDefinition = oPickedOcc.Parent
Dim oOccPatts As OccurrencePatterns = oADef.OccurrencePatterns
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oColl.Add(oPickedOcc)
Dim oNewOccPatt As RectangularOccurrencePattern = _
oOccPatts.AddRectangularPattern(oColl, oADef.WorkAxes.Item(1), True, _
"mColumnOffset = 6 in", "mColumnCount = 3 ul", oADef.WorkAxes.Item(2), True, _
"mRowOffset = 8 in", "mRowCount = 6 ul")
oNewOccPatt.Name = "Rect Pattern Of " & oPickedOcc.Name.Split(":").First
...and below is the same example that not only names the ModelParameters that it creates, but also supplies the names of existing UserParameters as the 'Expression' of the ModelParameters.
Dim oPickedOcc As ComponentOccurrence = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select a Component.")
If oPickedOcc Is Nothing Then Return
Dim oADef As AssemblyComponentDefinition = oPickedOcc.Parent
Dim oOccPatts As OccurrencePatterns = oADef.OccurrencePatterns
Dim oColl As ObjectCollection = ThisApplication.TransientObjects.CreateObjectCollection
oColl.Add(oPickedOcc)
Dim oNewOccPatt As RectangularOccurrencePattern = _
oOccPatts.AddRectangularPattern(oColl, oADef.WorkAxes.Item(1), True, _
"mColumnOffset = ColumnOffset", "mColumnCount = ColumnCount", oADef.WorkAxes.Item(2), True, _
"mRowOffset = RowOffset", "mRowCount = RowCount")
oNewOccPatt.Name = "Rect Pattern Of " & oPickedOcc.Name.Split(":").First
Just pointing out some alternatives.
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.