Replace views

Hello all,

i have recorded a journal in NX where i move all my views, notes and dimension from sheet x to sheet y. This is because of a new titleblock.
in the past the pattern was used for this but the new templates are using the new titleblock function of NX.

What is the fastest way to change this.

My recorded script is always looking to the specified view names. How can i make this variable?

Kind regards

Ruud

' NX 10.0.3.5
' Journal created by Ruud on Mon May 30 13:37:49 2016 W. Europe Daylight Time
'
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

' ----------------------------------------------
' Menu: Format->Layer Settings...
' ----------------------------------------------
Dim markId1 As NXOpen.Session.UndoMarkId
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

theSession.SetUndoMarkName(markId1, "Layer Settings Dialog")

Dim stateArray1(0) As NXOpen.Layer.StateInfo
stateArray1(0) = New NXOpen.Layer.StateInfo(256, NXOpen.Layer.State.Selectable)
workPart.Layers.ChangeStates(stateArray1, False)

Dim stateArray2(0) As NXOpen.Layer.StateInfo
stateArray2(0) = New NXOpen.Layer.StateInfo(256, NXOpen.Layer.State.Hidden)
workPart.Layers.ChangeStates(stateArray2, False)

theSession.SetUndoMarkName(markId1, "Layer Settings")

theSession.DeleteUndoMark(markId1, Nothing)

' ----------------------------------------------
' Menu: Edit->Selection->Select All
' ----------------------------------------------
' Refer to the sample NXOpen application, Selection for "Select All" alternatives.
' ----------------------------------------------
' Menu: Edit->Cut
' ----------------------------------------------
workPart.PmiManager.RestoreUnpastedObjects()

Dim markId2 As NXOpen.Session.UndoMarkId
markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Drafting Cut")

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId2)

Dim markId3 As NXOpen.Session.UndoMarkId
markId3 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

Dim nullNXOpen_Drawings_DrawingSheet As NXOpen.Drawings.DrawingSheet = Nothing

Dim drawingSheetBuilder1 As NXOpen.Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = workPart.DrawingSheets.DrawingSheetBuilder(nullNXOpen_Drawings_DrawingSheet)

drawingSheetBuilder1.AutoStartViewCreation = True

drawingSheetBuilder1.StandardMetricScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11

drawingSheetBuilder1.StandardEnglishScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardEnglishScale.S11

drawingSheetBuilder1.AutoStartViewCreation = False

drawingSheetBuilder1.MetricSheetTemplateLocation = "C:\PLM\NX\NX100\UGII\templates\Drawing-A0-Size2D-template.prt"

drawingSheetBuilder1.EnglishSheetTemplateLocation = "C:\PLM\NX\NX100\UGII\templates\Drawing-A-Size2D-template.prt"

drawingSheetBuilder1.Height = 841.0

drawingSheetBuilder1.Length = 1189.0

drawingSheetBuilder1.StandardMetricScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardMetricScale.S11

drawingSheetBuilder1.StandardEnglishScale = NXOpen.Drawings.DrawingSheetBuilder.SheetStandardEnglishScale.S11

drawingSheetBuilder1.ScaleNumerator = 1.0

drawingSheetBuilder1.ScaleDenominator = 1.0

drawingSheetBuilder1.Units = NXOpen.Drawings.DrawingSheetBuilder.SheetUnits.Metric

drawingSheetBuilder1.ProjectionAngle = NXOpen.Drawings.DrawingSheetBuilder.SheetProjectionAngle.Third

drawingSheetBuilder1.Number = "2"

drawingSheetBuilder1.SecondaryNumber = ""

drawingSheetBuilder1.Revision = "A"

theSession.SetUndoMarkName(markId3, "Sheet Dialog")

drawingSheetBuilder1.MetricSheetTemplateLocation = "C:\PLM\NX\NX100\UGII\templates\Drawing-A0-Size2D-template.prt"

drawingSheetBuilder1.MetricSheetTemplateLocation = "C:\PLM\NX\NX100\UGII\templates\Drawing-A2-Size2D-template.prt"

