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: 

iLogic Parameter AddByValue

5 REPLIES 5
Reply
Message 1 of 6
dano0310
2370 Views, 5 Replies

iLogic Parameter AddByValue

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

5 REPLIES 5
Message 2 of 6
MjDeck
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
Autodesk, Inc.

Message 3 of 6
dano0310
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

Message 4 of 6
MjDeck
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
Autodesk, Inc.

Message 5 of 6
dano0310
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.

 

Message 6 of 6
MjDeck
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
Autodesk, Inc.

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

Post to forums  

Autodesk Design & Make Report