Community
Inventor Forum
Welcome to Autodesk’s Inventor Forums. Share your knowledge, ask questions, and explore popular Inventor topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Verify if parameter exists - iLogic

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
tuliobarata
11819 Views, 3 Replies

Verify if parameter exists - iLogic

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

IV 2013
Tags (1)
3 REPLIES 3
Message 2 of 4
rhasell
in reply to: tuliobarata

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"

Reg
2024.2
Please Accept as a solution / Kudos
Message 3 of 4
Yijiang.Cai
in reply to: tuliobarata

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

Thanks,
River Cai

Inventor Quality Assurance Team
Autodesk, Inc.
Email: River-Yijiang.Cai@autodesk.com
Message 4 of 4
tuliobarata
in reply to: Yijiang.Cai

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

IV 2013

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

Post to forums  

Autodesk Design & Make Report