Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Automatically articulate sketch and record measurements 1

Status
Not open for further replies.

erik3000

Mechanical
Sep 13, 2013
48
[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.
 
Replies continue below

Recommended for you

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
        '  spreadsheet value
        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
                lw.WriteLine("expression '" & expressionName & "' not found, journal exiting")
            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
                lw.WriteLine("expression '" & measureExpressionName & "' not found, journal exiting")
            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
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor