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: 

VB.net If Parameter exists do nothing

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
j.romo
401 Views, 8 Replies

VB.net If Parameter exists do nothing

Hello again, here I am struggling with another part of my code.

I can succesfully change the parameter name of a dimension but if the parameter name allready exists it crashes on me, cant figure out how to prevent that.

here is my code

  Public Sub ChangeAngleName(ThisApplication As Inventor.Application)
        'Declare document Active
        Dim oDoc As PartDocument
        oDoc = ThisApplication.ActiveDocument
        Dim oNumber As String
        oNumber = "Bend_" & txtbName1.Text
        If oNumber = "" Then
            MsgBox("Write a Bend Number")
        Else
            Dim oDim As Object
            oDim = oDoc.SelectSet(1)
'here it crashes if parameter name allready exists
            oDim.Parameter.Name = oNumber


        End If
8 REPLIES 8
Message 2 of 9
Michael.Navara
in reply to: j.romo

Yes you can. This sample show how to check if the parameter exists

 

Dim part As PartDocument = ThisDoc.Document

'Check if parameter exists
Dim paramName As String = "MyParam"
Dim params As Parameters = part.ComponentDefinition.Parameters
Try
	params(paramName)
	'Parameter exists

Catch
	'Parameter NOT exists

End Try
Message 3 of 9
j.romo
in reply to: Michael.Navara

Thank you It worked like a charm even the same Try Catch Arg helps me if the user diesnt select a Dimension

the code

blic Sub ChangeAngleName(ThisApplication As Inventor.Application)
        'Declare document Active
        Dim oDoc As PartDocument
        oDoc = ThisApplication.ActiveDocument
        Dim oNumber As String
        oNumber = "Bend_" & txtbName1.Text
        If oNumber = "" Then
            MsgBox("Write a Bend Number")
        Else
            Dim oDim As Object
            Dim oParam As String = oNumber
            Dim oParams As Parameters = oDoc.ComponentDefinition.Parameters

            Try
                oDim = oDoc.SelectSet(1)
                oDim.Parameter.Name = oNumber
            Catch
                MsgBox("This Parameter already exists or select a Dimension")
                Exit Sub
            End Try
        End If
    End Sub
Message 4 of 9
Matthew_Policelli
in reply to: j.romo

Two things:

 

1. Wouldn't the parameter always have a name? I.e. if it's not renamed, it would be "d8" or something right? What do you get if instead of trying to rename the parameter, you just do a message box with the parameter name?

 

2. The way you have this written, the If statement would never be true, because even if your txtbName1.Text is blank, your oNumber will still be: Bend_. I don't know what you're trying to do with this, but would it work better if instead of checking that oNumber is not blank, you check that txtbName1.Text is not blank?

oNumber = "Bend_" & txtbName1.Text
        If oNumber = "" Then
            MsgBox("Write a Bend Number")
        Else

 3. As for actually getting the parameter to rename, try replacing line 13 with these 2 lines:

oDoc.ComponentDefinition.Parameters(oDim.Parameter.Name).Name = oNumber 'rename dimension name to oNumber
oDoc.Update2(True) 'update so that renamed dimension displays

 

Message 5 of 9
j.romo
in reply to: Matthew_Policelli

Ill give it a try, but strangely is working as intended maybe I will see a bug later. Ill keep you posted 

thank you very much

Message 6 of 9
j.romo
in reply to: j.romo

You were right I changed to if the textbox is empty then send the error message.

but if I use your code on the rename it doesnt work.

 

 'Declare document Active
        Delete_list(ThisApplication)
        Dim oDoc As PartDocument
        oDoc = ThisApplication.ActiveDocument
        Dim oNumber As String
        oNumber = "Bend_" & txtbName1.Text

        If txtbName1.Text = "" Then
            MsgBox("Write a Bend Number")
        Else
            Dim oDim As Object
            Dim oParam As String = oNumber
            Dim oParams As Parameters = oDoc.ComponentDefinition.Parameters

            Try
                oDim = oDoc.SelectSet(1)
                oDim.Parameter.Name = oNumber
                'SE AGREGARON ESTAS DOS LINEAS
                'oDoc.ComponentDefinition.Parameters(oDim.Parameter.Name).Name = oNumber 'rename dimension name to oNumber
                'oDoc.Update2(True) 'update so that renamed dimension displays
                Refill_list(ThisApplication)
            Catch
                MsgBox("This Parameter already exists or select a Dimension")
                Exit Sub
            End Try

 

Message 7 of 9
Matthew_Policelli
in reply to: j.romo

Can you give a screenshot of what you're trying to do exactly? Both what you're trying to rename, and what you want the user to select.

Message 8 of 9
j.romo
in reply to: Matthew_Policelli

Here is how is working at the moment

https://autode.sk/3T4hjiD

I woul like to know how to select only angular dimensions right now i can select any dimension an it would change the name but not populate the check list box.

Message 9 of 9
wilson.broeksema
in reply to: j.romo

sorry, wrong topic

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

Post to forums  

Autodesk Design & Make Report