Journal to delete all object on layer 201 in active drafting sheet only
Journal to delete all object on layer 201 in active drafting sheet only
(OP)
I need to delete all objects on layer 201 in the work-active drafting sheet. I have found a good journal to begin with (It delets everything on layer 201 in the whole part). The problem is, if I have multiple drafting sheets it deletes the objects on layer 201 everywhere. I have completely no idea how to solve this problem. I hope someone could help me with this. :D
CODE
Sub Main
Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
If displayPart Is Nothing Then
Exit Sub
End If
Dim notifyOnDelete1 As Boolean
notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete
theSession.UpdateManager.ClearErrorList()
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(workPart.Layers.GetAllObjectsOnLayer(201))
End Sub 




RE: Journal to delete all object on layer 201 in active drafting sheet only
Conditions:
1. Objects must not be a hidden object.
2. Open the drawing sheet and run the journal
CODE --> C#
using System; using NXOpen; public class NXJournal { public static void Main(string[] args) { Session theSession = NXOpen.Session.GetSession(); Part workPart = theSession.Parts.Work; // Set the layer No. int layerNo = 201; NXOpen.Drawings.DrawingSheet currentSheet = workPart.DrawingSheets.CurrentDrawingSheet; NXOpen.Layer.State state = workPart.Layers.GetState(layerNo); if(state != NXOpen.Layer.State.Selectable) { workPart.Layers.SetState(layerNo, NXOpen.Layer.State.Selectable); } currentSheet.View.Fit(); DisplayableObject[] sheetObjects = currentSheet.View.AskVisibleObjects(); theSession.UpdateManager.ClearDeleteList(); NXOpen.Session.UndoMarkId markId1; markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete"); foreach (DisplayableObject item in sheetObjects) { if (item.Layer == layerNo) { theSession.UpdateManager.AddToDeleteList(item); } } theSession.UpdateManager.DoUpdate(markId1); workPart.Layers.SetState(layerNo, state); } public static int GetUnloadOption(string dummy) { return (int)Session.LibraryUnloadOption.Immediately; } }RE: Journal to delete all object on layer 201 in active drafting sheet only
Exactly what I was looking for. Works great
I however changed it to VB...
Heres the code if anyone finds this Post again.
CODE --> VB.NET