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
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
RE: Deleting unused Planes
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
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
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
I'll give it a go.
RE: Deleting unused Planes
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
www.nxjournaling.com
RE: Deleting unused Planes
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
I think our Firewall prevents it so I have to copy & paste it into the box below.
Or am I doing it wrong?
Many thanks for your help.
RE: Deleting unused Planes
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
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
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
RE: Deleting unused Planes
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 Modulewww.nxjournaling.com
RE: Deleting unused Planes
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
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
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