Inventor General Discussion

Inventor General Discussion

Reply
Mentor
tuliobarata
Posts: 164
Registered: ‎11-30-2007
Message 1 of 4 (1,775 Views)
Accepted Solution

Verify if parameter exists - iLogic

1775 Views, 3 Replies
11-05-2012 11:42 AM

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 :smileyfrustrated:

 

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

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

Valued Mentor
rhasell
Posts: 330
Registered: ‎05-23-2007
Message 2 of 4 (1,762 Views)

Re: Verify if parameter exists - iLogic

11-05-2012 03:23 PM 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
Autodesk PDS Ultimate 2015 SP 1 Build 203
Intel Core i7 (950@3.07GHz)/Win7x64 (Home) - 12GB Ram
Nvidia GeForce GTX 560 Ti
 
Please Give Kudo's / accept as a solution if it solves your problem.
Employee
Yijiang.Cai
Posts: 359
Registered: ‎05-20-2008
Message 3 of 4 (1,752 Views)

Re: Verify if parameter exists - iLogic

11-05-2012 09:15 PM 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.
Mentor
tuliobarata
Posts: 164
Registered: ‎11-30-2007
Message 4 of 4 (1,733 Views)

Re: Verify if parameter exists - iLogic

11-06-2012 03:06 AM 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
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.