当前位置: 首页 > news >正文

UG/NX二次开发Siemens官方NXOPEN实例解析—2.6 CreateNote

列文章目录

UG/NX二次开发Siemens官方NXOPEN实例解析—2.1 AssemblyViewer

UG/NX二次开发Siemens官方NXOPEN实例解析—2.2 Selection

UG/NX二次开发Siemens官方NXOPEN实例解析—2.3 Selection_UIStyler

UG/NX二次开发Siemens官方NXOPEN实例解析—2.4 File2Points

UG/NX二次开发Siemens官方NXOPEN实例解析—2.5 QuickExtrude

UG/NX二次开发Siemens官方NXOPEN实例解析—2.6 CreateNote


前言

        随着工业智能化的不断发展,UG二次开发的需求越来越多,也吸引了大批的二开从业人员,本人作为一名资深IT从业者(10年+)也毅然加入二次开发大军。

        然而,和流行IT行业(互联网、金融、医疗等)相比,工业智能化的门槛显得更高一点,专业的工业软件,相对封闭的开发理念和更小的开发圈子,让刚进入二开的从业者有点举步维艰。边学边整理,希望通过这系列文章的整理能给二开的生态增添一叶绿。


一、知识点提取

本实例主要实现了创建注释、拷贝注释,主要设计的知识点如下:

1、通过ug_default.sbf文件,加载注释列表

2、创建新的注释

3、选择已有注释,拷贝注释

二、案例需求分析

1、效果图

2、需求分解

1、通过ug_default.sbf文件,加载注释列表

2、创建新的注释

3、选择已有注释,拷贝注释

三、程序分析

1、源码所在目录

UGOPEN\SampleNXOpenApplications\C++\CreateNote

2、主要功能分析 

1、通过ug_default.sbf文件,加载注释列表

//Load all the symbols from current sbf file to the enum list
void CreateNote::LoadSbfFile()
{
	NXOpen::BlockStyler::PropertyList *sbfFileBrowseProps = sbfFileBrowse->GetProperties();
	NXOpen::NXString sbfFileBrowse1 = sbfFileBrowseProps->GetString("Path");	

	if(!strcmp(sbfFileBrowse1.GetText(),""))
	{
		char *rootDir=NULL;
		UF_translate_variable("UGII_ROOT_DIR",&rootDir);
		NXString symbolDir = rootDir ;
		sbfFileBrowseProps->SetString("Path", symbolDir + "\\ug_default.sbf");	
	}

	sbfFileBrowse1 = sbfFileBrowseProps->GetString("Path");	
	delete sbfFileBrowseProps;
	theSession->Parts()->Work()->Annotations()->SetCurrentSbfFile(sbfFileBrowse1.GetText());
	std::vector<NXString> symbolNames= theSession->Parts()->Work()->Annotations()->ReadAllSymbolNamesFromSbfFile();
	NXOpen::BlockStyler::PropertyList *symListProps = symList->GetProperties();	
	symListProps->SetEnumMembers("Value",symbolNames);
	delete symListProps;
}

这个方法里面包括了以下知识点:

1、获取环境变量的方法 UF_translate_variable("UGII_ROOT_DIR",&rootDir)

2、解析sbf文件方法theSession->Parts()->Work()->Annotations()->ReadAllSymbolNamesFromSbfFile()

2、创建新的注释 

if(!strcmp(noteType2.GetText(),"Create from user defined symbol"))
{
	NXOpen::BlockStyler::PropertyList *symListProps = symList->GetProperties();
	NXString text = symListProps->GetEnumAsString("Value");
	delete symListProps;
	double scaleVal = scale->GetProperties()->GetDouble("Value");
	double aspectRatioVal = aspectRatio->GetProperties()->GetDouble("Value");
	double symWidth[256],symHeight[256];
	NXOpen::SymbolFont *noteSymbol = theSession->Parts()->Work()->Annotations()->LoadSymbolFontFromSbfFile(text,symWidth,symHeight);
	userSymbolPreferences1 = theSession->Parts()->Work()->Annotations()->NewUserSymbolPreferences(Annotations::UserSymbolPreferences::SizeTypeScaleAspectRatio,scaleVal,aspectRatioVal);

	//Selected text of the symbol is converted to symbol
	text = "<%"  + text + ">";
	string noteText = text.GetText();
	std::remove(noteText.begin(),noteText.end(),' ');
	size_t pos1 = noteText.find_first_of(">");
	noteText = noteText.substr(0,++pos1);
	NXString text1 = noteText;
	stringArray1.push_back(text1.GetText());	
	NXOpen::BlockStyler::PropertyList *selLocationProps = selLocation->GetProperties();
	NXOpen::Point3d cursor = selLocationProps->GetPoint("CursorLocation");
	delete selLocationProps;

	//Creates note in the given location
	theSession->Parts()->Work()->Annotations()->CreateNote(stringArray1,cursor,AxisOrientationHorizontal,letteringPreferences1,userSymbolPreferences1);		
}

这个方法里面包括了以下知识点:

1、创建注释方法:theSession->Parts()->Work()->Annotations()->CreateNote()

2、获取点选坐标方法:NXOpen::Point3d cursor = selLocationProps->GetPoint("CursorLocation")

3、选择已有注释,拷贝注释

