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/NX二次开发Siemens官方NXOPEN实例解析—2.7 DiameterSymbol(标注符号) 
UG/NX二次开发Siemens官方NXOPEN实例解析—2.8 DrawingCycle(图纸打印)
UG/NX二次开发Siemens官方NXOPEN实例解析—2.9 InteropCallCFromDotNet(VB调用VC++ DLL实践)
UG/NX二次开发Siemens官方NXOPEN实例解析—2.10 InteropNXOpenWithUFWrap(NXOPEN与Ufun混合使用)

前言

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

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


一、知识点提取

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

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

2、创建新的注释

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

二、案例需求分析

1、效果图

UG/NX二次开发Siemens官方NXOPEN实例解析—2.6 CreateNote(注释)_第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 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::vectorselectedObject;

	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(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(theDialog->TopBlock()->FindBlock("selectNote"));
//Setting selection mask to select only drafting notes or symbols
NXOpen::Selection::SelectionAction action = Selection::SelectionActionClearAndEnableSpecific;
std::vectorselectionMask_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);

你可能感兴趣的:(UG二开自学,开发语言,c++,学习)