drawingSheetBuilder1.MetricSheetTemplateLocation = "C:\PLM\NX\NX100\UGII\templates\Drawing-A0-Size2D-template.prt"

Dim markId4 As NXOpen.Session.UndoMarkId
markId4 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sheet")

theSession.DeleteUndoMark(markId4, Nothing)

Dim markId5 As NXOpen.Session.UndoMarkId
markId5 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Sheet")

Dim nXObject1 As NXOpen.NXObject
nXObject1 = drawingSheetBuilder1.Commit()

theSession.DeleteUndoMark(markId5, Nothing)

theSession.SetUndoMarkName(markId3, "Sheet")

drawingSheetBuilder1.Destroy()

workPart.Drafting.SetTemplateInstantiationIsComplete(True)

' ----------------------------------------------
' Menu: Edit->Paste
' ----------------------------------------------
Dim markId6 As NXOpen.Session.UndoMarkId
markId6 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Paste View(s)")

Dim baseView1 As NXOpen.Drawings.BaseView = CType(workPart.DraftingViews.FindObject("Front@1"), NXOpen.Drawings.BaseView)

baseView1.RestoreViewBorder()

Dim detailView1 As NXOpen.Drawings.DetailView = CType(workPart.DraftingViews.FindObject("DETAIL@7"), NXOpen.Drawings.DetailView)

detailView1.RestoreViewBorder()

Dim detailView2 As NXOpen.Drawings.DetailView = CType(workPart.DraftingViews.FindObject("DETAIL@8"), NXOpen.Drawings.DetailView)

detailView2.RestoreViewBorder()

Dim detailView3 As NXOpen.Drawings.DetailView = CType(workPart.DraftingViews.FindObject("DETAIL@9"), NXOpen.Drawings.DetailView)

detailView3.RestoreViewBorder()

Dim baseView2 As NXOpen.Drawings.BaseView = CType(workPart.DraftingViews.FindObject("Left@4"), NXOpen.Drawings.BaseView)

baseView2.RestoreViewBorder()

Dim baseView3 As NXOpen.Drawings.BaseView = CType(workPart.DraftingViews.FindObject("Bottom@2"), NXOpen.Drawings.BaseView)

baseView3.RestoreViewBorder()

Dim baseView4 As NXOpen.Drawings.BaseView = CType(workPart.DraftingViews.FindObject("Right@3"), NXOpen.Drawings.BaseView)

baseView4.RestoreViewBorder()

Dim detailView4 As NXOpen.Drawings.DetailView = CType(workPart.DraftingViews.FindObject("DETAIL@6"), NXOpen.Drawings.DetailView)

detailView4.RestoreViewBorder()

Dim views1(7) As NXOpen.Drawings.DraftingView
views1(0) = baseView1
views1(1) = detailView1
views1(2) = detailView2
views1(3) = detailView3
views1(4) = baseView2
views1(5) = baseView3
views1(6) = baseView4
views1(7) = detailView4
Dim drawingSheet1 As NXOpen.Drawings.DrawingSheet = CType(nXObject1, NXOpen.Drawings.DrawingSheet)

workPart.DraftingViews.MoveViewsToDrawing(views1, drawingSheet1)

Dim id1 As NXOpen.Session.UndoMarkId
id1 = theSession.NewestVisibleUndoMark

Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(id1)

' ----------------------------------------------
' Menu: Edit->Delete...
' ----------------------------------------------
Dim markId7 As NXOpen.Session.UndoMarkId
markId7 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Delete")

Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

theSession.UpdateManager.ClearErrorList()

Dim markId8 As NXOpen.Session.UndoMarkId
markId8 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete")

Dim objects1(0) As NXOpen.NXObject
Dim view1 As NXOpen.View = CType(workPart.Views.FindObject("Sheet 1@0"), NXOpen.View)

objects1(0) = view1
Dim nErrs3 As Integer
nErrs3 = theSession.UpdateManager.AddToDeleteList(objects1)

Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete

