Adding custom iProperties to idw ussing the vb.net Inventor API (Code included)

Adding custom iProperties to idw ussing the vb.net Inventor API (Code included)

Anonymous
Not applicable
1,544 Views
3 Replies
Message 1 of 4

Adding custom iProperties to idw ussing the vb.net Inventor API (Code included)

Anonymous
Not applicable

Hi,

 

I know how to create custom iproperties for either iparts and assemblies, but cant create any for my idw drawings? I cant get the same thing done for the iproperties of idw files? Th code I have sofar is as follows

 

        Dim invApp As Inventor.Application
        invApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")

        Dim Doc As Inventor.Document
        Doc = invApp.ActiveDocument

        UpdateCustomiProperty(Doc, "MYPROPERTY", textbox1.text)

        Doc.Update()

    Private Sub UpdateCustomiProperty(ByRef Doc As Inventor.Document, ByRef PropertyName As String, ByRef PropertyValue As Object)
        ' Get the custom property set. 
        Dim customPropSet As Inventor.PropertySet
        customPropSet = Doc.PropertySets.Item("Inventor User Defined Properties")

        ' Get the existing property, if it exists. 
        Dim prop As Inventor.Property = Nothing
        Dim propExists As Boolean = True
        Try
            prop = customPropSet.Item(PropertyName)
        Catch ex As Exception
            propExists = False
        End Try

        ' Check to see if the property was successfully obtained. 
        If Not propExists Then
            ' Failed to get the existing property so create a new one. 
            prop = customPropSet.Add(PropertyValue, PropertyName)
        Else
            ' Change the value of the existing property. 
            prop.Value = PropertyValue
        End If
    End Sub

The error i get is the following screenshot...

Naamloos.png

 Now Im just confused 😞

mabey one of you guys can help me out?

1,545 Views
3 Replies
Replies (3)
Message 2 of 4

nmunro
Collaborator
Collaborator

If you look at the bottom of your screen capture, the Autos window shows the current value of variables at the current statement. It clearly shows that your document reference (Doc) is Nothing. Your code is somehow not capturing the document object. Once you fix this it should work.

 

        


https://c3mcad.com

0 Likes
Message 3 of 4

Anonymous
Not applicable

thats whats confusing me it normally just captures the document...?

 

0 Likes
Message 4 of 4

NachoShaw
Advisor
Advisor

Hi

 

First things first, i would most definately change this

Dim Doc As Inventor.Document
Doc = invApp.ActiveDocument

to this

 

Dim Doc As Inventor.DrawingDocument = invApp.ActiveDocument

Once this is done, you will be able to see what property options are available from a DrawingDocument as oppose to a generic Document.

 

 

Also,

 

Are you running the function from the drawing environment or are you running it from an assembly to pass iProperties to a drawing? If so, the Assembly would be the Active Sheet and you would need to declare the Drawing document separately as a DrawingDocument

 

 

 

Cheers

 

Nacho

Nacho
Automation & Design Engineer

Inventor automation Programmer (C#, VB.Net / iLogic)
Furniture, Sheet Metal, Structural, Metal fab, Tradeshow, Fabrication, CNC

EESignature


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.


0 Likes