Hi @Anonymous . I updated my code to include your Item names, Parameter names, & Pattern name.
I also added a Try...Catch...End Try statement in there to try and reduce the possible errors.
If you run that code a second time on the same file, it was probably trying to re-create the same named pattern a second time, which would throw an error, because it already exists. The Try Catch statement should take care of that.
As far as the automatic updating not working. Within the local rule, make sure the text after "oDV = " exactly matches the spelling and case of the name of your local Parameter. When its done right, the text should turn blue (by default, this means it recognizes that word as representing a Parameter). Don't put any quote marks around the names of the parameters.
Now about the multiplying by 10 issue. Depending on what you're doing, I believe Inventor, uses centimeters for its distance units, by default, unless you specify different Units where the numbers are being used.
When dealing with Parameters, it already know to look at the Units column of the Parameters chart to know what Units it is supposed to be, but raw numbers in iLogic, aren't seen the same way.
About flipping the direction of an existing pattern. I have included a section in the code, where it checks to see if the Pattern already exists. If it does, it asks you a couple of questions about what you want to do with it.
First you can choose to delete it. This opens it up for the opportunity to either run your other external rule automatically with that line of code I have commented out, or simply place that deletion code right there.
Next it asks you if you want to Edit the Pattern. If Yes, it asks you a series of questions so you can change its values.
Amongst those questions it asks you if you want to flip the direction of the pattern.
I didn't complete all possible questions, because I wasn't sure if you wanted to use them or not.
But there there as an example of the possibility, for your convenience.
You can delete this whole Edit section if you want. Or just comment it out.
You'll notice too that I changed from calling out the Axis by item number, to calling them by name.
That's an odd behavior in iLogic & VBA. The tool tip for all the Item's says its looking for an Integer, but you can most often put the String type name of the item in that space instead, even though the instructions don't mention it.
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MessageBox.Show("THIS RULE '" & iLogicVb.RuleName & "' ONLY WORKS FOR ASSEMBLY DOCUMENTS.", "WRONG DOCUMENT TYPE", MessageBoxButtons.OK, MessageBoxIcon.Stop)
Return
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
Dim oOccs As ComponentOccurrences = oADef.Occurrences
Dim oUParams As UserParameters = oADef.Parameters.UserParameters
Try
Dim oPatt As RectangularOccurrencePattern = oADef.OccurrencePatterns.Item("PADR_PARAFUSOS_INOX")
Dim oDelete As MsgBoxResult = MsgBox("An OccurrencePattern named '" & oPatt.Name & "' already exists." & vbNewLine &
"Do you want to Delete it and its Components?", vbYesNo + vbQuestion, "PATTERN EXISTS - DELETE?")
If oDelete = vbYes Then
'iLogicVb.RunExternalRule("Name Of Rule To Delete Them")
'Or
oPatt.Delete
'If the following names don't match actual items exactly, it will throw an error.
' Dim oOcc1 As ComponentOccurrence = oOccs.ItemByName("4349:1")
' Dim oOcc2 As ComponentOccurrence = oOccs.ItemByName("0157:1")
' oOcc1.Delete
' oOcc2.Delete
'This can become difficult when more than one of the same item is in the same assembly.
'Instead you can use a loop code which searches for a name that 'contains' some text, like this
For Each oOcc As ComponentOccurrence In oOccs
If oOcc.Name.Contains("4349") Or oOcc.Name.Contains("0157") Then
oOcc.Delete
End If
Next
End If
Dim oEdit As MsgBoxResult = MsgBox("Do you want to Edit its Properties or Values?", vbYesNo + vbQuestion, "EDIT IT?")
If oEdit = vbYes Then
'Perhaps use a series of InputBox or InputListBox lines of code here to offer the user the ability to change its values
'Something like the following
'ColumnCount is Read Only, so to change its value, change the value of the Parameter being used by it
Dim oColumnCount As Parameter = oPatt.ColumnCount
oColumnCount.Value = InputBox("Enter New Column Count.")
Dim oAxisList As List(Of String)
oAxisList.Add("X Axis")
oAxisList.Add("Y Axis")
oAxisList.Add("Z Axis")
oPatt.ColumnEntity = InputListBox("Choose Axis For Column Entity.", oAxisList, oAxisList.Item(1), "COLUMN ENTITY")
oPatt.ColumnEntityNaturalDirection = InputRadioBox("Use Column Entity Natural Direction?", True, False)
'ColumnOffset is Read Only, so to change its value, change the value of the Parameter being used by it
Dim oColumnOffset As Parameter = oPatt.ColumnOffset
oColumnOffset.Value = InputBox("Enter New Column Offset.")
'Etc
ElseIf oEdit = vbNo Then
Return
End If
Catch
'It doesn't exist yet, so create it
Dim oTO As TransientObjects = ThisApplication.TransientObjects
Dim oObjects As ObjectCollection = oTO.CreateObjectCollection
oObjects.Add(oOccs.ItemByName("4349:1"))
oObjects.Add(oOccs.ItemByName("0157:1"))
Dim oRowEntity As Object = oADef.WorkAxes.Item("Z Axis")
Dim oColumnEntity As Object = oADef.WorkAxes.Item("Y Axis")
'You may also want to include a few lines here which check to make sure these UserParameters exist.
' Dim oColumnOffset As UserParameter =
' Dim oColumnCount As UserParameter =
Dim oRowOffset As UserParameter = oUParams.Item("DIST_SUP")
Dim oRowCount As UserParameter = oUParams.Item("QTD_SUP")
Dim oPatt As RectangularOccurrencePattern
oPatt = oADef.OccurrencePatterns.AddRectangularPattern(oObjects, oColumnEntity, True, 0, 1, oRowEntity, True, oRowOffset, oRowCount)
oPatt.Name = "PADR_PARAFUSOS_INOX"
End Try
iLogic is fairly easy to pick up if you're really interested in it.
VBA is perhaps a little bit more involved, because it covers more ground, since it has been around for a really long time and is also used by Microsoft for their Office softwares.
But they are fairly similar in many aspects. iLogic is just a simplified programming platform that Autodesk built into Inventor to help make it easier for users new to programming to get started into using code to manipulate stuff within its software.
Actualy Inventor's help files aren't a bad place to get started. It seems a bit more focussed on VBA than iLogic, but since things in iLogic are so similar to corresponding things in VBA, its fairly easy to put the two togeather.
Check out these locations in the online help especially, to help you figure out what certain program words mean.
Inventor 2020 online Help

Wesley Crihfield

(Not an Autodesk Employee)