Create a Boolean Parameter

Create a Boolean Parameter

smccoywm
Advocate Advocate
5,568 Views
9 Replies
Message 1 of 10

Create a Boolean Parameter

smccoywm
Advocate
Advocate

Does the IV2012 API allow the creation of a Yes/No parameter. If so can someone post an exapmple. I have created "Text" parameters but I am stumped on this one.

 

Scott A. McCoy

West-Mark Mfg.

0 Likes
Accepted solutions (1)
5,569 Views
9 Replies
Replies (9)
Message 2 of 10

xiaodong_liang
Autodesk Support
Autodesk Support
Accepted solution

Hi,

 

Please refer to the following code. Make sure the last argument is "BOOLEAN".

 

Sub test()

Dim oDoc As PartDocument
Set oDoc = ThisApplication.ActiveDocument

 

'bool

Dim oUserParam1 As UserParameter
Set oUserParam1 = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("Ready", True, "BOOLEAN")

 

'text

Dim oUserParam2 As UserParameter
Set oUserParam2 = oCompDef.Parameters.UserParameters.AddByValue("Name", "rocky", "TEXT")

 

'double

Dim oUserParam3 As UserParameter
Set oUserParam3 = oCompDef.Parameters.UserParameters.AddByValue("Length", 5, kCentimeterLengthUnits)



End Sub

 

Best regards,

 
autodesk_logo_signature.png

Xiaodong Liang

Developer Consultant

Autodesk Developer Technical Services

Message 3 of 10

Anonymous
Not applicable

I made some changes to avoid creating additional parameter like IPE_1, IPE_2 everytime I run my rule:

 

Try
myParam=Parameter("IPE")
Catch
Dim myParam As UserParameter
myParam = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("IPE", "IPE 000", "TEXT")
End Try

MultiValue.SetList("IPE", "IPE 080", "IPE 100", "IPE 500", "IPE 550", "IPE 600")

 maybe someone will need this later...

0 Likes
Message 4 of 10

Anonymous
Not applicable

How can I create a parameter in IAM file?

0 Likes
Message 5 of 10

ekinsb
Alumni
Alumni

The code above will work if you change the line

 

    Dim oDoc As PartDocument

 

to

 

    Dim oDoc As AssemblyDocument

 

or you can change it to

 

    Dim oDoc As Document

 

and the same program will work in both parts and assemblies.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
0 Likes
Message 6 of 10

Anonymous
Not applicable

Thanks it was not so obvious. I tried it before, had some errors, wasn't sure if its the right way. Now I've tried again - code is working in iLogis but afred I delete one line. No idea why.

 

Dim oDoc As Document
oDoc = ThisApplication.ActiveDocument
  
Try
 myParam=Parameter("TYPE")
Catch
 'Dim myParam As UserParameter
 myParam = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TYPE", "TYPE 0", "TEXT")
End Try

MultiValue.SetList("TYPE", "TYPE 1", "TYPE 2")

 thanks again.

0 Likes
Message 7 of 10

Anonymous
Not applicable

Hi,

 

i was wondering if there is a way to add unitless user parameters?

i managed to add length type parameters but i'm unable to create a unitless.

0 Likes
Message 8 of 10

Anonymous
Not applicable

Does this work for you:

 

Dim oPartDoc As Inventor.Document
Set oPartDoc = ThisApplication.ActiveDocument

Dim oUserParam3 As UserParameter
Set oUserParam3 = oPartDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("Length", 4, kUnitlessUnits)

 

tested in Inventor 2015

0 Likes
Message 9 of 10

JorisSteurs1246
Advocate
Advocate

This code is not working for me in AI 2015

 

" set" is no longer supported and without "set" it doesn't work 😞

 

0 Likes
Message 10 of 10

Anonymous
Not applicable

"set" is working only in VBA editor

 

which code is not working? This one?:

 

Try
 myParam=Parameter("TYPE")
Catch
 'Dim myParam As UserParameter
 myParam = oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue("TYPE", "TYPE 0", "TEXT")
End Try

MultiValue.SetList("TYPE", "TYPE 1", "TYPE 2")
0 Likes