Delete iProperties ilogic

Delete iProperties ilogic

sebastian.muschler
Explorer Explorer
209 Views
3 Replies
Message 1 of 4

Delete iProperties ilogic

sebastian.muschler
Explorer
Explorer

Hi everyone!

 

I am currently trying to write an ilogic script with which I can delete all user parameters and all user-specific iProperties in the assemblies and in the parts. The user-specific parameters are deleted with the ilogic, but the iProperties are not, I just can't get them deleted
Perhaps someone here can help me with what I am doing wrong here.

 

many thanks in advance

Sub Main 
    Dim invApp As Application
    invApp = ThisApplication
    
    ' Aktive Baugruppe holen
    Dim doc As AssemblyDocument
    If TypeOf invApp.ActiveDocument Is AssemblyDocument Then
        doc = invApp.ActiveDocument
    Else
        MsgBox ("Bitte eine Baugruppe öffnen!")
        Exit Sub
    End If
    
    ' Benutzerparameter in deren Baugruppe löschen
    DeleteUserParameters(doc)
    ' iProperties in der Baugruppe löschen
    DeleteAlliProperties(doc)
    
    ' Alle Bauteile in der Baugruppe durchlaufen
    Dim compDef As AssemblyComponentDefinition
    compDef = doc.ComponentDefinition
    
    Dim oOccurrence As ComponentOccurrence
    For Each oOccurrence In compDef.Occurrences
        If oOccurrence.DefinitionDocumentType = kPartDocumentObject Then
            Dim partDoc As PartDocument
            partDoc = oOccurrence.ReferencedDocumentDescriptor.ReferencedDocument
            DeleteUserParameters(partDoc)
            DeleteAlliProperties(partDoc)
        End If
    Next
    
    MsgBox("Alle Benutzerparameter und iProperties wurden gelöscht!")
End Sub

Sub DeleteUserParameters(ByVal doc As Document)
    On Error Resume Next
    Dim params As UserParameters
    params = doc.ComponentDefinition.Parameters.UserParameters
    
    Dim i As Integer
    For i = params.Count To 1 Step -1
        params.Item(i).Delete
    Next i
    On Error GoTo 0
End Sub

Sub DeleteAlliProperties(ByVal doc As Document)
    On Error Resume Next
    Dim propSets As PropertySets
    propSets = doc.PropertySets
    
    ' Alle iProperties (Standard und Benutzerdefiniert) durchlaufen
    Dim propSet As PropertySet
    Dim prop As Inventor.Property
    Dim i As Integer
    
    For Each propSet In propSets
        ' Für jede PropertySet durchlaufen
        For i = propSet.Count To 1 Step -1
            prop = propSet.Item(i)
            ' Überprüfen, ob die iProperty nicht schreibgeschützt ist
            If Not prop.ReadOnly Then
                ' iProperty löschen
                propSet.Remove (i)
            End If
        Next i
    Next propSet
    On Error GoTo 0
End Sub

 

0 Likes
Accepted solutions (1)
210 Views
3 Replies
Replies (3)
Message 2 of 4

swalton
Mentor
Mentor

I've asked the forum mods to move this post to the Inventor programming forum.  I believe the folks over there will be able to help.

 

See: https://forums.autodesk.com/t5/inventor-programming-ilogic/bd-p/120

Steve Walton
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Inventor 2025
Vault Professional 2025
0 Likes
Message 3 of 4

kacper.suchomski
Mentor
Mentor
Accepted solution

Hi

Will this help you? (iProperties in active document)

 

' Aktives Dokument abrufen
Dim oDoc As Document = ThisApplication.ActiveDocument

' Überprüfen, ob ein Dokument geöffnet ist und iProperties unterstützt
If oDoc Is Nothing Then
    MessageBox.Show("Kein aktives Dokument gefunden.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error)
    Return
End If

' Benutzerdefinierte Eigenschaften abrufen
Dim customProps As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")

' Alle benutzerdefinierten Eigenschaften löschen
Dim propCount As Integer = customProps.Count
For i As Integer = propCount To 1 Step -1
    customProps.Item(i).Delete()
Next

' Erfolgsnachricht anzeigen
MessageBox.Show("Alle benutzerdefinierten iProperties wurden gelöscht.", "Erfolg", MessageBoxButtons.OK, MessageBoxIcon.Information)

 


Kacper Suchomski

EESignature


YouTube - Inventor tutorials | LinkedIn | Instagram

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.


Message 4 of 4

sebastian.muschler
Explorer
Explorer

Hallo Kacper,

thank you, yes that helped me a lot. It does exactly what it's supposed to do. 👍

 	Sub Main 
		
    Dim oDoc As Document = ThisApplication.ActiveDocument
    invApp = ThisApplication
    
    ' Aktive Baugruppe holen
    Dim doc As AssemblyDocument
    If TypeOf invApp.ActiveDocument Is AssemblyDocument Then
        doc = invApp.ActiveDocument
    Else
        MsgBox ("Bitte eine Baugruppe öffnen!")
        Exit Sub
    End If
    
    ' Benutzerparameter in deren Baugruppe löschen
    DeleteUserParameters(doc)
    ' iProperties in der Baugruppe löschen
    DeleteAlliProperties(doc)
    
    ' Alle Bauteile in der Baugruppe durchlaufen
    Dim compDef As AssemblyComponentDefinition
    compDef = doc.ComponentDefinition
    
    Dim oOccurrence As ComponentOccurrence
    For Each oOccurrence In compDef.Occurrences
        If oOccurrence.DefinitionDocumentType = kPartDocumentObject Then
            Dim partDoc As PartDocument
            partDoc = oOccurrence.ReferencedDocumentDescriptor.ReferencedDocument
            DeleteUserParameters(partDoc)
            DeleteAlliProperties(partDoc)
        End If
    Next
    ' Erfolgsnachricht anzeigen
MessageBox.Show("Alle benutzerdefinierten iProperties wurden gelöscht.", "Erfolg", MessageBoxButtons.OK, MessageBoxIcon.Information)
    
End Sub

Sub DeleteUserParameters(ByVal doc As Document)
    On Error Resume Next
    Dim params As UserParameters
    params = doc.ComponentDefinition.Parameters.UserParameters
    
    Dim i As Integer
    For i = params.Count To 1 Step -1
        params.Item(i).Delete
    Next i
    On Error GoTo 0
End Sub

Sub DeleteAlliProperties(ByVal doc As Document)

' Benutzerdefinierte Eigenschaften abrufen
Dim customProps As PropertySet = doc.PropertySets.Item("Inventor User Defined Properties")

' Alle benutzerdefinierten Eigenschaften löschen
Dim propCount As Integer = customProps.Count
For i As Integer = propCount To 1 Step -1
    customProps.Item(i).Delete()
Next i
    On Error GoTo 0
End Sub

All iProperties in the assembly and in the sub-assemblies and parts are now deleted as required