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.
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
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 Modulewww.nxjournaling.com