if(!strcmp(noteType2.GetText(),"Copy existing symbol"))
{
	std::vector<NXOpen::TaggedObject *>selectedObject;

	NXOpen::BlockStyler::PropertyList *selectNoteProps = selectNote->GetProperties();		
	selectedObject = selectNoteProps->GetTaggedObjectVector("SelectedObjects");
	delete selectNoteProps;

	NXOpen::BlockStyler::PropertyList *selLocationProps = selLocation->GetProperties();
	NXOpen::Point3d cursor = selLocationProps->GetPoint("CursorLocation");
	delete selLocationProps;

	//Here the user selected note/symbol is copied
	if (selectedObject.size()>0)
	{
		Annotations::Note *note1(dynamic_cast<Annotations::Note *>(selectedObject[0]));
		if(note1!=NULL)
		{				
			letteringPreferences1 = note1->GetLetteringPreferences();
			userSymbolPreferences1 = note1->GetUserSymbolPreferences(); 
			stringArray1 = note1->GetText();
			theSession->Parts()->Work()->Annotations()->CreateNote(stringArray1,cursor,AxisOrientationHorizontal,letteringPreferences1,userSymbolPreferences1);
		}
	}
}

1、获取选择注释对象方法:selectedObject = selectNoteProps->GetTaggedObjectVector("SelectedObjects");

2、获取点选坐标方法:NXOpen::Point3d cursor = selLocationProps->GetPoint("CursorLocation")

3、创建注释方法:theSession->Parts()->Work()->Annotations()->CreateNote()

4、 补充一个知识点,选择对象控件根据注释过滤的方法

selectNote = dynamic_cast<NXOpen::BlockStyler::UIBlock* >(theDialog->TopBlock()->FindBlock("selectNote"));
//Setting selection mask to select only drafting notes or symbols
NXOpen::Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vector<NXOpen::Selection::MaskTriple>selectionMask_array(2);
selectionMask_array[0].Type = UF_drafting_entity_type;
selectionMask_array[0].Subtype = UF_draft_note_subtype;
selectionMask_array[1].Type = UF_drafting_entity_type;
selectionMask_array[1].Subtype = UF_draft_label_subtype;
selLocation->GetProperties()->SetEnumAsString("StepStatus","Required");		
selectNote->GetProperties()->SetEnumAsString("StepStatus","Required");
selectNote->GetProperties()->SetSelectionFilter("SelectionFilter",action,selectionMask_array);

 

相关文章:

  • 斯坦福联合Meta提出多模态模型RA-CM3,检索增强机制或成文本图像领域新制胜法宝
  • Mit6.006-problemSession03
  • 高通Ride软件开发包使用指南(12)
  • 回调函数的基本使用
  • 艾美捷内皮血管生成检测试剂盒的多种特点
  • Java反射介绍
  • 【Spring专题】「开发指南」夯实实战基础功底之解读logback-spring.xml文件的详解实现
  • vue.config.js configureWebpack 对象和函数两种使用方法
  • 记录我の秋招之旅【23届 CV算法岗】
  • IHRM0728 项目参数化框架
  • 搜遍全网,终于找到了报表自动化的最佳工具,比Excel好用10倍
  • python自定义包实例
  • 用React做一个音乐播放器
  • 【计算机组成原理】期末复习
  • JVM - 内存区域划分 类加载机制 垃圾回收机制
  • 0基础学习移动端适配
  • 2017-08-04 前端日报
  • css系列之关于字体的事
  • JavaScript学习总结——原型
  • NLPIR语义挖掘平台推动行业大数据应用服务
  • Python学习笔记 字符串拼接
  • Redash本地开发环境搭建
  • SpiderData 2019年2月23日 DApp数据排行榜
  • SQLServer之创建显式事务
  • Three.js 再探 - 写一个跳一跳极简版游戏
  • v-if和v-for连用出现的问题
  • vue脚手架vue-cli
  • 反思总结然后整装待发
  • 构造函数(constructor)与原型链(prototype)关系
  • 基于webpack 的 vue 多页架构
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 融云开发漫谈:你是否了解Go语言并发编程的第一要义?
  • 如何优雅的使用vue+Dcloud(Hbuild)开发混合app
  • 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!
  • 完善智慧办公建设,小熊U租获京东数千万元A+轮融资 ...
  • #### go map 底层结构 ####
  • (30)数组元素和与数字和的绝对差
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (Redis使用系列) Springboot 使用redis的List数据结构实现简单的排队功能场景 九
  • (层次遍历)104. 二叉树的最大深度
  • (二)斐波那契Fabonacci函数
  • (附程序)AD采集中的10种经典软件滤波程序优缺点分析
  • (附源码)ssm教材管理系统 毕业设计 011229
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (经验分享)作为一名普通本科计算机专业学生,我大学四年到底走了多少弯路
  • (免费领源码)python#django#mysql公交线路查询系统85021- 计算机毕业设计项目选题推荐
  • (排序详解之 堆排序)
  • (三维重建学习)已有位姿放入colmap和3D Gaussian Splatting训练
  • (原創) 物件導向與老子思想 (OO)
  • (轉貼) 2008 Altera 亞洲創新大賽 台灣學生成果傲視全球 [照片花絮] (SOC) (News)
  • .NET Micro Framework 4.2 beta 源码探析
  • .NET 中选择合适的文件打开模式(CreateNew, Create, Open, OpenOrCreate, Truncate, Append)
  • .NET和.COM和.CN域名区别
  • .net利用SQLBulkCopy进行数据库之间的大批量数据传递
  • @JsonSerialize注解的使用