Here's some sample code that demonstrates the use
of this function and the AddByExpression function. The input value for the
AddByValue function is always database units for the unit type specified.
For example in the first two calls to AddByValue below, they are defining a
distance. The internal database units for distance within Inventor are
centimeters, so distance values passed into the AddByValue function will always
be assumed to be centimeters. The unit argument allows you to set the unit
associated with the parameter. The unit argument is the equivalen of the
Unit column in the parameters dialog. For example, the first call creates
a parameter that has a value of 2.54 centimeters but will use an inch
unit. In the parameters dialog this results in a display of a parameter of
1 inch. For a more complete discussion of the units see the Units of
Measure section in the online help.
The AddByExpression function is the equivalent to
creating an parameter interactively through the dialog. In this case,
instead of a value you specify a string. This string can contain unit
information and equations. For example you could provide input like "5 in
+ 3 cm" or "Dist1 / 2.0".
Public Sub AddParams()
' Get
a reference to the active part document.
Dim oDoc As
PartDocument
Set oDoc =
ThisApplication.ActiveDocument
With
oDoc.ComponentDefinition.Parameters.UserParameters
' Create two parameters using distance units and
value.
Call .AddByValue("Dist1",
2.54, "in")
Call
.AddByValue("Dist2", 2.54, "cm")
' Create two parameters using
distance units and expression.
Call .AddByExpression("Dist3", "1",
"in")
Call
.AddByExpression("Dist4", "2.54",
"cm")
' Create two parameters using
angle units and value.
Call
.AddByValue("Angle1", 3.14, "deg")
Call .AddByValue("Angle2", 3.14,
"rad")
' Create two parameters using
angle units and expression.
Call
.AddByExpression("Angle3", "180",
"deg")
Call
.AddByExpression("Angle4", "3.14", "rad")
End With
End
Sub
-Brian
style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Hello!
I have to add a lot of userparameters to a batch of parts. Userparams
name, value and units will be the same for each parts so I'm trying to write a
program that will do this boring job for me but I don't know how work the
addbyvalue method and I did'nt find explicit samples in IV. Someone can help?
Sword
Venmar CES inc.