Dim nErrs4 As Integer
nErrs4 = theSession.UpdateManager.DoUpdate(markId8)

theSession.DeleteUndoMark(markId7, Nothing)

' ----------------------------------------------
' Menu: Format->Layer Settings...
' ----------------------------------------------
Dim markId9 As NXOpen.Session.UndoMarkId
markId9 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Start")

theSession.SetUndoMarkName(markId9, "Layer Settings Dialog")

Dim stateArray3(0) As NXOpen.Layer.StateInfo
stateArray3(0) = New NXOpen.Layer.StateInfo(256, NXOpen.Layer.State.Selectable)
workPart.Layers.ChangeStates(stateArray3, False)

Dim stateArray4(0) As NXOpen.Layer.StateInfo
stateArray4(0) = New NXOpen.Layer.StateInfo(256, NXOpen.Layer.State.Visible)
workPart.Layers.ChangeStates(stateArray4, False)

theSession.SetUndoMarkName(markId9, "Layer Settings")

theSession.DeleteUndoMark(markId9, Nothing)

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

If you have a reference to a drawing sheet, you can get all the views on that sheet with the .GetDraftingViews method. Now you have references to all the views on the sheet and you can move them to the new sheet.

Do you maybe have a example of this kind of script?

Ruud van den Brand

NX CAD-Engineer

Below is a journal that will create a new drawing sheet based on the options of the current sheet and will move the drafting views to the new sheet.

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 move drafting views")

lw.Open()

lw.Close()

'get current sheet options
Dim startSheet As Drawings.DrawingSheet = theSession.Parts.Work.DrawingSheets.CurrentDrawingSheet
Dim drawingSheetBuilder1 As Drawings.DrawingSheetBuilder
drawingSheetBuilder1 = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(startSheet)
Dim curSheetOption As Drawings.DrawingSheetBuilder.SheetOption = drawingSheetBuilder1.Option
Dim curSheetViewCreation As Boolean = drawingSheetBuilder1.AutoStartViewCreation
Dim curSheetHeight As Double = drawingSheetBuilder1.Height
Dim curSheetLength As Double = drawingSheetBuilder1.Length
Dim curSheetMetricScale As Drawings.DrawingSheetBuilder.SheetStandardMetricScale = drawingSheetBuilder1.StandardMetricScale
Dim curSheetEnglishScale As Drawings.DrawingSheetBuilder.SheetStandardEnglishScale = drawingSheetBuilder1.StandardEnglishScale
Dim curSheetUnits As Drawings.DrawingSheetBuilder.SheetUnits = drawingSheetBuilder1.Units
Dim curSheetProjectionAngle As Drawings.DrawingSheetBuilder.SheetProjectionAngle = drawingSheetBuilder1.ProjectionAngle
drawingSheetBuilder1.Destroy()

Dim viewsToMove() As Drawings.DraftingView = startSheet.GetDraftingViews

'create new sheet based on current sheet options
Dim nullDrawings_DrawingSheet As Drawings.DrawingSheet = Nothing
Dim drawingSheetBuilder2 As Drawings.DrawingSheetBuilder = theSession.Parts.Work.DrawingSheets.DrawingSheetBuilder(nullDrawings_DrawingSheet)
With drawingSheetBuilder2
.Option = curSheetOption
.AutoStartViewCreation = curSheetViewCreation
.Height = curSheetHeight
.Length = curSheetLength
.StandardMetricScale = curSheetMetricScale
.StandardEnglishScale = curSheetEnglishScale
.Units = curSheetUnits
.ProjectionAngle = curSheetProjectionAngle
.Name = "journal_sheet"
End With

Dim newSheet As Drawings.DrawingSheet
newSheet = drawingSheetBuilder2.Commit()

drawingSheetBuilder2.Destroy()

theSession.Parts.Work.DraftingViews.MoveViewsToDrawing(viewsToMove, newSheet)

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image immediately after execution within NX
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

'----Other unload options-------
'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

'Unloads the image explicitly, via an unload dialog
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
'-------------------------------

End Function

End Module