NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal
NX 二次开发源码分享: 直接获取CAM对象类型 C#直接播放Jornal 就可以使用了using System;
using NXOpen;
using NXOpen.UF;
using NXOpen.Utilities;
using NXOpen.CAM;
using NXOpen.Assemblies;
static class GetSubTypeToOperation
{
static Session theSession;
static UFSession theUfSession;
private static UI theUI;
public static void Main()
{
theSession = Session.GetSession();
theUfSession = UFSession.GetUFSession();
Part workPart = theSession.Parts.Work;
theUI = UI.GetUI();
if (workPart == null)
{
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "A Part must be Opened.");
return;
}
theSession.EnableRedo(false);
if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
SystemInfo(theUfSession.Part, workPart);
try
{
Tag[] operTag;
Tag setupTag = Tag.Null;
int countObject = 0;
theUfSession.Cam.InitSession();
theUfSession.Setup.AskSetup(out setupTag);
if (setupTag == Tag.Null)
{
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "No Cam Setup in this Part.");
return;
}
theUfSession.UiOnt.AskSelectedNodes(out countObject, out operTag);
if (countObject == 0)
{
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, "An Operation must be Selected.");
return;
}
for (int i = 0; i < countObject; i++)
{
int type, subType;
theUfSession.Obj.AskTypeAndSubtype(operTag, out type, out subType);
NXObject camObject = (NXObject)(NXObjectManager.Get(operTag));
if (type == UFConstants.UF_machining_operation_type)
{
NXOpen.CAM.Operation operation = (NXOpen.CAM.Operation)(NXObjectManager.Get(operTag));
GetOperationSubType(operation);
} /* if type */
} /* for int i = 0 */
}
catch (NXOpen.NXException ex)
{
UI.GetUI().NXMessageBox.Show("Message", NXMessageBox.DialogType.Error, ex.Message);
}
}
/// <summary>
/// Retrieve the Operation Subtype
/// </summary>
/// <param name="operation">The Operation to Query</param>
/// <returns>Return the Subtype Operation</returns>
public static int GetOperationSubType(NXOpen.CAM.Operation operation)
{
if (operation == null) return -1;
int type = 0;
int subType = 0;
try
{
theUfSession.Obj.AskTypeAndSubtype(operation.Tag, out type, out subType);
theSession.ListingWindow.WriteFullline("Operation : " + operation.Name.ToString() + " -> Type " + type + " SubType : " + subType + " -> Operation GetType : " + operation.GetType().Name.ToString());
/* If needed to Switch to Operation Subtype (uf_object_types.h)*/
switch (subType)
{
case UFConstants.UF_mach_pocket_subtype: /* Planar Milling Operation */
case UFConstants.UF_mach_cavity_milling_subtype: /* Cavity Milling Operation */
case UFConstants.UF_mach_face_milling_subtype: /* Face Milling Operation */
case UFConstants.UF_mach_zlevel_milling_subtype: /* Z-Level Milling Operation */
case UFConstants.UF_mach_groove_milling_subtype: /* Groove Milling Operation */
case UFConstants.UF_mach_cylinder_milling_subtype: /* Hole Milling Operation */
case UFConstants.UF_mach_chamfer_milling_subtype: /* Chamfer Milling Operation */
case UFConstants.UF_mach_radial_groove_milling_subtype: /* Radial Groove Milling Operation */
case UFConstants.UF_mach_surface_contour_subtype: /* Fixed Contour Operation */
case UFConstants.UF_mach_plunge_milling_subtype: /* Plunge Milling Operation */
case UFConstants.UF_mach_vasc_subtype: /* Variable Contour Operation */
case UFConstants.UF_mach_vazl_milling_subtype: /* Z-Level 5 Axis */
case UFConstants.UF_mach_thread_milling_subtype: /* Thread Milling Operation */
case UFConstants.UF_mach_fb_hole_milling_subtype: /* Hole Making Operation (Legacy) */
case UFConstants.UF_mach_hole_drilling_subtype: /* Drilling Cycle */
case UFConstants.UF_mach_mill_ud_subtype: /* User Mill Defined Operation */
case UFConstants.UF_mach_gmc_subtype: /* Generic Motion Operation */
case UFConstants.UF_mach_mill_mc_subtype: /* Mill Control */
case UFConstants.UF_mach_gssm_main_op_subtype: /* Sequential Milling */
case UFConstants.UF_mach_hole_making_subtype: /* Hole Making (Legacy) */
case UFConstants.UF_mach_planar_additive_subtype: /* Additive */
case UFConstants.UF_insp_tolerance_subtype:
case UFConstants.UF_insp_path_subtype:
case UFConstants.UF_insp_output_subtype:
case UFConstants.UF_insp_misc_subtype:
case UFConstants.UF_insp_align_subtype:
case UFConstants.UF_insp_sensor_subtype:
case UFConstants.UF_insp_construct_subtype:
case UFConstants.UF_insp_bounding_feature_subtype:
case UFConstants.UF_insp_feature_subtype:
case UFConstants.UF_mach_canned_cycle_subtype:
case UFConstants.UF_mach_laser_teachmode_subtype:
case UFConstants.UF_mach_turn_rough_subtype:
case UFConstants.UF_mach_turn_finish_subtype:
case UFConstants.UF_mach_turn_teachmode_subtype:
case UFConstants.UF_mach_turn_thread_subtype:
case UFConstants.UF_mach_turn_cdrill_subtype:
case UFConstants.UF_mach_turn_auxiliary_subtype:
case UFConstants.UF_mach_turn_probing_subtype:
case UFConstants.UF_mach_turn_tool_probing_subtype:
case UFConstants.UF_mach_lathe_mc_subtype:
case UFConstants.UF_mach_lathe_ud_subtype:
case UFConstants.UF_mach_wedm_subtype:
case UFConstants.UF_mach_wedm_mc_subtype:
case UFConstants.UF_mach_wedm_ud_subtype:
case UFConstants.UF_mach_mass_edit_subtype:
break;
default:
theSession.ListingWindow.WriteFullline("Unknown Operation SubType.");
break;
}
}
catch (NXException nXException)
{
theUI.NXMessageBox.Show("Operation", NXMessageBox.DialogType.Error, "Unable to Query Operation. Error : " + nXException.Message.ToString());
subType = -1;
}
return subType;
}
/// <summary>
/// Display System Information
/// </summary>
/// <param name="uFPart">The UFPart to Query</param>
/// <param name="workPart">The Work Part to Query</param>
static void SystemInfo(UFPart uFPart, Part workPart)
{
try
{
SystemInfo sysInfo = default(SystemInfo);
theUfSession.UF.AskSystemInfo(out sysInfo);
string partName = string.Empty;
if (workPart != null) uFPart.AskPartName(workPart.Tag, out partName);
if (!theSession.ListingWindow.IsOpen) theSession.ListingWindow.Open();
theSession.ListingWindow.WriteFullline("============================================================");
theSession.ListingWindow.WriteFullline("Information Listing Created by : " + sysInfo.user_name.ToString());
theSession.ListingWindow.WriteFullline("Date : " + sysInfo.date_buf.ToString());
if (workPart != null) theSession.ListingWindow.WriteFullline("Current Work Part : " + partName);
theSession.ListingWindow.WriteFullline("Node Name : " + sysInfo.node_name.ToString());
theSession.ListingWindow.WriteFullline("============================================================\n\n");
}
catch (NXException nXException)
{
theUI.NXMessageBox.Show("System Information", NXMessageBox.DialogType.Error, "Unable to Display System Information. Error : " + nXException.Message.ToString());
}
}
/// <summary>
/// Unload the Current Image
/// </summary>
/// <param name="arg">String Send by NX</param>
/// <returns>Unload Integer</returns>
public static int GetUnloadOption(string arg)
{
/* Unloads the Image Immediately */
return System.Convert.ToInt32(Session.LibraryUnloadOption.Immediately);
/* Unloads the Image Explicitly, via an Unload Dialog */
//return System.Convert.ToInt32(Session.LibraryUnloadOption.Explicitly);
/* Unloads the Image when the NX Session Terminates */
//return System.Convert.ToInt32(Session.LibraryUnloadOption.AtTermination);
}
}
页:
[1]