Building my first Add-in problem 1

Building my first Add-in problem 1

j.romo
Advocate Advocate
429 Views
3 Replies
Message 1 of 4

Building my first Add-in problem 1

j.romo
Advocate
Advocate

Hello, I'm trying to develop my first add-in, i have some experience with Ilogic and right now I'm struggling with te basics of it.

The add-in will work for old inventor files  or imported components, so we can add some custom Iproperties.

the problem i will asume is very basic but i cant seem to figure out how to structure the create property...

using visual studio 2015

here is my code

 

 

 

 

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click

'Public Sub CreateCustomProperties()
' Get the active document.
Dim invDoc As Document
invDoc = _invApp.ActiveDocument

' Get the user defined (custom) property set.
Dim invCustomPropertySet As PropertySet
invCustomPropertySet = invDoc.PropertySets.Item("Inventor User Defined Properties")

' Declare some variables that will contain the various values.

Dim strProv As String
Dim strTel As String
Dim strMail As String
Dim strTe As String

 

 


' Set values for the variables.
strProv = "AGREGAR PROVEEDOR"
strTel = "AGREGAR TELEFONO"
strMail = "AGREGAR CORREO ELECTRONICO"
strTe = "AGREGAR TIEMPO DE ENTREGA"

' Create the properties.
Dim invProperty As [Property]
invProperty = invCustomPropertySet.Add(strProv, "PROVEEDOR")
invProperty = invCustomPropertySet.Add(strTel, "TELEFONO")
invProperty = invCustomPropertySet.Add(strMail, "CORREO")
invProperty = invCustomPropertySet.Add(strTe, "T.E")


End Sub

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

Owner2229
Advisor
Advisor
Accepted solution

Your code is correct, except the property definition:

 

 

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ' Get the active document.
    Dim oDoc As Document = _invApp.ActiveDocument
    ' Get the user defined (custom) property set.
    Dim oProSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
    ' Declare some variables that will contain the various values and set values for the variables.
    Dim strProv As String = "AGREGAR PROVEEDOR"
    Dim strTel As String = "AGREGAR TELEFONO"
    Dim strMail As String = "AGREGAR CORREO ELECTRONICO"
    Dim strTe As String = "AGREGAR TIEMPO DE ENTREGA"
    ' Create the properties.
    Dim invProperty As Inventor.Property
    invProperty = oProSet.Add(strProv, "PROVEEDOR")
    invProperty = oProSet.Add(strTel, "TELEFONO")
    invProperty = oProSet.Add(strMail, "CORREO")
    invProperty = oProSet.Add(strTe, "T.E")
End Sub

 

Also, if you only want to add the iPropery (and not work with it further), you can do it without declaration, e.g.:

 

oProSet.Add(strProv, "PROVEEDOR")

 

You should also check for existing iProperty:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    ' Get the active document.
    Dim oDoc As Document = _invApp.ActiveDocument
    ' Get the user defined (custom) property set.
    Dim oProSet As PropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")
    ' Declare some variables that will contain the various values and set values for the variables.
    Dim strProv As String = "AGREGAR PROVEEDOR"
    Dim strTel As String = "AGREGAR TELEFONO"
    Dim strMail As String = "AGREGAR CORREO ELECTRONICO"
    Dim strTe As String = "AGREGAR TIEMPO DE ENTREGA"
    ' Create the properties.
    GetProperty(oProSet, "PROVEEDOR", strProv)
    GetProperty(oProSet, "TELEFONO", strTel)
    GetProperty(oProSet, "CORREO", strMail)
    GetProperty(oProSet, "T.E", strTe)
End Sub

Private Function GetProperty(oProSet As PropertySet, sName As String, Optional sValue As String = "") As Inventor.Property
Dim iPro As Inventor.Property
Try
iPro = oProSet(sName)
Catch
iPro = oProSet.Add(sValue, sName)
End Try
Return iPro
End Function

 

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
Message 3 of 4

j.romo
Advocate
Advocate

thank you Mike worked as a charm....Smiley Very Happy

 

 

ill give it a study to learn from what I did wrong

 

 

 

thanks 

0 Likes
Message 4 of 4

Owner2229
Advisor
Advisor
Inventor.Property

instead of

[Property]
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