Journal for Sketch settings

Hi,

I need a journal to change the Sketch Preferences of existing Sketch features in a part file.

I had 100s of parts and it is a lot of work to open every part and set sketch preferences for each sketch in sketcher.

Here's what I suggest:

  • Step 1: Open a part and record a journal while changing the desired sketch setting(s).
  • Step 2: Edit the resulting code; eliminate unnecessary stuff that the journal recorder may have added, turn this code into a dedicated function or subroutine. The function or subroutine will take a sketch feature as an argument and set the settings as desired.
  • Step 3: Extend this code to iterate through the part's feature collection; when a sketch feature is found, pass it to the function/sub from step 2.
  • Step 4: When the code works well on a single part, extend the code to process all of the files that need this change. Some code for processing all the parts in a given directory can be found here:
    http://nxjournaling.com/content/process-files-directory

Post back with any specific questions that you have along the way.

I tried to follow your steps. With a little bit of this and a little bit of that I assembled the next code.
Since I'm a newbie (experience = 1 day) I I had to settle for a script which needs you to select each sketch, I could not possibly understand how to run the setting for all sketches in the part, let alone a whole folder)

(Note: the script specifically sets just 2 values of the sketch settings, but once it works I think it's easy to tweak)

Can someone tell me why it doesn't work? NX points to the the line ".Type = NXOpen.UFConstants.UF_sketch_type"

Thanks!

CODE BELOW

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display

' ----------------------------------------------
' Dialog Begin Sketch Settings
' ----------------------------------------------

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sketch Settings")

Dim sketch1 As NXOpen.Sketch = SelectSketch()
sketch1.Preferences.FixedTextSize = 6.0
sketch1.Preferences.ConstraintSymbolSize = 6.0
sketch1.Preferences.ApplySketchPreferences(0)

theSession.DeleteUndoMark(markId1, Nothing)

End Sub

Function SelectSketch() As NXOpen.Sketch

Dim ui As UI = ui.GetUI
Dim message As String = "Select sketch"
Dim title As String = "Selection"

Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim keepHighlighted As Boolean = False
Dim includeFeatures As Boolean = True

Dim selectionAction As Selection.SelectionAction = _
Selection.SelectionAction.ClearAndEnableSpecific

Dim selectionMask_array(0) As Selection.MaskTriple
With selectionMask_array(0)
.Type = NXOpen.UFConstants.UF_sketch_type
.Subtype = 0
End With

Dim selectedObject As NXObject = Nothing
Dim cursor As Point3d

ui.SelectionManager.SelectObject(message, title, scope, _
selectionAction, includeFeatures, _
keepHighlighted, selectionMask_array, _
selectedObject, cursor)

Dim sketch As NXOpen.Sketch = CType(selectedObject, NXOpen.Sketch)

If sketch Is Nothing Then
Return Nothing
End If

Return sketch

End Function

End Module

The UFConstants are part of the NXOpen.UF namespace. Change the following line:

.Type = NXOpen.UFConstants.UF_sketch_type

to:

.Type = UF.UFConstants.UF_sketch_type

If you want the journal to process all the sketches in the current work part, you could do the following:

Option Strict Off
Imports System
Imports NXOpen

Module Module63
Sub Main(ByVal args() As String)

Dim theSession As NXOpen.Session = NXOpen.Session.GetSession()
Dim workPart As NXOpen.Part = theSession.Parts.Work
Dim displayPart As NXOpen.Part = theSession.Parts.Display

Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sketch Settings")

For Each tempSketch As Sketch In workPart.Sketches
tempSketch.Preferences.FixedTextSize = 6.0
tempSketch.Preferences.ConstraintSymbolSize = 6.0
tempSketch.Preferences.ApplySketchPreferences(0)
Next

theSession.DeleteUndoMark(markId1, Nothing)

End Sub

End Module

Yeah. Works great!!
Thank you very much!
Julian