NXOpen UG二次开发

本文详细介绍了如何在UG中创建自定义菜单,包括安装UG版本、创建启动文件夹和模具.men文件,以及通过编程添加主菜单和子菜单。重点讲解了如何设计对话框,如知识检索、方案推荐和属性赋值,并展示了如何调用MFC应用和管理参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、创建ug菜单

1、安装ug110.0版本

2、在Program Files\Siemens\NX 10.0\TKLTOOLS目录下创建“startup”文件夹,在文件夹中创建“模具.men”文件

3、添加代码

VERSION 120
EDIT UG_GATEWAY_MAIN_MENUBAR         //编辑ug的主菜单

AFTER UG_HELP                 		 //在help后面添加
	CASCADE_BUTTON moju  			 //定义ID 
	LABEL 模具  					    //标签名字(显示的名字)
END_OF_AFTER

MENU moju   						 //设计ID为moju的子菜单
BUTTON 111  						 //定义第一个按钮的ID
LABEL 知识检索  					  //标签名字(显示的名字)
BITMAP       						 //可以添加图案
ACTIONS webjiansuo 					 //需要链接的dll文件名(dll文件为点击该按钮后弹出的对话框)

BUTTON 222
LABEL 方案推荐
BITMAP
ACTIONS FangAnTuiJian

BUTTON 333
LABEL 人工审核
BITMAP
ACTIONS evaluate

END_OF_MENU   

​ 4、添加环境变量

​ [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GmQPZMaB-1657869876988)(C:\Users\123\Desktop\1.png)]

二、设计对话框

1、打开ug,点击:新建–>确定–>启动–>所有应用模具–>块UI样式编辑器。

2、设计对话框的样式,按钮,下拉框,显示的内容等。

3、 设计完成后,点击:代码生成,语言选择c++

4、点击:文件–>保存,选择保存路径,点击:OK。会保存后缀分别为“.dlx”, ".h"和“.cpp”的文件

三、编辑对话框

1、打开visual studo软件,新建项目,选择NX10 NXopen Wizard 点击新建;

2、新建完成后删除存在的cpp文件,将第二步生成的“.h”和“.cpp”添加到新建的项目中。弹出的对话框中语言选择c++;下一步选择

Automatically (ufsta) 和Automatically, when the NX session terminates ;点击完成。

3、在“.h”中引入头文件

#include <Windows.h>

#ifdef CreateDialog
#undef CreateDialog
#endif


#include <uf.h>
#include <uf_ui.h>
#include <uf_exit.h>
#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/ModelingView.hxx>
#include <NXOpen/ModelingViewCollection.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <uf_ui.h>
#include <uf_ui_ugopen.h>
#include <uf.h>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/selection.hxx>
#include <NXOpen/Features_Feature.hxx>
#include <NXOpen/ListingWindow.hxx>
#include <uf_obj.h>
#include <uf_attr.h>
#include <uf_cfi.h>
#include <uf_curve.h>
#include <uf_modl_primitives.h>
#include <stdlib.h>
#include <uf_modl.h>

#include <uf_defs.h>
#include <uf_ui_types.h>
#include <iostream>
#include <NXOpen/Session.hxx>
#include <NXOpen/UI.hxx>
#include <NXOpen/NXMessageBox.hxx>
#include <NXOpen/Callback.hxx>
#include <NXOpen/NXException.hxx>
#include <NXOpen/BlockStyler_UIBlock.hxx>
#include <NXOpen/BlockStyler_BlockDialog.hxx>
#include <NXOpen/BlockStyler_PropertyList.hxx>
#include <NXOpen/BlockStyler_Enumeration.hxx>
#include <NXOpen/BlockStyler_Group.hxx>
#include <NXOpen/BlockStyler_Button.hxx>


#include <uf_defs.h>
#include <NXOpen/NXException.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Assemblies_AssembliesGeneralPropertiesBuilder.hxx>
#include <NXOpen/Assemblies_AssembliesParameterPropertiesBuilder.hxx>
#include <NXOpen/Assemblies_Component.hxx>
#include <NXOpen/Assemblies_ComponentAssembly.hxx>
#include <NXOpen/Assemblies_SelectComponentList.hxx>
#include <NXOpen/AttributeManager.hxx>
#include <NXOpen/AttributePropertiesBaseBuilder.hxx>
#include <NXOpen/AttributePropertiesBuilder.hxx>
#include <NXOpen/BasePart.hxx>
#include <NXOpen/Builder.hxx>
#include <NXOpen/DateBuilder.hxx>
#include <NXOpen/DateItemBuilder.hxx>
#include <NXOpen/DateItemBuilderList.hxx>
#include <NXOpen/Expression.hxx>
#include <NXOpen/MassPropertiesBuilder.hxx>
#include <NXOpen/NXObject.hxx>
#include <NXOpen/ObjectGeneralPropertiesBuilder.hxx>
#include <NXOpen/Part.hxx>
#include <NXOpen/PartCollection.hxx>
#include <NXOpen/PropertiesManager.hxx>
#include <NXOpen/SelectNXObjectList.hxx>
#include <NXOpen/SelectObjectList.hxx>
#include <NXOpen/Session.hxx>
#include <NXOpen/Update.hxx>
#include <NXOpen/NXObjectManager.hxx>

