Inventor Customization

Reply
Valued Contributor
smccoywm
Posts: 51
Registered: ‎09-29-2008
Message 1 of 6 (488 Views)
Accepted Solution

Create a Boolean Parameter

488 Views, 5 Replies
09-13-2011 07:02 AM

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.

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

ADN Support Specialist
xiaodong.liang
Posts: 1,303
Registered: ‎06-12-2011
Message 2 of 6 (471 Views)

Re: Create a Boolean Parameter

09-16-2011 12:10 PM 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



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Valued Contributor
eljoseppo
Posts: 76
Registered: ‎10-11-2010
Message 3 of 6 (304 Views)

Re: Create a Boolean Parameter

10-31-2013 03:09 AM 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...

Valued Contributor
eljoseppo
Posts: 76
Registered: ‎10-11-2010
Message 4 of 6 (274 Views)

Re: Create a Boolean Parameter

11-08-2013 03:44 AM in reply to: xiaodong.liang

How can I create a parameter in IAM file?

ADN Support Specialist
ekinsb
Posts: 324
Registered: ‎07-21-2006
Message 5 of 6 (268 Views)

Re: Create a Boolean Parameter

11-08-2013 01:07 PM 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
Developer Technical Services
Autodesk Developer Network
Autodesk, Inc.
Valued Contributor
eljoseppo
Posts: 76
Registered: ‎10-11-2010
Message 6 of 6 (262 Views)

Re: Create a Boolean Parameter

11-09-2013 10:13 AM 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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.