UG/NX二次开发Siemens官方NXOPEN实例解析—3.3 TitleBlock(添加图纸Title)

前言

        通过程序自动添加图纸的Title,在我以为图纸的title一般会直接做到模板里,然后通过调用模板输出,官方之所以专门出了这样一个实例,我想是为了给自动出图纸做铺垫吧。

一、知识点提取

本实例实现了自动添加图纸Title,主要包括一下内容:

1、获取图纸信息和系统信息

2、创建title的表格

3、填入title的文本内容

二、效果图

三、源码分析

 1、源码所在目录

UGOPEN\SampleNXOpenApplications\C++\TitleBlock

2、获取图纸信息和系统信息

Session *theSession = Session::GetSession();
Part *workPart(theSession->Parts()->Work());
Part *displayPart(theSession->Parts()->Display());

//Getting Part Name into String
NXOpen::BlockStyler::PropertyList *partNameProps = partName->GetProperties();
NXOpen::NXString partName1 = partNameProps->GetString("WideValue");
delete partNameProps;

//Getting Author Name into String
NXOpen::BlockStyler::PropertyList *authNameProps = authorName->GetProperties();
NXOpen::NXString authorName1 = authNameProps->GetString("WideValue");
delete authNameProps;

//Getting Current Date into String
UF_system_info_t info;
UF_ask_system_info(&info);
			
//Now the info.date_buf contains date and time seperated be space
//from which date will be extracted
NXOpen::NXString currDate = info.date_buf;		
string date = currDate.GetText();
size_t pos1 = date.find_first_of(" ");
date = date.substr(0,pos1);
currDate = date;	

3、创建title的表格

// ----------------------------------------------
//   Menu: Insert->Annotation...
// ----------------------------------------------
Session::UndoMarkId markId1;
markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible,  "Create Annotation");
Annotations::LetteringPreferences *letteringPreferences1;
letteringPreferences1 = workPart->Annotations()->Preferences()->GetLetteringPreferences();
// ----------------------------------------------------------------------
//   For this example, we need the set the lettering preferences so the
//   Text will align correctly in the title block
// ----------------------------------------------------------------------
Annotations::Lettering annotations_Lettering1;
annotations_Lettering1.Size = 0.125;
annotations_Lettering1.CharacterSpaceFactor = 1;
annotations_Lettering1.AspectRatio = 1.0;
annotations_Lettering1.LineSpaceFactor = 1.0;
annotations_Lettering1.Cfw.Color = 2;
annotations_Lettering1.Cfw.Font = 1;
annotations_Lettering1.Cfw.Width = Annotations::LineWidthThin;
letteringPreferences1->SetGeneralText(annotations_Lettering1);
workPart->Annotations()->Preferences()->SetLetteringPreferences(letteringPreferences1);
Annotations::UserSymbolPreferences *userSymbolPreferences1;
userSymbolPreferences1 = theSession->Parts()->Work()->Annotations()->NewUserSymbolPreferences(Annotations::UserSymbolPreferences::SizeTypeScaleAspectRatio,1,1);
// -------------------------------------------------------------------------------------
//   We need to load in the custom sybmol of the simple title block that has three lines
// -------------------------------------------------------------------------------------
NXString name = theSession->Parts()->Work()->FullPath();
string fullpath = name.GetText();
size_t pos = fullpath.find_last_of("\\"); ;
fullpath = fullpath.substr(0,(pos+1));
name = fullpath;
name = name +"special.sbf";
theSession->Parts()->W
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

MarcoPro

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值