Delete all contents in Layer

Hello all,

Can anybody help me in delete all objects, lines, splines in a particular layer with journal. I have created section views in modeling and saved a copy in particular layers. But i want to completely erase all the splines and lines in the layer. It would be great help if somebody can help me.
Thanks in advance.

The following code will delete all curves in layer 256 (change this to the layer you want before running).


Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim curvesToDelete As New List(Of Curve)

'&&&&& layer number to delete objects from
Const layerToDelete As Integer = 256

If displayPart Is Nothing Then
'no part to work on
Exit Sub
End If

For Each tempObj As Curve In workPart.Curves
If tempObj.Layer = layerToDelete Then
curvesToDelete.Add(tempObj)
End If
Next

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(curvesToDelete.ToArray)

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

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

Thanks a lot, its perfectly working for me. I have posted one more thread regarding Creating Section View in drafting with Journal, if you have any code code please post it back.
Thank you once again

I would like to use this journal to erase all objects in a specific layer, not only curves. Is that possible?

You can use the .GetAllObjectsOnLayer() method to get all the objects on a particular layer; this method combined with the existing code will allow you to delete everything on a given layer.

Can you help me, please, with this modification in the code?

The journal below will attempt to delete all the objects on layer 16; change this to your desired layer before running the journal. Depending on your NX settings (specifically those in Modeling -> General -> Delete and suppress), the journal may not delete objects that are used as parents of features, or it may delete child objects on layer(s) other than the one specified.





Option Strict Off
Imports System
Imports NXOpen

Module Module16

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display

'&&&&& layer number to delete objects from
Const layerToDelete As Integer = 16

If displayPart Is Nothing Then
'no part to work on
Exit Sub
End If

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(workPart.Layers.GetAllObjectsOnLayer(layerToDelete))

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

End Sub

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

It worked perfectly. Thank you very much.

What change can I make to the above code to delete all features in the current drawing including titleblock, all notes, all layers except the existing views. Thanks in advanced.

Regards,
MFJ

If you have a multi-sheet drawing and only want to delete things from a specific sheet, you can test what sheet the object resides on with the following code:

http://nxjournaling.com/comment/1095#comment-1095

Is there a way to delete all objects in drafting mode text and annotations etc by color on multiple drafting sheets?

Paul Fillion