Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to delete ilogic forms using .net

11 REPLIES 11
Reply
Message 1 of 12
jj
Explorer
1973 Views, 11 Replies

How to delete ilogic forms using .net

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

11 REPLIES 11
Message 2 of 12
FarrenYoung
in reply to: jj

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

--Farren

************************************************************************************
If this post helps, please click the "thumbs up" to give kudos
If this post answers your question, please click "Accept as Solution"
************************************************************************************
Message 3 of 12
jj
Explorer
in reply to: FarrenYoung

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.

Message 4 of 12
xiaodong_liang
in reply to: jj

Hi,

 

Message 5 of 12
jj
Explorer
in reply to: xiaodong_liang

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.

Message 6 of 12
xiaodong_liang
in reply to: jj

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. 

Message 7 of 12
BWMcDowell
in reply to: xiaodong_liang

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

Message 8 of 12
dba78
in reply to: jj

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
in reply to: dba78

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.

Message 10 of 12
dba78
in reply to: hkempeneers

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
in reply to: dba78

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
in reply to: hkempeneers

So true...! 😁

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report