Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Journal to delete all object on layer 201 in active drafting sheet only 1

Status
Not open for further replies.

danuvi

Mechanical
Jul 15, 2015
2
0
0
CH
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
 
Replies continue below

Recommended for you

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:
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; }
}
 
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:
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
 
Status
Not open for further replies.
Back
Top