NX How to report an objects Type and Subtype using NXOpen

2023-05-24T21:17:22Z
NX Open

Summary


Details

Problem:

How to report an objects type and subtype using NXOpen?

Solution

An objects Type and Subtype can be found by passing any objects tag ( NXObject.Tag) into the UF_OBJ_ask_type_and_subtype(Tag tag, out Type, out Subtype) function.  The .NET wrapper for this function is theUfSession.obj.AskTypeAndSubtype();

The sample code used in this video:

using System;

using System.Collections.Generic;

using NXOpen;

using NXOpen.UF;

public class Program

{

// class members

private static Session theSession;

private static UI theUI;

private static UFSession theUfSession;

public static Program theProgram;

public static bool isDisposeCalled;

//------------------------------------------------------------------------------

// Constructor

//------------------------------------------------------------------------------

public Program()

{

try

{

theSession = Session.GetSession();

theUI = UI.GetUI();

theUfSession = UFSession.GetUFSession();

isDisposeCalled = false;

}

catch (NXOpen.NXException ex)

{

// ---- Enter your exception handling code here -----

// UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);

}

}

//------------------------------------------------------------------------------

// Explicit Activation

// This entry point is used to activate the application explicitly

//------------------------------------------------------------------------------

public static int Main(string[] args)

{

int retValue = 0;

try

{

theProgram = new Program();

//TODO: Add your application code here

theSession.ListingWindow.Open();

TaggedObject selobj;

while ((selobj = select_anything()) != null)

{

int type = 0;

int subtype = 0;

string descriptor = String.Empty;

theUfSession.Obj.AskTypeAndSubtype(selobj.Tag, out type, out subtype);

theSession.ListingWindow.WriteFullline("\nObject selected: " + selobj.ToString());

theSession.ListingWindow.WriteFullline(" Tag: " + selobj.Tag.ToString());

theSession.ListingWindow.WriteFullline(" Type: " + type.ToString());

theSession.ListingWindow.WriteFullline(" Subtype: " + subtype.ToString());

}

theProgram.Dispose();

}

catch (NXOpen.NXException ex)

{

// ---- Enter your exception handling code here -----

}

return retValue;

}

//------------------------------------------------------------------------------

// Select any object

//------------------------------------------------------------------------------

public static TaggedObject select_anything()

{

TaggedObject selobj;

Point3d cursor;

Selection.SelectionType[] typeArray =

{ Selection.SelectionType.All, Selection.SelectionType.Edges, Selection.SelectionType.Faces, Selection.SelectionType.Edges, Selection.SelectionType.Features };

theUfSession.Ui.SetCursorView(0);

Selection.Response resp = theUI.SelectionManager.SelectTaggedObject("Select anything", "Select anything",

Selection.SelectionScope.AnyInAssembly, false, typeArray, out selobj, out cursor);

if (resp == Selection.Response.ObjectSelected ||

resp == Selection.Response.ObjectSelectedByName)

{

return selobj;

}

else

return null;

}

//------------------------------------------------------------------------------

// Following method disposes all the class members

//------------------------------------------------------------------------------

public void Dispose()

{

try

{

if (isDisposeCalled == false)

{

//TODO: Add your application code here

}

isDisposeCalled = true;

}

catch (NXOpen.NXException ex)

{

// ---- Enter your exception handling code here -----

}

}

public static int GetUnloadOption(string arg)

{

//Unloads the image explicitly, via an unload dialog

//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);

//Unloads the image immediately after execution within NX

return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);

//Unloads the image when the NX session terminates

// return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);

}

}

KB Article ID# PL8719085

Contents

SummaryDetails

Associated Components

NX Open - All Languages