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?
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
In a rule, you can get a ComponentDefinition from the predefined object named ThisDoc.Document. Then get the Parameters collection from the ComponentDefinition.
Mike this is a little like pulling teeth.
Ok so this is the code I am trying to use which is converted from VBA:
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
Dim oUserParams as userparameters
Dim oGravity As Parameter
oGravity=oUserParams.AddByValue("Gravity", "9.81", kMillimeterLengthUnits)
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.
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.
Access a broad range of knowledge to help get the most out of your products and services.