Forums:
Hello Guys,
I am trying to delete DrawingView searching by it's name.
It gets deleted for the first time. But if i will add any base view into drawing then it is not getting deleted.
As an example First i will add the view by Name "A0" then I will add Baseview and after that I will run below code so it will delete the A0 view.
After that I will add the view which name is "A1" and will run the code so at that time it will not delete the A1 view.
Can anyone please help me to solve this issue ?
Below is the code:
Option Strict Off Imports System Imports NXOpen Imports NXOpen.UF Module Module2 Sub Main() Dim workPart As Part Dim displayPart As Part Dim theSession As Session Dim DWGName As String Dim dwgShtBld As Drawings.DrawingSheetBuilder Dim drawingSheet1 As Drawings.DrawingSheet theSession = Session.GetSession() workPart = theSession.Parts.Work displayPart = theSession.Parts.Display dwgShtBld = workPart.DrawingSheets.DrawingSheetBuilder(workPart.DrawingSheets.CurrentDrawingSheet) drawingSheet1 = workPart.DrawingSheets.CurrentDrawingSheet DWGName = drawingSheet1.Name dwgShtBld.Commit() dwgShtBld.Destroy() Dim VName As String On Error Resume Next If DWGName = "SHEET 1" Then For Each View1 As Drawings.DrawingView In drawingSheet1.SheetDraftingViews VName = View1.Name Dim leftstring As String = VName.ToString().Substring(0, 2) If leftstring = "A0" Then DeleteViewByName(VName) ElseIf leftstring = "A1" Then DeleteViewByName(VName) End if Next End if On Error GoTo 0 End Sub Sub DeleteViewByName(ByVal Name As String) Dim workPart As Part Dim displayPart As Part Dim theSession As Session Dim drawingSheet1 As Drawings.DrawingSheet theSession = Session.GetSession() workPart = theSession.Parts.Work displayPart = theSession.Parts.Display drawingSheet1 = workPart.DrawingSheets.CurrentDrawingSheet Dim View As Drawings.DraftingViewCollection = workPart.DraftingViews Dim bodyname As String = Name For Each b As Drawings.DraftingView In View If b.Name = bodyname Then Dim markId1 As Session.UndoMarkId markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete") Dim notifyOnDelete1 As Boolean notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete theSession.UpdateManager.ClearErrorList() Dim nErrs1 As Integer nErrs1 = theSession.UpdateManager.AddToDeleteList(b) Dim nErrs2 As Integer nErrs2 = theSession.UpdateManager.DoUpdate(markId1) End If Next End Sub End Module