Inventor Customization

Reply
Valued Contributor
dano0310
Posts: 91
Registered: ‎03-04-2007
Message 1 of 6 (922 Views)

iLogic Parameter AddByValue

922 Views, 5 Replies
12-15-2010 03:28 PM

Just wondering how to use the addbyvalue command in ilogic to create a parameter?

 

Also is there a more in depth help file somewhere for the iLogic?

 

Regards

Dan

Employee
MjDeck
Posts: 957
Registered: ‎02-24-2009
Message 2 of 6 (897 Views)

Re: iLogic Parameter AddByValue

12-16-2010 10:39 AM in reply to: dano0310

AddByValue is an Inventor API function.  These are not documented in the iLogic help. You can find it in the API help which can be accessed from the Help menu under   Additional Resources -> Programming Help

 



Mike Deck
Software Developer
DLS - Mechanical Design
Autodesk, Inc.

Valued Contributor
dano0310
Posts: 91
Registered: ‎03-04-2007
Message 3 of 6 (889 Views)

Re: iLogic Parameter AddByValue

12-16-2010 02:33 PM in reply to: MjDeck

Thanks Mike

I can get it to work in API but I was wondering how to add a parameter in iLogic.

Cheers

Dan

Employee
MjDeck
Posts: 957
Registered: ‎02-24-2009
Message 4 of 6 (886 Views)

Re: iLogic Parameter AddByValue

12-16-2010 05:32 PM in reply to: dano0310

In a rule, you can get a ComponentDefinition from the predefined object named ThisDoc.Document.  Then get the Parameters collection from the ComponentDefinition.

 



Mike Deck
Software Developer
DLS - Mechanical Design
Autodesk, Inc.

Valued Contributor
dano0310
Posts: 91
Registered: ‎03-04-2007
Message 5 of 6 (883 Views)

Re: iLogic Parameter AddByValue

12-16-2010 07:14 PM in reply to: MjDeck

Mike this is a little like pulling teeth.

 

Ok so this is the code I am trying to use which is converted from VBA:

 

 

Sub Main
Dim oApp As Application
oApp = ThisApplication

Dim oPartDoc As Document
oPartDoc = oApp.ActiveDocument

If oPartDoc.DocumentType = kPartDocumentObject Then
Dim oPartCompDef As PartComponentDefinition
oPartCompDef = oPartDoc.ComponentDefinition

Dim oParams as Parameters
oParams=oPartCompDef.Parameters

Dim oUserParams as userparameters
oUserParams=oparams.userparameters

Dim oGravity As Parameter
oGravity=oUserParams.AddByValue("Gravity", "9.81", kMillimeterLengthUnits)

Else
Exit Sub
End If
End Sub

Basically it doesn't work (just ignore the fact that mm is not the right units for gravity)

 

I want to create a Parameter from within a rule.

 

Employee
MjDeck
Posts: 957
Registered: ‎02-24-2009
Message 6 of 6 (870 Views)

Re: iLogic Parameter AddByValue

12-17-2010 08:25 AM in reply to: dano0310

You need a couple of changes to make it work, and there's a few different ways to do it.  Here's a modified version of your rule showing AddByExpression as well as AddByValue:

 

Sub Main
    Dim oPartDoc As Document
    oPartDoc = ThisDoc.Document
    
    If oPartDoc.DocumentType = kPartDocumentObject Then
        Dim oPartCompDef As PartComponentDefinition
        oPartCompDef = oPartDoc.ComponentDefinition
    
        Dim oParams as Parameters
        oParams=oPartCompDef.Parameters 
    
        Dim oUserParams as UserParameters
        oUserParams=oParams.UserParameters
        
        Dim oGravityX As Parameter
		If (Not ParameterExists(oParams, "GravityX")) Then
          oGravityX=oUserParams.AddByValue("GravityX", 9.81/10, "mm")
		End If
        
		Dim oGravityY As Parameter
		If (Not ParameterExists(oParams, "GravityY")) Then
        oGravityY=oUserParams.AddByExpression("GravityY", "9.81 mm", UnitsTypeEnum.kMillimeterLengthUnits)
		End If
    Else
        Exit Sub
    End If
End Sub

Function ParameterExists(oParams as Parameters, parameterName As String)
 Try
   Dim param as Parameter = oParams(parameterName)
 Catch
   Return False
 End Try
 Return True
End Function

 

 

1) Gravity is a predefined constant for parameter equations. So I changed it to GravityX and GravityY in this sample.

2) The AddByValue function needs a number for the second argument.  It can't be in quotes.

3)  In iLogic (and VB.NET), you have to add the enumeration type (in this case UnitsTypeEnum) in front of Inventor constants that start with "k".  You can find the enum type to use by searching for the constant (in this case kMillimeterLengthUnits) in the API help.  You can use the statement:

Option Explicit On

at the top of the rule to see where enumeration types are required.

4)  Instead of using the constant, you can use a unit string such as "mm".  You will need a unit string if you want to create a parameter with compound units (such as acceleration due to gravity).

5) I would recommend using AddByExpression instead of AddByValue.  It gives you more flexibility.  Note that in the AddByValue function, you have to specify the value in centimeters (or other predefined database units).

6) Since the rule might be run more than once, you should check to see if the parameter already exists.  I added a function to do that.

 

 



Mike Deck
Software Developer
DLS - Mechanical Design
Autodesk, Inc.

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
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

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