×
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

Deleting unused Planes

Deleting unused Planes

Deleting unused Planes

(OP)
Good morning.
Is there a way of deleting unused Planes (Not Datum Planes)without manually selecting them.
They are not in the 'Unused Items' list
Thanks in advance
Regards
Ian

RE: Deleting unused Planes

(OP)
... other than exporting the part, deleting everything and importing it back in!

RE: Deleting unused Planes

What ways did you have in mind other than manually selecting them ?
Do an Info -> object on one of those planes and post what it gives in the information window

Jerry J.
Milwaukee Electric Tool
http://www.milwaukeetool.com/

RE: Deleting unused Planes

(OP)
Thanks Jerry,
The text below is from info object of an unused Plane.
(Coordinates have been removed from the text for simplification)
The only thing the text will show you is that it is not used.

I use a few Journals for often used commands....
In a new part to set Preferences, Categories, Absolute Datum Plane & XYZ lines for controlling Draft & Extrude etc
In a working part to toggle ON/OFF Save Rollback Data and Compress Part to speed up large models.

My plan was to set up a Journal to delete unused planes as I use a lot in creating my models.
I use planes as opposed to trim sheets or subtracting a solid, because they are transparent, require minimal data and quick to find without cluttering my display.
============================================================
Information listing created by : it11066
Date : 08.05.2015 08:23:06
Current work part : 13491134/002
Node name : pcs313-055
============================================================
Information on object # 1

Owning part xxxxxxxxx/002
Layer 21
Type Plane
Color 69 (Dark Cyan Teal)
Font SOLID
Width Normal
Modified Version 214 02 Okt 2014 14:40 (by user itxxxxx)
Created Version 196 30 Sep 2014 17:24 (by user itxxxxx)

------------------------------------------------------------
Object Dependency Graph:
Plane - ID 1572762
Used by:
None

------------------------------------------------------------

RE: Deleting unused Planes

The following journal will attempt to delete any unused planes in the work part.

CODE

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

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "delete unused planes"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim planesToDelete As New List(Of Plane)

        For Each tempPlane As Plane In workPart.Planes

            Dim featTag As Tag = Tag.Null

            theUfSession.Modl.AskObjectFeat(tempPlane.Tag, featTag)
            If featTag = Tag.Null Then
                planesToDelete.Add(tempPlane)
            End If

        Next

        Dim markId2 As Session.UndoMarkId
        markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")

        Dim notifyOnDelete1 As Boolean
        notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

        theSession.UpdateManager.ClearErrorList()

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(planesToDelete.ToArray)

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

        lw.Close()

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module 

*Edited to correct the highlighted line

RE: Deleting unused Planes

(OP)
Thanks
I'll give it a go.

RE: Deleting unused Planes

(OP)
Hi Cowski,
I ran the Journal and keep getting an error message. See attached.(Not sure if it uploaded correctly)
'Undo Mark is missing' Line 51 error.
Do I need to prepare the file in any way?
Or did I miss something?
I ran it with only the 'Planes' layer on then off with no difference.
Thanks in Advance

RE: Deleting unused Planes

Whoops, there was a typo in the line indicated in the error message. I've edited the code above to correct it.

www.nxjournaling.com

RE: Deleting unused Planes

(OP)
Ok... we are progressing.
I forgot to mention that prior to the typo edit... ALL planes where being deleted.
I added some planes before I began using the first Journal just to be sure it was going to delete them.

Now I get a different Error. See attached
But NO planes are being deleted.

RE: Deleting unused Planes

What version of NX are you using?
Can you attach your test part file?

I'm using NX 9 and I have not been able to reproduce the error.

www.nxjournaling.com

RE: Deleting unused Planes

(OP)
I just updated my profile and added the NX9.0 TcAE10 info.
Sorry about that.
I can't send you the actual file, I'll make a new one in Native and see what happens.
May not get back to you until tomorrow.
Thanks
Ian

Automotive
EDAG Engineering Germany
GM Opel since 2007
NX9.0 TcAE 10

RE: Deleting unused Planes

That's strange. For my test file, I had created an associative datum plane that was offset from the plane object. The parent planes were not deleted, the unused ones were.

Anyway, here is an updated version. The strategy used is far from elegant, but it seems to work in our test cases.

CODE

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

Module Module2

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim lg As LogFile = theSession.LogFile

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Const undoMarkName As String = "delete unused planes"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow

        Dim planesToDelete As New List(Of Plane)

        For Each tempPlane As Plane In workPart.Planes

            Dim tempFile As String = IO.Path.GetTempFileName
            lg.WriteLine("tempFile: " & tempFile)

            lw.SelectDevice(ListingWindow.DeviceType.File, tempFile)
            lw.Open()

            theSession.Information.DisplayObjectsDetails({tempPlane})

            lw.Close()
            lw.SelectDevice(ListingWindow.DeviceType.Window, "")

            If Not IsUsed(tempFile) Then
                planesToDelete.Add(tempPlane)
            End If

            IO.File.Delete(tempFile)

        Next

        Dim markId2 As Session.UndoMarkId
        markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")

        Dim notifyOnDelete1 As Boolean
        notifyOnDelete1 = theSession.Preferences.Modeling.NotifyOnDelete

        theSession.UpdateManager.ClearErrorList()

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(planesToDelete.ToArray)

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


    End Sub

    Function IsUsed(ByVal theFile As String) As Boolean

        If Not IO.File.Exists(theFile) Then
            Throw New System.IO.FileNotFoundException
            lg.WriteLine("Error: file not found")
            'assume it is used so it is not marked for deletion
            Return True
        End If

        Dim line As String
        Dim checkNextLine As Boolean = False
        Dim usedBy As String


        Using sr As IO.StreamReader = New IO.StreamReader(theFile)
            Try
                line = sr.ReadLine()
                While Not line Is Nothing

                    If checkNextLine Then
                        usedBy = line
                        lg.WriteLine("used by: " & usedBy)
                        If usedBy.Trim.ToLower = "none" Then
                            lg.WriteLine("Function 'IsUsed' returning: False")
                            Return False
                        Else
                            lg.WriteLine("Function 'IsUsed' returning: True")
                            Return True
                        End If
                    End If

                    If line = "Used by:" Then
                        checkNextLine = True
                        lg.WriteLine("line: 'Used by:' found")
                    End If

                    line = sr.ReadLine()
                End While
            Catch E As Exception

            End Try
        End Using

    End Function

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module 

www.nxjournaling.com

RE: Deleting unused Planes

(OP)
Ooooh... fabtacular!
Just what I needed.
I don't need to find Datum Planes as any unused ones are shown in the 'Unused Items' list
in Part Navigator.
Many thanks
Until next time.
Have a good week
Regards
Ian

Automotive
EDAG Engineering Germany
NX9.0 TcAE 10

RE: Deleting unused Planes

The previous code did not look for or delete datum planes. Rather, in my test file I created a datum plane that was associated to a plane object. The code correctly recognized that the plane object was being used (as the parent object of the datum plane). However, apparently when used in a trim body command they are not recognized as the parent for some reason.

You might want to consider using fixed datum planes in place of the plane objects. Datum planes have better support (i.e. they don't have the same quirks).

Glad to hear the revised journal is working for you.

www.nxjournaling.com

RE: Deleting unused Planes

(OP)
Good morning,
Ok thanks. I don't like to have the Part Nav tree unnecessarily long, but I will reconsider that regarding planes.
CHeers

Automotive
EDAG Engineering Germany
NX9.0 TcAE 10

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