DELETE FORMS WITH RULE

DELETE FORMS WITH RULE

bence.pinter
Observer Observer
1,555 Views
6 Replies
Message 1 of 7

DELETE FORMS WITH RULE

bence.pinter
Observer
Observer

Hi,

 

I would like to delete forms with an iLogic rule.

 

Can anybody help me?

 

Thx

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

WCrihfield
Mentor
Mentor

Hi @bence.pinter.  I do not think that is possible right now with normal iLogic code.  You can delete iLogic rules from a document using iLogic code.  You can list the names of iLogic Forms in a document.  And you can show an iLogic Form in a document.  But I do not believe I have ever seen any methods available within the Inventor API or in iLogic for deleting iLogic forms from a document by code...yet.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

Curtis_Waguespack
Consultant
Consultant
Accepted solution

Hi @bence.pinter 

 

Welcome to the forum.  Here is a bit of code you can try. I just did a quick test in Inventor 2020 and Inventor 2022 and it seemed to work fine, but I have not used this in "real life" so I would proceed with caution, and do some testing for yourself.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

 

AddReference "Autodesk.iLogic.Core.dll"
AddReference "Autodesk.iLogic.UiBuilderCore.dll"
Imports iLogicCore = Autodesk.iLogic.Core
Dim oDoc = ThisApplication.ActiveDocument 

iCount = 0
Dim oUIatts As New iLogicCore.UiBuilderStorage.UiAttributeStorage(oDoc)
For Each oName In oUIatts.FormNames
  '  Dim oFormsSpecs = oUIatts.LoadFormSpecification(oName)
    iCount = iCount +1                     
Next

If iCount = 0 Then
	MsgBox("No intneral iLogic forms found.",,"iLogic")
	Return 'exit rule
End If

RUSure = MessageBox.Show(iCount & " internal iLogic forms found." _
	& vbLf & "This will delete all of these internal forms." _
	& vbLf & "Are you sure you want to continue?", "iLogic", _
		MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)

If RUSure = vbNo Then Return 'exit rule
	
'delete all internal forms
Dim Attset As Inventor.AttributeSet 

For Each Attset In oDoc.AttributeSets
	If Attset.Name Like "iLogicInternalUi*" Then
		Attset.Delete 
	End If 
Next

'blink the browser to clear memory
For Each oDockableWindow As Inventor.DockableWindow _
		In ThisApplication.UserInterfaceManager.DockableWindows
	If oDockableWindow.InternalName = "ilogic.treeeditor" Then
		oDockableWindow.Visible = False
		oDockableWindow.Visible = True
	End If
Next

 

 

EESignature

Message 4 of 7

WCrihfield
Mentor
Mentor

Cool code @Curtis_Waguespack.  It worked in a quick test I tried it out on.  I had seen those similar named attribute sets listed before, and guessed that they had something to do with the local forms, but never thought that they contained the actual definitions of the local forms.  That's nice to know.  And I had also known about the iLogic browser being a dock-able window, but did not know about the 'blink' action to update it after something like this.

 

Although the tools & process you used at the start of your code is new to me, and very interesting, I had a much simpler idea in mind for counting how many local iLogic forms were present in the document.  I was just referring to the ReadOnly Property called 'FormNames' of the 'iLogicForm' Interface object in the iLogic rule environment.  But I suppose that may only work within a local iLogic rule...I'm not sure.  Either way, your method lets you input a target document, and that simpler route I mentioned does not.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 7

TrexChristopher
Explorer
Explorer

To delete all the forms in all the parts inside an assembly file in Inventor 2022. 


AddReference "Autodesk.iLogic.Core.dll"
AddReference "Autodesk.iLogic.UiBuilderCore.dll"
Imports iLogicCore = Autodesk.iLogic.Core

Dim oAsmDoc As AssemblyDocument = TryCast(ThisApplication.ActiveDocument, AssemblyDocument)

If oAsmDoc IsNot Nothing Then
For Each oCompOccurrence As ComponentOccurrence In oAsmDoc.ComponentDefinition.Occurrences
If oCompOccurrence.DefinitionDocumentType = DocumentTypeEnum.kPartDocumentObject Then
Dim oPartDoc As PartDocument = TryCast(oCompOccurrence.Definition.Document, PartDocument)

