INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Automatically articulate sketch and record measurements

## Automatically articulate sketch and record measurements

(OP)
[NX 10]

I have a fully constrained kinematic sketch with one input dimension. Is there a way to vary that dimension, maybe with an expression, so that it steps through each value and a corresponding reference dimension is automatically measured and tabulated against each input value?

The Animate Sketch tool would be useful for this were it able to record the values of a given reference dimension at each step. It seems to be for visual only.

I've gotten it to work via Motion Simulation, but it is a bit convoluted and requires excessive use of 'phantom' joints and links in order to set up the appropriate sensors to measure the dimension of interest.

I've experimented a bit trying to set up a journal to automate changing the input expression for each step but haven't been able to get that to work. I'm thinking there must be a relatively straightforward way to achieve this that I am not aware of.

### RE: Automatically articulate sketch and record measurements

Try the code below. It will vary a specified expression from the start value to the end value by the given step size. It will also report the value of the expression and another expression at each step. Edit the code where specified with your desired values before running the journal. For the measureExpressionName, I suggest creating an associative measurement and using its expression; do not use the expression of a sketch reference dimension because those expressions do not get updated as long as the dimension is marked as reference.

#### CODE

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()

Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "NXJ vary expression")

lw.Open()

'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
'Change the values of the following constants to suit your needs
'  specify expression name in .prt file that references
Const expressionName As String = "p0"
Const measureExpressionName As String = "p3"
Const startValue As Double = 6
Const endValue As Double = 7
Const stepValue As Double = 0.25
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Dim theExpression As Expression
Try
theExpression = theSession.Parts.Work.Expressions.FindObject(expressionName)
Catch ex As NXException
If ex.ErrorCode = 3520016 Then
'no expression found with given name
Else
lw.WriteLine(ex.ErrorCode & ": " & ex.Message)
End If
Return
End Try

Dim measureExpression As Expression
Try
measureExpression = theSession.Parts.Work.Expressions.FindObject(measureExpressionName)
Catch ex As NXException
If ex.ErrorCode = 3520016 Then
'no expression found with given name
Else
lw.WriteLine(ex.ErrorCode & ": " & ex.Message)
End If
Return
End Try

Dim currentValue As Double = startValue
Dim newFormula As String
Do While currentValue <= endValue

'update expression with current value
newFormula = currentValue.ToString
'lw.WriteLine("newFormula: " & newFormula)

theSession.UpdateManager.ClearErrorList()
Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Expression edit")

theExpression.RightHandSide = newFormula

Dim nErrs1 As Integer

'update model
Try
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Catch ex As NXException
lw.WriteLine("** Update Error with value: " & currentValue.ToString)
lw.WriteLine("** " & ex.ErrorCode & ": " & ex.Message)
lw.WriteLine("")

End Try

'record current value and measurment
lw.WriteLine("expression value: " & theExpression.Value.ToString)
lw.WriteLine("measurement value: " & measureExpression.Value.ToString)
lw.WriteLine("")

'update current value
currentValue += stepValue
Loop

lw.Close()

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX

End Function

End Module 

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!