Deleting and adding custom properties

Deleting and adding custom properties

Anonymous
Not applicable
2,983 Views
9 Replies
Message 1 of 10

Deleting and adding custom properties

Anonymous
Not applicable

Hi everyone!

Sometimes when I dowload 3D CAD models from manufacturer, dowloaded file have many useless properties and each one I have to delete and add my. I'm trying to write a vba macro to deleting and adding custom properties of *IPT and *.IAM files. I have problem with deleting. Why it is not working? Please help.

 

Private Sub DeleteButton_Click()
Dim oCustomPropertySet As Document
Set oCustomPropertySet = ThisApplication.ActiveDocument
Dim invCustomPropertySet As PropertySet
oCustomPropertySet = invCustomPropertySet.PropertySets.Item("Inventor User Defined Properties")
For Each oCustomPropertySet In invCustomPropertySet
oCustProp.Delete
Next

End Sub

Thanks

Adam

0 Likes
Accepted solutions (1)
2,984 Views
9 Replies
Replies (9)
Message 2 of 10

j.romo
Advocate
Advocate

Try with this one

you can keep properties just filling the hello world with the name of the property to keep if not all of them will be gone

 

SyntaxEditor Code Snippet

'define custom property collection
oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
'look at each property in the collection
For Each oCustProp In oCustomPropertySet
'check for a property name that you don't want to delete
If Not oCustProp.name = "HelloWorld" Then
'delete the custom iProperty
oCustProp.Delete 
Else 
End If
Next

 

0 Likes
Message 3 of 10

Anonymous
Not applicable

Thanks for answer but I still have Compile error: Invald use or property on:

oCustomPropertySet = ThisDoc.Document.PropertySets.Item("Inventor User Defined Properties")
0 Likes
Message 4 of 10

j.romo
Advocate
Advocate

I have used the code many times

What inventor are u using?

check my screencast

 

 

Message 5 of 10

Anonymous
Not applicable

Hmm, maybe it is not working because I'm writing macro in VBA editor, not in ILogic 🙂

0 Likes
Message 6 of 10

dgreatice
Collaborator
Collaborator
Accepted solution

Hi,

 

fix :

Private Sub DeleteButton_Click()
Dim oCustomPropertySet as PropertySet Set oCustomPropertySet = ThisApplication.ActiveDocument.PropertySets.Item("Inventor User Defined Properties") Dim oCustProp As Property
For Each oCustProp In oCustomPropertySet oCustProp.Delete Next End Sub
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 7 of 10

Anonymous
Not applicable

Thanks! it's works great now!

0 Likes
Message 8 of 10

arkelec
Collaborator
Collaborator

infoMASU6  

 

I was about to post to ask if this was possible.  I see that it is, but my skills in this area are weak. 

 

Rather than start a new topic, could anyone post some pointers as to how I implement the process?

 

I have previously been able to add fan external rule & a form for accessing custom fields, but this was very much "monkey see-monkey do".

 

To start with, I'm not sure about the comment VBA vs iLogic.  

 

Thanks in advance.

0 Likes
Message 9 of 10

arkelec
Collaborator
Collaborator

I found some code to point me in the right direction, but it didn't do exactly what I need, so I've started a new thread.

0 Likes
Message 10 of 10

snappyjazz
Collaborator
Collaborator

@dgreatice 

runtime error let and set.png

 

Newbie here. I am running Inventor 2019. The compile error shows this method doesn't work anymore. Is there another way?

0 Likes