If oPartDoc IsNot Nothing Then
Dim oDoc As Object = oPartDoc

Dim oUIatts As New iLogicCore.UiBuilderStorage.UiAttributeStorage(oDoc)
Dim iCount As Integer = 0

For Each oName In oUIatts.FormNames
' Dim oFormsSpecs = oUIatts.LoadFormSpecification(oName)
iCount = iCount + 1
Next

If iCount > 0 Then
Dim RUSure As DialogResult = MessageBox.Show(iCount & " internal iLogic forms found in " & oDoc.DisplayName & "." _
& vbLf & "This will delete all of these internal forms." _
& vbLf & "Are you sure you want to continue?", "iLogic", _
MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)

If RUSure = DialogResult.Yes Then
' delete all internal forms
Dim Attset As AttributeSet

For Each Attset In oDoc.AttributeSets
If Attset.Name Like "iLogicInternalUi*" Then
Attset.Delete()
End If
Next

' blink the browser to clear memory
For Each oDockableWindow As DockableWindow In ThisApplication.UserInterfaceManager.DockableWindows
If oDockableWindow.InternalName = "ilogic.treeeditor" Then
oDockableWindow.Visible = False
oDockableWindow.Visible = True
End If
Next
End If
End If
End If
End If
Next
Else
MsgBox("The active document is not an assembly.", , "iLogic")
End If

Message 6 of 7

WCrihfield
Mentor
Mentor

Hi @TrexChristopher.  Nice idea there.  But I believe it might be more efficient to loop through the referenced documents, instead of the assembly components, because there could be multiple components referencing the same model document.  And I believe you would only need to 'blink' the iLogic DockableWindow once after the entire process was finished, instead of once per document.  It seems to just be a visual artifact of the user interface, and the originally visible document will most likely remain the visible document after the process is done.

Here is an example iLogic rule code for nearly the same task, minus the PartDocument filter, that is broken down into 2 sections, just for reference.  Now that we know that those form specifications are being stored as a Bit array in the value of an Attribute, in specifically named AttributteSets, there is really no further need of the added references either for this specific task.

Sub Main
	Dim oDoc As Document = ThisDoc.Document
	DeleteInternalForms(oDoc) 'run the custom Sub routine on the active document if needed
	Dim oAllRefDocs As DocumentsEnumerator = oDoc.AllReferencedDocuments 'all levels
	Dim oRefDocs As DocumentsEnumerator = oDoc.ReferencedDocuments 'first level only
	If oAllRefDocs.Count = 0 Then Return
	For Each oRefDoc As Document In oAllRefDocs
		DeleteInternalForms(oRefDoc) 'run the custom Sub routine on this referenced document
	Next
	Dim iLogicWindow As DockableWindow = ThisApplication.UserInterfaceManager.DockableWindows.Item("ilogic.treeeditor")
	iLogicWindow.Visible = False
	iLogicWindow.Visible = True
	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

However, I still haven't quite figured out how to delete just one specific internal iLogic form by its name yet.  There does not appear to be a good way to differentiate which Form each AttributeSet, or any of the Attribute objects within each AttributeSet is for.  I suspect that we would need to know how to retrieve that Bit array into one of the internally referenced resource tools, then use that tool somehow to find out the name of that Form.  I have dabbled with that task a few times, but it is rather time consuming digging through all those references.  Since they just gave us the ability to close an open iLogic form recently, maybe they will extend further ability in future releases of Inventor that will allow us the ability to delete specific forms using built-in tools.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 7 of 7

WCrihfield
Mentor
Mentor

Just following up on this topic with news of some new development progress I made today.  I believe I now have a working solution (custom Sub routine) which will allow us to delete an internal iLogic Form by name, without deleting any others, and without messing the remaining ones up.  I have attached a text file containing the code for an iLogic rule example using the custom Sub routine I created.  It is certainly not very convenient to copy that whole large Sub routine between rules, but there are multiple ways to utilize that same block of code more convenient way.  You could put that code into an external iLogic rule, then prepare it to 'receive' the 'input' Document object and form name, one way or another.  Or you could put it out into an external rule, and convert it so you could reference it using AddVbFile from another rule, and use it that way too.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes