Inventor General

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

Verify if parameter exists - iLogic

884 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
Valued Mentor
rhasell
Posts: 287
Registered: ‎05-23-2007
Message 2 of 4 (871 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 Product Design Suite Premium 2014 SP1-Update 2 Build 222
Intel Core i7 (950@3.07GHz)/Win7x64 (Home) - 12GB Ram
Nvidia GeForce GTX 560 Ti
 
Please accept as a solution if it fixes your problem.
Employee
Posts: 348
Registered: ‎05-20-2008
Message 3 of 4 (861 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
Posts: 164
Registered: ‎11-30-2007
Message 4 of 4 (842 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube