×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

Try this. Below method will help you.

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

(OP)
Thanks SelvarajC, you just made my day :D
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

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal

Sub Main

		Dim theSession As Session = NXOpen.Session.GetSession()
		Dim workPart As Part = theSession.Parts.Work
		' Set the layer No.
		Dim layerNo As Integer = 201

		Dim currentSheet As NXOpen.Drawings.DrawingSheet = workPart.DrawingSheets.CurrentDrawingSheet

		Dim state As NXOpen.Layer.State = workPart.Layers.GetState(layerNo)

		If state <> NXOpen.Layer.State.Selectable Then
			workPart.Layers.SetState(layerNo, NXOpen.Layer.State.Selectable)
		End If
		currentSheet.View.Fit()
		Dim sheetObjects As DisplayableObject() = currentSheet.View.AskVisibleObjects()
		theSession.UpdateManager.ClearDeleteList()
		Dim markId1 As NXOpen.Session.UndoMarkId
		markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Delete")

		For Each item As DisplayableObject In sheetObjects
			If item.Layer = layerNo Then
				theSession.UpdateManager.AddToDeleteList(item)
			End If
		Next

		theSession.UpdateManager.DoUpdate(markId1)

		workPart.Layers.SetState(layerNo, state)

	End Sub
	Public Function GetUnloadOption(dummy As String) As Integer
		Return CInt(Session.LibraryUnloadOption.Immediately)
	End Function

End Module 

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources