How to get all unused entities in a model

Hi,

I am a newbie to NXOpen. I was trying to find all unused entities in a model. I am aware that using features collection I can loop through all features and find if they have children. However, I would like to also find entities that are non associative in nature (which are not listed in the part navigator). I tried using displayable object collection. But I could not find a method like GetChildren() for the displayable objects. Could someone tell me what approach i could use to accomplish this?

Thanks and best regards,
Navaneeth

You can use the .AskObjectFeat method to see if an object is used or not.
https://docs.plm.automation.siemens.com/data_services/resources/nx/1899/...

Below is a quick example:

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work

Dim featTag As Tag = Tag.Null

For Each myCurve As Curve In workPart.Curves
theUfSession.Modl.AskObjectFeat(myCurve.Tag, featTag)
If featTag = Tag.Null Then
'curve is unused
myCurve.Highlight()
End If
Next

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

Thanks for the code. I am doing it on C# and was trying to use the AskObjectFeat(). But apparently it left out some points and curves. i.e, although there were some unused curves and lines they did not return null tag. Am I missing something? The only difference between our codes is thatI am looping through all displayable objects while you are doing it only on curves collection. Please see my code below:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NXOpen;
using NXOpenUI;

namespace Find_unused_objects
{
public class Class1
{
public static void Main()
{
Session theSession = Session.GetSession();
NXOpen.UF.UFSession theUFSession = NXOpen.UF.UFSession.GetUFSession();
Part workPart = theSession.Parts.Work;
ListingWindow lw = theSession.ListingWindow;
lw.Open();
DisplayableObject[] objArray = workPart.ModelingViews.WorkView.AskVisibleObjects();
Tag featureTag;
foreach (DisplayableObject nxObject in objArray)
{
try
{
lw.WriteLine(nxObject.Layer.ToString());
theUFSession.Modl.AskObjectFeat(nxObject.Tag, out featureTag);
if (featureTag == Tag.Null)
{
//lw.WriteLine(nxObject.Tag.ToString());

nxObject.Highlight();
nxObject.RedisplayObject();

}

}
catch
{

}

}

}
public static int GetUnloadOption()
{
return 1;
}
}
}

I ran a quick test with your code and it seems to be working for me. Do you have a simple part where the code does not work? If so, can you email it to me?
info@nxjournaling.com

I have sent you a test part via email. Please let me know if you are also facing the same issue. For me it does not highlight unused points and datum planes.