Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Shortest Code to change styles of all drawing views in NX using vb/journal

Status
Not open for further replies.

DeerSpotter

Military
Apr 27, 2022
2

let me know if there is a better way, this is my first post here on eng-tips





Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet
Dim views As ModelingViewCollection = workPart.ModelingViews

'iterate through the view collection
For Each vw As NXOpen.Drawings.DraftingView In startSheet.SheetDraftingViews

Dim editViewSettingsBuilder1 As NXOpen.Drawings.EditViewSettingsBuilder = Nothing
editViewSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder({vw})
Dim editsettingsbuilders1(0) As NXOpen.Drafting.BaseEditSettingsBuilder
editsettingsbuilders1(0) = editViewSettingsBuilder1
workPart.SettingsManager.ProcessForMultipleObjectsSettings(editsettingsbuilders1)

'change all view settings here use editViewSettingsBuilder1.yourcodehere
editViewSettingsBuilder1.ViewStyle.ViewStyleSmoothEdges.SmoothEdge = True
editViewSettingsBuilder1.ViewStyle.ViewStyleSmoothEdges.Color = workPart.Colors.Find("Light Gray")
editViewSettingsBuilder1.ViewStyle.ViewStyleSmoothEdges.Font = NXOpen.Preferences.Font.Phantom
editViewSettingsBuilder1.Commit()
next

End Sub
End Module

 
Replies continue below

Recommended for you

The .CreateDrawingEditViewSettingsBuilder accepts an array of views as the input. I've not tried it, but you can probably pass them all in at once and avoid the for loop.
Code:
editViewSettingsBuilder1 = workPart.SettingsManager.CreateDrawingEditViewSettingsBuilder(startSheet.SheetDraftingViews.ToArray())

Whether you use the for loop or pass them all in at once, you will need to call the .Destroy method right after the .Commit. Builder objects that are not destroyed can later cause strange behavior in NX.

Code:
editViewSettingsBuilder1.Commit()
editViewSettingsBuilder1.Destroy()

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

Part and Inventory Search

Sponsor