ilogic - Edit rectangular pattern

ilogic - Edit rectangular pattern

JBerns
Advisor Advisor
4,718 Views
24 Replies
Message 1 of 25

ilogic - Edit rectangular pattern

JBerns
Advisor
Advisor

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

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Accepted solutions (3)
4,719 Views
24 Replies
Replies (24)
Message 2 of 25

HermJan.Otterman
Advisor
Advisor

Hello Jerry,

 

After You create the pattern you get a RectangularOccurrencePattern, this has properies like RowCount.value and RowOffset.value

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 3 of 25

JBerns
Advisor
Advisor

@HermJan.Otterman,

 

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.

https://forums.autodesk.com/t5/inventor-customization/flipping-component-pattern-in-assemblies-with-...

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

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 4 of 25

JBerns
Advisor
Advisor

@HermJan.Otterman,

 

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.

2019-04-19_9-01-25.png

 

Is it possible to have created the pattern with the Parameter names instead of their values as the Equation?

2019-04-19_9-09-01.png

 

Regards,

Jerry

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 5 of 25

HermJan.Otterman
Advisor
Advisor
Accepted solution

Look at my assembly... 2019

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 6 of 25

JBerns
Advisor
Advisor

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

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 7 of 25

JBerns
Advisor
Advisor

@HermJan.Otterman,

 

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.

2020-03-03_iLogic_snippet.png

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.

2020-03-03_VB.png

 

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

 

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 8 of 25

Curtis_Waguespack
Consultant
Consultant
Accepted solution

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

EESignature

Message 9 of 25

JBerns
Advisor
Advisor

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

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
0 Likes
Message 10 of 25

Curtis_Waguespack
Consultant
Consultant

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

 

 

EESignature

0 Likes
Message 11 of 25

Curtis_Waguespack
Consultant
Consultant

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

 

EESignature

0 Likes
Message 12 of 25

jberns-newell
Contributor
Contributor

@Curtis_Waguespack 

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

 

0 Likes
Message 13 of 25

agrove72Y9W
Participant
Participant

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()
0 Likes
Message 14 of 25

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 25

trevorauman
Contributor
Contributor

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.

0 Likes
Message 16 of 25

trevorauman
Contributor
Contributor

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. 

0 Likes
Message 17 of 25

A.Acheson
Mentor
Mentor

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. 

AAcheson_0-1685209452826.png

 

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")

 

 

 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 18 of 25

jkorson
Enthusiast
Enthusiast
Accepted solution

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

 

jkorson_0-1723151339549.png

 

Message 19 of 25

WCrihfield
Mentor
Mentor

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

EESignature

(Not an Autodesk Employee)

Message 20 of 25

WCrihfield
Mentor
Mentor

Hi @t_fransman.  I do not know enough about the assembly components in your rectangular pattern to know how to extract a 'curve length' from them.  Creating a parameter sounds easy enough though.  Not sure what the 'multiple sketches' may have to do with this situation yet either.  Is there a parameter in the component that represents its overall length that could be retrieved, or does the component need to be physically measured within the context of the assembly?  Is the assembly component being patterned just a sketch in a part, with no solids or surfaces, and you need to get the length of a specific sketch line or profile in that part?  Maybe some screen captured images of what you are working with, along with some additional information about what you are trying to achieve would help us understand the situation better.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes