using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;
public class NXJournal
{
public static void Main(string[] args)
{
// Get sessions
Session theSession = Session.GetSession();
UFSession ufs = UFSession.GetUFSession();
UI theUI = UI.GetUI();
Part workPart = theSession.Parts.Work;
// Define selection filters: point, curve, face
Selection.MaskTriple[] mask = new Selection.MaskTriple[3];
mask[0] = new Selection.MaskTriple
{
Type = UFConstants.UF_point_type,
Subtype = 0,
SolidBodySubtype = 0
};
mask[1] = new Selection.MaskTriple
{
Type = UFConstants.UF_line_type,
Subtype = 0,
SolidBodySubtype = 0
};
mask[2] = new Selection.MaskTriple
{
Type = UFConstants.UF_face_type,
Subtype = 0,
SolidBodySubtype = 0
};
// Declare selection result containers
NXObject[] selectedObjects;
Point3d cursor;
// Declare temporary variables for out parameters
NXObject[] tempSelectedObjects;
Point3d tempCursor;
// Prompt user to select objects
NXOpen.Selection.Response resp = theUI.SelectionManager.SelectObjects(
"Select points, curves, or surfaces",
"Select Geometry",
NXOpen.Selection.SelectionScope.WorkPart,
NXOpen.Selection.SelectionAction.ClearAndEnableSpecific,
false, // includeFeatures
false, // keepHighlighted
mask,
out tempSelectedObjects,
out tempCursor
);
selectedObjects = tempSelectedObjects;
cursor = tempCursor;
if (resp != NXOpen.Selection.Response.Ok || selectedObjects == null || selectedObjects.Length == 0)
return;
// Loop through selected objects
foreach (NXObject nxObj in selectedObjects)
{
if (nxObj is TaggedObject obj)
{
ufs.Obj.AskTypeAndSubtype(obj.Tag, out int objType, out int objSubtype);
int color = 1;
int layer = 1;
// Assign layer and color based on type
switch (objType)
{
case UFConstants.UF_point_type:
color = 186; // Red
layer = 11;
break;
case UFConstants.UF_line_type:
color = 27; // Blue
layer = 31;
break;
case UFConstants.UF_face_type:
color = 13; // Yellow
layer = 41;
break;
default:
continue;
}
// Apply display changes
if (obj is DisplayableObject displayObj)
{
DisplayModification displayMod = theSession.DisplayManager.NewDisplayModification();
displayMod.ApplyToAllFaces = true;
displayMod.ApplyToOwningParts = false;
displayMod.NewColor = color;
displayMod.NewLayer = layer;
displayMod.Apply(new DisplayableObject[] { displayObj });
displayMod.Dispose();
}
}
}
}
public static int GetUnloadOption(string dummy)
{
// Unload immediately after execution
return (int)Session.LibraryUnloadOption.Immediately;
}
}