四、在“.cpp"中添加添加属性函数

1、方案评估代码

void messaage()函数 //给对象添加属性

/* Initialize the API environment */
	if (UF_CALL(UF_initialize()))
	{
		return;
	}

	//获取所选择对象的标签
	tag_t tagUnderFace = 0;
	std::vector<TaggedObject*>objects = this->selection0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
	for (int i = 0; i<objects.size(); i++)
	{
		tagUnderFace = objects[i]->Tag();
	}

	UF_ATTR_value_t value;
	//分配一个“字符串”属性给对象
	PropertyList*  enumProps = enum01->GetProperties();//获取零件类型的标签(Type为零件类型的ID)
	NXString enumValue = enumProps->GetEnumAsString("Value");//获取零件类型的值的标签
	string a = enumValue.GetLocaleText();//获取该值
	char c_enum01[150];
	strcpy(c_enum01, a.c_str());
	char * p = (char*)a.data();//转成char类型
	value.type = UF_ATTR_string; //string类型
	value.value.string = p; //value为零件类型的值
	UF_CALL(UF_ATTR_assign(tagUnderFace, "注塑模类型", value));//为指定的对象分配属性

	enumProps = enum02->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum02[50];
	strcpy(c_enum02, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "分型面形式", value));

	enumProps = enum03->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum03[50];
	strcpy(c_enum03, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "抽芯机构", value));

	enumProps = enum04->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum04[50];
	strcpy(c_enum04, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "脱模机构", value));

	enumProps = enum05->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum05[50];
	strcpy(c_enum05, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "复位机构", value));

	enumProps = enum06->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum06[50];
	strcpy(c_enum06, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "浇口", value));

	enumProps = enum07->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum07[50];
	strcpy(c_enum07, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "温控方式", value));

	enumProps = enum08->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum08[50];
	strcpy(c_enum08, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "冷却方式", value));

	enumProps = enum010->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum010[50];
	strcpy(c_enum010, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "基本体素", value));

	enumProps = enum011->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum011[50];
	strcpy(c_enum011, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "构件类", value));

	enumProps = enum012->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum012[50];
	strcpy(c_enum012, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "绘制特征", value));

	enumProps = enum013->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum013[50];
	strcpy(c_enum013, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "位置特征", value));

	enumProps = enum018->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum018[50];
	strcpy(c_enum018, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "元截面的比例关系", value));

	enumProps = enum020->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum020[50];
	strcpy(c_enum020, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "内浇道位置", value));

	enumProps = enum021->GetProperties();
	enumValue = enumProps->GetEnumAsString("Value");
	a = enumValue.GetLocaleText();
	char c_enum021[50];
	strcpy(c_enum021, a.c_str());
	p = (char*)a.data();
	value.type = UF_ATTR_string;
	value.value.string = p;
	UF_CALL(UF_ATTR_assign(tagUnderFace, "浇注速度和温度", value));

//打开mfc设计的对话框
	WinExec("D:\\Program Files\\Siemens\\NX 10.0\\TKLTOOLS\\application\\MFCApplication1.exe", SW_SHOW);

void evaluate::showDlag()函数 // 显示与隐藏对话框中的不同栏

int enumVale = this->enum0->GetProperties()->GetEnum("Value");
	if (enumVale == 0)
	{
		this->group00->GetProperties()->SetLogical("Show", true);   //true为显示
		this->group10->GetProperties()->SetLogical("Show", true);
		this->group01->GetProperties()->SetLogical("Show", false);   //false为隐藏
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 1)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", true);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 2)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", true);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 3)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", true);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 4)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", true);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 5)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", true);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 6)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", true);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 7)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", true);
		this->group08->GetProperties()->SetLogical("Show", false);
	}
	else if (enumVale == 8)
	{
		this->group00->GetProperties()->SetLogical("Show", false);
		this->group10->GetProperties()->SetLogical("Show", false);
		this->group01->GetProperties()->SetLogical("Show", false);
		this->group02->GetProperties()->SetLogical("Show", false);
		this->group03->GetProperties()->SetLogical("Show", false);
		this->group04->GetProperties()->SetLogical("Show", false);
		this->group05->GetProperties()->SetLogical("Show", false);
		this->group06->GetProperties()->SetLogical("Show", false);
		this->group07->GetProperties()->SetLogical("Show", false);
		this->group08->GetProperties()->SetLogical("Show", true);
	}


