Cancel
Showing results for 
Search instead for 
Did you mean: 

Not Able To Delete Drawing View

Creator
Creator

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

6 REPLIES

Re: Not Able To Delete Drawing View

Genius
Genius
Have you tried switching A0 and A1? Do you get any Exceptions/Errors during the run? Or is there just no action?

Not Able To Delete Drawing View

Creator
Creator

Hi,

I am not using NX default drawing function for changing the Sheet Size. I am doing it though .dll.

I have created a frame into the DrawingVIew and renamed it to "A0" , "A1".. etc.

 

Re: Not Able To Delete Drawing View

Genius
Genius
That is no problem :-)
I was speaking about your journal:
If leftstring = "A0" Then
DeleteViewByName(VName)
ElseIf leftstring = "A1" Then
DeleteViewByName(VName)
End if

should be edited to:
If leftstring = "A1" Then
DeleteViewByName(VName)
ElseIf leftstring = "A0" Then
DeleteViewByName(VName)
End if

And then you can see if A1 could be deleted. If yes, you have a problem in your sub routine, if no, you have a problem with the A1 Views...

Re: Not Able To Delete Drawing View

Creator
Creator

Hi,

I have tried by changing the sequance.

Still it is not working.

If I will delete the Baseview from the drawing then it is working fine.

 

So I think there is something with baseview properties.

Re: Not Able To Delete Drawing View

Gears Honored Contributor Gears Honored Contributor
Gears Honored Contributor

A DrawingView and a BaseView are two different types of drafting views. To handle both types, use the parent DraftingView class rather than the DrawingView class; change the following line:

 

For Each View1 As Drawings.DrawingView In drawingSheet1.SheetDraftingViews

to:

For Each View1 As Drawings.DraftingView In drawingSheet1.SheetDraftingViews

Not Able To Delete Drawing View

Creator
Creator

Hello,

 

Thansk for the help.

Now it is working as expected.