Here is another rule you can try. It will also attempt to delete the rule from the drawing document associated with each of the main assemblies referenced documents. I left two options for you to specify the name of the rule you want to find & delete. You can either just use a simple InputBox, and enter the name manually (just un-comment that line of code), or you can have it get all rules, create a list of their names, then present the list for you to choose from, as in the code posted above. In this code, I assume the first rule name you specify is the one you want to find/delete throughout main assembly and all other documents.
Sub Main
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Dim oRuleName As String 'specify once, then use that for all
'[ Option 1 - for getting name of rule to find/delete
'oRuleName = InputBox("Enter Name Of Rule To Delete.", "Rule Name", "")
']
'[ Option 2 for getting name of rule to find/delete
Dim oRuleNames As New List(Of String)
Dim oARules As IEnumerable = oAuto.Rules(oADoc)
For Each oRule As iLogicRule In oARules
oRuleNames.Add(oRule.Name)
Next
oRuleName = InputListBox("", oRuleNames, "", "Choose Rule to Delete.", "Rule Names")
']
If String.IsNullOrEmpty(oRuleName) Then Exit Sub
Try
oAuto.DeleteRule(oADoc, oRuleName)
Catch
End Try
DeleteRuleFromDrawing(oADoc, oRuleName)
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
Try
oAuto.DeleteRule(oRefDoc, oRuleName)
Catch
End Try
DeleteRuleFromDrawing(oRefDoc, oRuleName)
Next
End Sub
Sub DeleteRuleFromDrawing(oDoc As Document, oRName As String)
Dim oDrawingFile As String = System.IO.Path.ChangeExtension(oDoc.FullFileName, ".dwg")
If System.IO.File.Exists(oDrawingFile) Then
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Open(oDrawingFile, False)
Try
iLogicVb.Automation.DeleteRule(oDDoc, oRName)
oDDoc.Save2(False)
oDDoc.Close(True)
Catch
End Try
End If
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you want and have time, I would appreciate your Vote(s) for My IDEAS 💡or you can Explore My CONTRIBUTIONS
Wesley Crihfield

(Not an Autodesk Employee)