给零件添加注塑机参数

	if (UF_CALL(UF_initialize()))
			{
				return 0;
			}
//寻找对象标签
			tag_t tagUnderFace = 0;
			std::vector<TaggedObject*>objects = this->selection0->GetProperties()->GetTaggedObjectVector("SelectedObjects");
			for (int i = 0; i<objects.size(); i++)
			{
				tagUnderFace = objects[i]->Tag();
			}

//添加属性
			UF_ATTR_value_t value;
			
			Injection *dialogInjection = new Injection(); //注塑机参数设置对话框
			dialogInjection->Show();//显示该对话框
			
			NXString str = dialogInjection->v_strValue[0];
			string a = str.GetLocaleText();
			char str0[150];
			strcpy(str0, a.c_str());
			char *p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "螺杆直径(mm)", value));


			str = dialogInjection->v_strValue[1]; //
			a = str.GetLocaleText();
			char str01[150];//
			strcpy(str01, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "螺杆长径比(L/D)", value));//

			str = dialogInjection->v_strValue[2]; //
			a = str.GetLocaleText();
			char str02[150];//
			strcpy(str02, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "螺杆压缩比", value));//

			str = dialogInjection->v_strValue[3]; //
			a = str.GetLocaleText();
			char str03[150];//
			strcpy(str03, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "螺杆行程(cm)", value));//

			str = dialogInjection->v_strValue[4]; //
			a = str.GetLocaleText();
			char str04[150];//
			strcpy(str04, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "理论注射容积(cm^3)", value));//

			str = dialogInjection->v_strValue[5]; //
			a = str.GetLocaleText();
			char str05[150];//
			strcpy(str05, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "最大注重量(g)", value));//

			str = dialogInjection->v_strValue[6]; //
			a = str.GetLocaleText();
			char str06[150];//
			strcpy(str06, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "螺杆最大转速(r/min)", value));//

			str = dialogInjection->v_strValue[7]; //
			a = str.GetLocaleText();
			char str07[150];//
			strcpy(str07, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "最大塑化能力(kg/h)", value));//

			str = dialogInjection->v_strValue[8]; //
			a = str.GetLocaleText();
			char str08[150];//
			strcpy(str08, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "注射压力(MPa)", value));//

			str = dialogInjection->v_strValue[9]; //
			a = str.GetLocaleText();
			char str09[150];//
			strcpy(str09, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "注射速度(g/s)", value));//

			str = dialogInjection->v_strValue[10]; //
			a = str.GetLocaleText();
			char str010[150];//
			strcpy(str010, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "注射时间(s)", value));//

			str = dialogInjection->v_strValue[11]; //
			a = str.GetLocaleText();
			char str011[150];//
			strcpy(str011, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "注射座推力及喷嘴推力(kN)", value));//

			str = dialogInjection->v_strValue[12]; //
			a = str.GetLocaleText();
			char str012[150];//
			strcpy(str012, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "喷嘴行程(cm)", value));//

			str = dialogInjection->v_strValue[13]; //
			a = str.GetLocaleText();
			char str013[150];//
			strcpy(str013, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "锁模力(ton)", value));//

			str = dialogInjection->v_strValue[14]; //
			a = str.GetLocaleText();
			char str014[150];//
			strcpy(str014, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "最大容模量(mm)", value));//

			str = dialogInjection->v_strValue[15]; //
			a = str.GetLocaleText();
			char str015[150];//
			strcpy(str015, a.c_str());//
			p = (char*)a.data();
			value.type = UF_ATTR_string;
			value.value.string = p;
			UF_CALL(UF_ATTR_assign(tagUnderFace, "开模行程(mm)", value));//
			delete dialogInjection;
			delete p;

2、方案推荐代码

对话框设计同第二步

只添加了打开mfc的函数

	#include   "windows.h "                                   //需要该头文件
	WinExec("D:\\Program Files\\Siemens\\NX 10.0\\TKLTOOLS\\application\\MFCApplication1.exe", SW_SHOW);

3、知识检索与知识索引没有设计对话框,知识添加了打开mfc对话框的函数

#include   "windows.h "                                   //需要该头文件
WinExec("D:\\Program Files\\Siemens\\NX 10.0\\TKLTOOLS\\application\\MFCApplication1.exe", SW_SHOW);

