Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations IDS on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is expression exist

Status
Not open for further replies.

Ehaviv

Computer
Jul 2, 2003
1,012
Hi

Currently I check if an expression
exist by using:

Try
expression.rename
Catch
' expression already exists
End Try

Please if someone know of a more
normal way.

Thank you.
 
Replies continue below

Recommended for you

I'm not sure if this is what you'd call 'normal', but I use a try catch block to create the expression. If it already exists, a specific error code will be returned - at which point I just use the existing expression. Something like below:

Code:
Dim exp_1 As Expression = Nothing
Dim exp1Value As Double = 2.7182
Try
    'create expression, type: Number [constant] (unitless)
    '.Create method will not work to create an expression of type String
    exp_1 = workPart.Expressions.Create("NXJ_1 = " & exp1Value.ToString)
 
    'alternately, let the compiler convert the value to a string
    'exp_1 = workPart.Expressions.Create("NXJ_1 = " & exp1Value)
 
    'or, pass in the value directly
    'exp_1 = workPart.Expressions.Create("NXJ_1 = 2.7182")
 
Catch ex As NXException
[highlight #FCE94F]    If ex.ErrorCode = 1050017 Then
        'expression already exists[/highlight]
        exp_1 = workPart.Expressions.FindObject("NXJ_1")
    Else
        'other error
        lw.WriteLine("NX exception: " & ex.ErrorCode & ", " & ex.Message)
 
    End If
 
End Try

Alternatively, you could iterate through the expression collection and check to see if an expression with a particular name already exists.

www.nxjournaling.com
 
Cowski thank you.

The yellow code is more correct then
check an array.
Because is unsafe.

I wonder why nx developers
Don't provide a direct statement
Something lik isexprexisy.

Thank you again.
 
I mean that expressions are created
Dynamically and can be a situation
that the array expressions are
not updated.

Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor