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: 

Cant get custom iPropertie vb.net API (Have code sample)

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
356 Views, 2 Replies

Cant get custom iPropertie vb.net API (Have code sample)

Hi,

 

Using the Inventor API and vb.,net combination I am able to successfully read an iPropertie and place its value in a textbox inside my vb.net form the code to do so is as follows...

 

        Dim DESTRACKPropSet As Inventor.PropertySet
        DESTRACKPropSet = Doc.PropertySets.Item("Design Tracking Properties")

        ' Get the existing property, if it exists. 
        Dim PROPDATE As Inventor.Property = Nothing
        PROPDATE = DESTRACKPropSet.Item("Creation Time")
        Dim VALDATE As String = PROPDATE.Value
        TextBox4.Text = VALDATE

 This code will retrive my Creation Time properties value and place its value in textbox4 .

 

what I understand is that I must select the correct Propertie set in the above example thats "Design Tracking Properties" and I must also know the propertie set item which im trying to access in the above example thats "Creation Time"...

 

Okay so this all works however now I want to select a custom propertie that i have created in the iproperties.. the Item is named "ARTNR" and its value is set to the text "HELLOthisISaTEST". Based on what Know from the code above I would think that the rightway to access and display my custom ipropertie as follows, however it dosnt work?

 

        ' Get the custom property set. 
        Dim CUST2PropSet As Inventor.PropertySet
        CUST2PropSet = Doc.PropertySets.Item("Inventor User Defined Properties")

        ' Get the existing property, if it exists. 
        Dim PROPARTNO As Inventor.Property = Nothing
        PROPARTNO = CUST2PropSet.Item("ARTNR")
        Dim VALARTNO As String = PROPARTNO.Value
        TextBox3.Text = VALARTNO
2 REPLIES 2
Message 2 of 3
JamieVJohnson2
in reply to: Anonymous

your code looks sound, however for some reason that I forgot, I use a for loop every time I want to locate a property.

 

 Public Function FindiProperty(ByVal PropSetName As String, ByVal PropName As String, ByVal invDoc As Inventor.Document) As Inventor.Property
        For Each propSet As PropertySet In invDoc.PropertySets
            If propSet.Name = PropSetName OrElse propSet.InternalName = PropSetName Then
                For Each prop As [Property] In propSet
                    If prop.Name = PropName Then
                        Return prop
                    End If
                Next
            End If
        Next
        Return Nothing
    End Function

    Public Function GetiPropertyValue(PropSetName As String, PropName As String, invDoc As Inventor.Document) As Object
        Dim prop As Inventor.Property = FindiProperty(PropSetName, PropName, invDoc)
        If prop IsNot Nothing Then Return prop.Value
        Return Nothing
    End Function
jvj
Message 3 of 3
Owner2229
in reply to: Anonymous

Hi, to get User Defined iProperties I'm ussing this global function:

 

Public Function iPropertyUser(oDoc As Inventor.Document, oProp As String) As Inventor.Property
	Dim oPropsets As PropertySets = oDoc.PropertySets
	Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
	Try
		iPropertyUser = oPropSet.Item(oProp)
	Catch
		oPropSet.Add("", oProp) ' This line will add missing iProperty
		iPropertyUser = oPropSet.Item(oProp)
	End Try
End Function

You can then use it like this:

 

Dim VALARTNO As String = iPropertyUser(oDoc, "ARTNR").Expression
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

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

Post to forums  

Autodesk Design & Make Report