4、mfc对话框只添加了打开网址的控件

五、将设计的对话框添加到ug

1、将所写vs项目,生成为dll文件

2、在Program Files\Siemens\NX 10.0\TKLTOOLS目录下创建”application“文件夹

3、将第二部中生成的dlx文件和vs生成的dll文件保存到该文件夹下

4、在第一步,在每个子菜单对应的按钮中添加dll文件名,例:在ACTIONS后添加文件名

BUTTON 111  						 //定义第一个按钮的ID
LABEL 知识检索  					  //标签名字(显示的名字)
BITMAP       						 //可以添加图案
ACTIONS webjiansuo 					 //需要链接的dll文件名(dll文件为点击该按钮后弹出的对话框)
<think>嗯,用户问的是关于NX Open UG二次开发中如何获取点的tag。首先,我需要回忆一下NX Open的基本知识。NX Open是西门子NX软件的API,用于自动化任务和定制功能。用户可能是在进行建模或者CAM相关的开发,需要访问几何元素的信息,比如点。 首先,确定用户提到的“点”是指哪种类型的点。在NX中,点可能有多种形式,比如基准点、曲线上的点、特征中的点,或者是通过坐标创建的点对象。不同的点类型可能需要不同的方法来获取它们的tag。 接下来,思考如何访问这些点。通常,在NX Open中,所有的对象都有一个Tag属性,作为其在会话中的唯一标识。要获取这个tag,首先需要获得该对象的引用。例如,如果用户创建了一个点特征,可能需要使用Features.PointFeature类来获取该点的Tag。 另外,用户可能是在处理已有的模型,需要遍历部件中的点对象。这时候可能需要使用Part.Layers或者Part.Bodies来遍历所有对象,然后检查每个对象的类型是否为Point。或者,使用Selection类让用户手动选择一个点,然后获取其Tag。 可能还需要考虑点在其他结构中的情况,比如在草图(Sketch)中的点,或者在装配中的组件中的点。这时候可能需要更具体的上下文信息,比如当前的工作部件或者特定的特征。 需要注意的是,NX Open有多个语言支持,比如C++、VB.NET、C#等,不同的语言语法可能略有不同,但基本思路是一致的。用户可能需要根据自己使用的编程语言来调整代码示例。 此外,异常处理也是需要考虑的,比如当没有选中点或者点不存在时,如何处理错误,避免程序崩溃。可能需要使用try-catch块来捕获异常,并给出提示信息。 最后,总结一下可能的步骤:确定点的来源(创建、选择、遍历)→ 使用相应的方法获取对象引用 → 访问Tag属性。同时,提醒用户注意对象的类型和上下文,确保正确获取tag。</think>在NX Open二次开发中,获取点的Tag(对象标识符)是常见的操作。以下是几种典型场景的实现方法: ### 1. **创建点并获取Tag** ```csharp using NXOpen; // 获取当前工作部件 Part workPart = theSession.Parts.Work; // 创建点坐标 Point3d coord = new Point3d(10.0, 20.0, 30.0); // 创建点对象 Features.PointFeature pointFeature = workPart.Features.CreatePointFeature(null, coord); // 获取点的Tag Tag pointTag = pointFeature.Tag; ``` ### 2. **通过选择集获取点Tag** ```csharp using NXOpen.UF; // 初始化UFun UFSession ufSession = UFSession.GetUFSession(); // 选择单个点对象 Tag selectedTag; ufSession.UI.SelectWithSingleDialog("请选择一个点", "", out selectedTag); ``` ### 3. **遍历部件内所有点** ```csharp foreach (NXObject obj in workPart.Layers.GetAllObjectsOnLayer(0)) { if (obj is Point) { Tag pointTag = obj.Tag; // 处理点对象... } } ``` ### 4. **在草图中获取点** ```csharp Sketch sketch = workPart.Sketches.Create("MY_SKETCH"); // 创建草图点后获取Tag SketchPoint skPoint = sketch.CreatePoint(new Point3d(5,5,0)); Tag skPointTag = skPoint.Tag; ``` ### 关键注意事项: - **Tag本质**:Tag是NX对象在内存中的唯一标识符(uint类型数字) - **对象类型校验**:建议先用`obj is Point`判断是否为点对象 - **跨部件操作**:装配环境下需注意工作部件的切换(`SetWorkComponent`) - API版本:不同NX版本API可能有细微差异,建议查阅对应版本的NX Open文档 实际开发中推荐结合NX Open的**对象选择器(UI.GetUI().SelectionManager)**和**特征遍历**方法灵活获取目标点对象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值