userparams.addbyvalue: how is this work?

userparams.addbyvalue: how is this work?

Anonymous
Not applicable
565 Views
7 Replies
Message 1 of 8

userparams.addbyvalue: how is this work?

Anonymous
Not applicable
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.
0 Likes
566 Views
7 Replies
Replies (7)
Message 2 of 8

Anonymous
Not applicable
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.

0 Likes
Message 3 of 8

Anonymous
Not applicable
Thanks for your help!

Sword
0 Likes
Message 4 of 8

Anonymous
Not applicable
Brian (or anybody who know how to do it), could please tell me if it is possible to programmatically export parameters? With your previous example, I'm now able to create new params, give it new value or expression and set the unit of measure...Only "how to export it" is missing!:)

Thanks,
Sword
0 Likes
Message 5 of 8

Anonymous
Not applicable
There is the ability to iterate through all of the
parameters and to query all of their information so to export them the real
question is where do you want the data and what specific information do you
need.  You could choose to export them to a simple text file, or define an
XML format, or write them to an Excel spreadsheet, or write them into an Access
database, or probably a hundred other things.  Here's a simple program that
write all of the parameters to a comma delimited text file.

 

Public Sub WriteParamters()
    '
Get a reference to the parameters collection.  This will
fail
    ' if a part or assembly document is not
active.
    On Error Resume Next
    Dim
oParams As Parameters
    Set oParams =
ThisApplication.ActiveDocument.ComponentDefinition.Parameters
   
If Err Then
        MsgBox "A part or
assembly document must be active."
       
Exit Sub
    End If
    On Error GoTo
0
   
    ' Open the text file.  If
the file exists it will overwrite it.
    Open
"C:\Temp\Params.txt" For Output As #1

 

    ' Iterate through the parameters
and write out information
    Dim oParam As
Parameter
    For Each oParam In
oParams
        Dim strData As
String
        Print #1, oParam.Name &
", " & oParam.Expression & ", " & oParam.Value & ", " &
oParam.Units & ", """ & oParam.Comment & """"
   
Next
   
    ' Close the
file
    Close #1
End Sub

-Brian


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Brian
(or anybody who know how to do it), could please tell me if it is possible to
programmatically export parameters? With your previous example, I'm now able
to create new params, give it new value or expression and set the unit of
measure...Only "how to export it" is missing!:)

Thanks,
Sword

0 Likes
Message 6 of 8

Anonymous
Not applicable
thanks for the answer but it's not really what i'm looking for. I need to programmatically check the "export checkbox" in the paramaters table. This way, parameters will be transpose as "text custom properties" and I will be able to use it in an idw...

Sword
0 Likes
Message 7 of 8

Anonymous
Not applicable
Just set the ExposedAsProperty to True for the
property you want to export.

 

-Brian


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
thanks
for the answer but it's not really what i'm looking for. I need to
programmatically check the "export checkbox" in the paramaters table. This
way, parameters will be transpose as "text custom properties" and I will be
able to use it in an idw...

Sword

0 Likes
Message 8 of 8

Anonymous
Not applicable
thanks again!
0 Likes