Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Create a Boolean Parameter

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
smccoywm
4656 Views, 9 Replies

Create a Boolean Parameter

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.

9 REPLIES 9
Message 2 of 10
xiaodong_liang
in reply to: smccoywm

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
eljoseppo
in reply to: xiaodong_liang

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...

Message 4 of 10
eljoseppo
in reply to: xiaodong_liang

How can I create a parameter in IAM file?

Message 5 of 10
ekinsb
in reply to: eljoseppo

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
Message 6 of 10
eljoseppo
in reply to: ekinsb

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.

Message 7 of 10
Jefkee
in reply to: eljoseppo

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.

Inventor 2013
Message 8 of 10
eljoseppo
in reply to: Jefkee

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

Message 9 of 10

This code is not working for me in AI 2015

 

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

 

Message 10 of 10
eljoseppo
in reply to: JorisSteurs1246

"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")

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

Post to forums  

Autodesk Design & Make Report