Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Deleting unused Planes

Status
Not open for further replies.

itaylor

Automotive
Apr 1, 2008
38
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
 
Replies continue below

Recommended for you

... other than exporting the part, deleting everything and importing it back in!
 
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
 
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

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

 
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
        [highlight #FCE94F]markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Delete")[/highlight]

        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
 
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
 
 http://files.engineering.com/getfile.aspx?folder=d5e8db70-82c2-4a00-8049-6e82cf0597e1&file=Journal_Execution_Error.jpg
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.
 
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
 
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
 
I've created a simple file in NX9 Native with planes used and unused trimming a block
When I run the journal I don't get an error message but all planes are deleted!!
Cheers & thanks


Automotive
EDAG Engineering Germany
NX9.0 TcAE 10
 
 http://files.engineering.com/getfile.aspx?folder=8bae1f86-2965-4306-8d55-b28f468e2823&file=Delete_Planes.prt
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor