How can I verify if one parameter exists ?
Im doing a code to add some needed parameters in some drawings, i can create the parameters with the code below, but, if there is any parameter with the same name..it creates another one with _ in front of its name..
I tried to verify with a simple If but didnt work :S
This is the code that create those parameters, still with just 2 for tests:
Imports Inventor.UnitsTypeEnum Dim oParams As Parameters oParams=ThisApplication.ActiveDocument.Parameters Dim oUserParams As UserParameters oUserParams=oParams.UserParameters oUserParams.AddByValue("ref_ID1","PT",kTextUnits) MultiValue.SetList("ref_ID1","ES","EN","FR", "PT") oUserParams.AddByValue("ref_ID2","EN",kTextUnits) MultiValue.SetList("ref_ID2","0 - Sem idioma secundario", "ES","EN","FR", "PT")
Thanks very much, again!
Túlio Barata
Solved! Go to Solution.
Solved by tuliobarata. Go to Solution.
Hi
I have manged to get info from the forum and have made-up this piece of code.
I am no Guru, but perhaps you can work with this workflow and customize this for yourself?
' Create Custom Paramteres if not done.
Dim oPartDoc as PartDocument = ThisDoc.Document
Dim userParams As UserParameters = oPartDoc.ComponentDefinition.Parameters.UserParameters
Try
BOLT_Params = oPartDoc.ComponentDefinition.Parameters("BOLT_SIZE")
Catch
Dim newParam As UserParameter = userParams.AddByExpression("BOLT_SIZE", 0, "mm")
End Try
Try
BOLT_OFFSET_param = oPartDoc.ComponentDefinition.Parameters("BOLT_OFF")
Catch
Dim newParam As UserParameter = userParams.AddByExpression("BOLT_OFF", 0, "mm")
End Try
Try
BOLT_OFFSET_param = oPartDoc.ComponentDefinition.Parameters("BOLT_H")
Catch
Dim newParam As UserParameter = userParams.AddByExpression("BOLT_H", 0, "mm")
End Try
Parameter("BOLT_OFF")="BOLT_SIZE*1.5"
Parameter("BOLT_H")="BOLT_SIZE+4"
Please see the function to check whether the parameter exists -
Function ParaExist(sName) As Boolean
Dim blTag As Boolean
blTag = False
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition
For i = 1 To oCompDef.Parameters.Count
If oCompDef.Parameters(i).Name = sName Then
blTag = True
Exit For
End If
Next
ParaExist = blTag
End Function
Good morning all !
Thanks Cai and rhasel!!
The code is working perfectly now! Actually, i didnt understand very well the Cai's code, it didnt work. But the rhasel's, i just changed some details and now is working as i need!
This is the final code:
Imports Inventor.UnitsTypeEnum ' Create Custom Paramteres if not done.
Dim oPartDoc as DrawingDocument = ThisDoc.Document Dim userParams As UserParameters = oPartDoc.Parameters.UserParameters Try parametro = oPartDoc.Parameters("param1") Catch Dim newParam As UserParameter = userParams.AddByValue("param1","a",kTextUnits) End Try Try parametro = oPartDoc.Parameters("param2") Catch Dim newParam As UserParameter = userParams.AddByValue("param2","a",kTextUnits) End Try Try parametro = oPartDoc.Parameters("param3") Catch Dim newParam As UserParameter = userParams.AddByValue("param3","a",kTextUnits) End Try
Actually i dont know why, but i had to remove the ComponentDefinition from the code, and just change the oPartDoc line.
Thanks to both!
Túlio Barata