How to Delete all Ilogic and forms from PARTS

How to Delete all Ilogic and forms from PARTS

J.VandeMerckt
Advocate Advocate
1,491 Views
6 Replies
Message 1 of 7

How to Delete all Ilogic and forms from PARTS

J.VandeMerckt
Advocate
Advocate

Hi Everyone

 

I need to cleanup old imbedded Ilogic and forms in hundreds of files.

I'm trying to find a way to write a external Ilogic rule for this.


So I can add all these files in a assembly and activate the ilogic to delete all Ilogic in the underlying Parts.
Or open every individual part and run the Ilogic.
Either way is a huge time profit.

I don't need to filter through the Ilogic rules, they all need to be deleted.
Except of course external rules and forms.

I've tried finding something that resembles what I need but everything on the forum seems a bit too complex with too much specific uses.

Does anyone know how to start this or maybe has a link to another post on the forum?

Thank you in advance.
Br

Justin

0 Likes
Accepted solutions (1)
1,492 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @J.VandeMerckt.  Luckily that is a relatively easy task to automate...now.  Deleting the forms was only discovered fairly recently though.  Below is something you can try.  However, this will also delete the local Event Triggers settings in each document.  If you do not want to delete the local (in 'This Document' tab) Event Triggers settings in each document (which may also run external rules on events), then just delete or comment out those lines of code, as needed.

 

Sub Main
	Dim oDoc As Inventor.Document = ThisDoc.Document
	DeleteEventTriggersPropSet(oDoc)
	iLogicVb.Automation.DeleteAllRules(oDoc) 'deletes all rules in this and all referenced documents
	DeleteInternalForms(oDoc) 'run the custom Sub routine on the active document if needed
	Dim oAllRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments 'all levels
	If oAllRefDocs.Count > 0 Then
		For Each oRefDoc As Document In oAllRefDocs
			DeleteEventTriggersPropSet(oRefDoc)
			'iLogicVb.Automation.DeleteAllRulesInDocument(oDoc) 'only that document
			DeleteInternalForms(oRefDoc) 'run the custom Sub routine on this referenced document
		Next
	End If
	BlinkiLogicWindow 'runs custom Sub routine below
	If oDoc.RequiresUpdate Then oDoc.Update2(True)
	If oDoc.Dirty Then oDoc.Save2(True)
End Sub

Sub DeleteInternalForms(oDoc As Document)
	If oDoc Is Nothing OrElse oDoc.IsModifiable = False Then Return
	Dim oDocAttSets As AttributeSets = oDoc.AttributeSets
	If oDocAttSets.Count = 0 Then Return
	For Each oSet As AttributeSet In oDocAttSets
		If oSet.Name.StartsWith("iLogicInternalUi") Then
			Try : oSet.Delete : Catch : End Try
		End If
	Next 'oSet
End Sub

Sub DeleteEventTriggersPropSet(oDoc As Inventor.Document)
	Dim oSet As Inventor.PropertySet = Nothing
	If oDoc.PropertySets.PropertySetExists("{2C540830-0723-455E-A8E2-891722EB4C3E}", oSet) Then
		Try : oSet.Delete : Catch : End Try
	End If
End Sub

Sub BlinkiLogicWindow()
	Dim iLogicWindow As DockableWindow = ThisApplication.UserInterfaceManager.DockableWindows.Item("ilogic.treeeditor")
	iLogicWindow.Visible = False
	iLogicWindow.Visible = True
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) 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

J.VandeMerckt
Advocate
Advocate
Hi!

I will try this out out tomorrow.
Deleting local event triggers is actually a bonus.

Tnx a lot for the setup.
Br
Justin
0 Likes
Message 4 of 7

WCrihfield
Mentor
Mentor

Hi @J.VandeMerckt.  I edited my first response to inform you that the Event Triggers settings this will delete are only the settings directly inserted into the 'This Document' tab, not the ones defined in any of the other tabs within the Event Triggers dialog.  The ones on the 'This Document' tab are stored locally in a hidden PropertySet (if it exists at all).  The settings on all other tabs are stored within an external XML file.  But another detail to keep in mind is that within the 'This Document' tab might possibly be instructions to run external iLogic rules when certain event happen (not just instructions to run local iLogic rules), but this code does not check which setting are for which type of iLogic rule, just deletes the whole set.  It is possible though to 'edit' those settings (Property objects within the PropertySet), and check the Property.Value, which is usually the name of the rule to run.  If the rule name starts with "file://", then it is for an external rule.  That could be used to delete only the properties for running internal rules only, if needed.  But that would require a larger custom Sub routine, if that level of control is needed.

Just so you are aware, before making that big decision, which can not be undone.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 7

J.VandeMerckt
Advocate
Advocate
Hi Wesley

Atm we only have 1 external rules which runs for all documents and therefore appears fade out in the "this document" tab.
So I assume I could also just run your code and reapply the event trigger for all documents.
Or remove the event trigger for this external rule altogether, use your code and then add this external rule back into the all document event trigger.
0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor

If that one external rule is already set-up on the all documents tab, then running that rule above should not effect it at all.  That setting is saved within an external XML file, so deleting the PropertySet will not effect it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

J.VandeMerckt
Advocate
Advocate
Thank you, it works as intented!
Br
Justin
0 Likes