Create Ilogic To Delete All Rule In Assembly, Subassembly And Part

haphanthanhtam.work
Enthusiast

Create Ilogic To Delete All Rule In Assembly, Subassembly And Part

haphanthanhtam.work
Enthusiast
Enthusiast

I want have a Ilogic to delete all rule in assembly, subassembly and part
2.png

0 Likes
Reply
Accepted solutions (1)
490 Views
3 Replies
Replies (3)

Andrii_Humeniuk
Advisor
Advisor
Accepted solution

Hi @haphanthanhtam.work . This rule removes all internal rules in all documents of the assembly. Use it as an external rule.

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	Dim oAuto As IiLogicAutomation = iLogicVb.Automation
	If Not TypeOf oDoc Is AssemblyDocument Then Exit Sub
	Dim oAsmDoc As AssemblyDocument = oDoc
	oAuto.DeleteAllRules(oAsmDoc)
	Dim oRefDocs As DocumentsEnumerator = oAsmDoc.AllReferencedDocuments
	Dim oOccs As ComponentOccurrences = oAsmDoc.ComponentDefinition.Occurrences
	Dim oPBar As Inventor.ProgressBar = ThisApplication.CreateProgressBar(False, oRefDocs.Count, "Copy ryles...")
	Dim i As Integer = 1
	oPBar.Message = "Loading..."
	Dim oTM As Transaction = ThisApplication.TransactionManager.StartTransaction(oAsmDoc, "RemoveRulesInAllDocs")
	For Each oRefDoc As Document In oRefDocs
		oPBar.Message = "Remove rules in docs. Progress " & i & " of " & oRefDocs.Count & "."
		If oOccs.AllReferencedOccurrences(oRefDoc).Count > 0 Then
			If Not oRefDoc.IsModifiable Then Continue For
			oAuto.DeleteAllRules(oRefDoc)
			oRefDoc.Save()
		End If
		oPBar.UpdateProgress
		i += 1
	Next
	oPBar.Close()
	oTM.End()
End Sub

Andrii Humeniuk - CAD Coordinator, Autodesk Certified Instructor

LinkedIn | My free Inventor Addin | My Repositories

Did you find this reply helpful ? If so please use the Accept as Solution/Like.

EESignature

WCrihfield
Mentor
Mentor

Have you tried just that one line of code yet.  There are two built-in methods for deleting all internal iLogic rules.  One is limited to just the input document, and will go no deeper.

iLogicVb.Automation.DeleteAllRulesInDocument(oDoc)

WCrihfield_1-1699300512540.png

 

The other says essentially the same thing as the button in the ribbon (works on the input document, and if its an assembly, all referenced documents).

iLogicVb.Automation.DeleteAllRules(oDoc)

WCrihfield_0-1699300447153.png

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

gilhoej_teknik
Community Visitor
Community Visitor

Thx you're a life saver. Michael

0 Likes

Type a product name