How to delete ilogic forms using .net

How to delete ilogic forms using .net

Anonymous
Not applicable
2,325 Views
11 Replies
Message 1 of 12

How to delete ilogic forms using .net

Anonymous
Not applicable

Hi all,

 

Could someone please tell me how to delete iLogic forms from Inventor 2013 parts/assembly using VB.net 2010?

I am able to delete all the rule using "Activated_iLogic.DeleteAllRules(PartDoc)" but "Activated_iLogic.DeleteAllForms(PartDoc)" or "Activated_iLogic.DeleteForm(PartDoc, FormName)" does not give me the result I was expecting and Google is not showing any result related to this.

Many thanks in advance.

 

JJ

0 Likes
2,326 Views
11 Replies
Replies (11)
Message 2 of 12

Anonymous
Not applicable

The forms are stored in the document's attributesets.  If you delete the attributeset/attribute, the form is gone.

0 Likes
Message 3 of 12

Anonymous
Not applicable

Hi Farren,

 

thanks for the suggestion. I can't get it to work but that is because of my lack of understanding the API & .net skills.

0 Likes
Message 4 of 12

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

0 Likes
Message 5 of 12

Anonymous
Not applicable

Hi Xiaodong, thanks for your reply.

 

I was able to delete rules and I tought that if I wanted to delete forms I needed to use the iLogic statements so that's how I came up with the 2 methods.
I have started with vb.net a couple of weeks ago and still struggling understanding the API and how to communicate with Inventor when I want something done. Replacing parts or subassemblies in an assembly took me a day to get that working. I am on a trail and error mode to get things done.

0 Likes
Message 6 of 12

xiaodong_liang
Autodesk Support
Autodesk Support

Hi,

 

Sorry, I still have no idea how to delete the iLogic form by code. I doubt this may be a requirement which has not been exposed. 

0 Likes
Message 7 of 12

BWMcDowell
Enthusiast
Enthusiast

Was looking for the same thing and found this

Hope i helps

https://www.cadlinecommunity.co.uk/hc/en-us/articles/202020531-Inventor-2015-iLogic-Delete-All-iLogi... by LukeDavenport

0 Likes
Message 8 of 12

dba78
Advocate
Advocate

I see, this is an old post 🙂

 

in .net you need a reference to Autodesk.ilogic.core.dll

 

then you can use: 

 

Imports ilc = Autodesk.iLogic.Core

public class myIlogic

    Public Shared Sub DeleteForms(doc As Document, optional FormName a string =Nothing)
        Dim uiatts As New ilc.UiBuilderStorage.UiAttributeStorage(doc)
        For Each name In uiatts.FormNames
            Dim fsp = uiatts.LoadFormSpecification(name)
            if FormName isnot nothing
                if FormName.Equals(name) Then
                    uiatts.DeleteFormSpecification(name)
                end if
            else
                uiatts.DeleteFormSpecification(name)
            End if
        Next
    End Sub

end class

BR,

Daniel

Message 9 of 12

hkempeneers
Advocate
Advocate

Hi Daniel,

I see this is a very old post...🙈

Thank you for the code.

But how can I manipulate this code for use in iLogic?

In version 2019 this code fails. (see picture)

hkempeneers_0-1594732921973.png

We really need code to delete forms from within an Inventor model.

0 Likes
Message 10 of 12

dba78
Advocate
Advocate

Hi, in an iLogic rule the core would look something like this

This code should delete all forms in the current document.

 

 

AddReference "Autodesk.iLogic.Core.dll"
AddReference "Autodesk.iLogic.UiBuilderCore.dll"

Imports ilc= Autodesk.iLogic.Core
Dim doc = ThisApplication.ActiveDocument 

Dim uiatts As New ilc.UiBuilderStorage.UiAttributeStorage(doc)
For Each name In uiatts.FormNames
    Dim fsp = uiatts.LoadFormSpecification(name)
    uiatts.DeleteFormSpecification(name)                        
Next

 

 

This throws me an error on inventor 2020.3.1 stating there was  problem with the different Versions of the referenced Assemblies.... However, you may be lucky and there is not version-interference in the 2019-assemblies.
I couldn't find any option to turn off the version restriction in iLogic (not sure this constellation would even work in a .net-Addin).

Anyway,  the code should work, if the assemblies aren't mixed up (by Autodesk)

 

Alternatively you may check the Attributes of the Document (since iLogic stores all its information in a document-Attributes) and delete them.... This is a real brute-force attempt but might work for your scenario:

 

Dim Attset As Inventor.AttributeSet 
Dim doc As Inventor.Document
doc = ThisApplication.ActiveDocument 

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

 

 

as a side node, the Forms are cached, so they will still be available until the iLogic-Window isn't closed and reopened.

 

HTH,

Daniel

 

Message 11 of 12

hkempeneers
Advocate
Advocate

Hi Daniel,

 

Many thanks for this solutions!

It works for us.

You wrote "This is a real brute-force attempt.."

Sometimes we need brute force to make life more pleasant. 😉

 

 

Message 12 of 12

dba78
Advocate
Advocate

So true...! 😁