前言
通过程序自动添加图纸的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

最低0.47元/天 解锁文章
2383

被折叠的 条评论
为什么被折叠?



