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
Solved! Go to Solution.
Solved by Michael.Navara. Go to Solution.
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
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
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
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
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
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.
Here is how is working at the moment
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.
Can't find what you're looking for? Ask the community or share your knowledge.