Submitted by kts14 on Tue, 09/15/2015 - 22:26
Forums:
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.
re: sketch settings
Here's what I suggest:
http://nxjournaling.com/content/process-files-directory
Post back with any specific questions that you have along the way.
Tried to do that
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
re: sketch preferences
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!!
Yeah. Works great!!
Thank you very much!
Julian