• NX二次开发-UFUN创建工程图注释UF_DRF_create_note


     1     NX9+VS2012
     2     
     3     #include <uf.h>
     4     #include <uf_drf.h>
     5     #include <NXOpen/Annotations_Note.hxx>
     6     #include <NXOpen/NXObjectManager.hxx>
     7 
     8 
     9     UF_initialize();
    10 
    11     //创建注释
    12     char* TextString[] = {"Caesar卢尚宇"};
    13     double Origin3d[3] = {100,100,100};
    14     tag_t NoteTag = NULL_TAG;
    15     UF_DRF_create_note(1, TextString, Origin3d, 0, &NoteTag);
    16 
    17     //读取注释
    18     Annotations::Note *note1(dynamic_cast<Annotations::Note *>(NXObjectManager::Get(NoteTag)));
    19     std::vector<NXString> Notes = note1->GetText();
    20 
    21     //打印
    22     lw->Open();
    23     lw->WriteLine(Notes[0].GetLocaleText());
    24 
    25     UF_terminate();

    附加代码

    读取配置文件,格式xxx|xxx|xxx      |为换行分隔符

    生成三行注释

     1 //string替换所有指定字符串
     2 string&   replace_all(string&   str, const   string&   old_value, const   string&   new_value)
     3 {
     4     while (true)   {
     5         string::size_type   pos(0);
     6         if ((pos = str.find(old_value)) != string::npos)
     7             str.replace(pos, old_value.length(), new_value);
     8         else   break;
     9     }
    10     return   str;
    11 }
    12 
    13 
    14 
    15 void MyClass::CreateValueScopeNote(char* Data, Point3d Origin)
    16 {
    17     //转换
    18     string str = Data;
    19 
    20     //string替换所有指定字符串
    21     string AA = replace_all(str, "|", "
    ");
    22 
    23     //转换
    24     char msg[256];
    25     sprintf_s(msg, "%s", AA.c_str());
    26 
    27     //创建注释
    28     char* TextString[] = { msg };
    29     double Origin3d[3] = { Origin.X, Origin.Y, Origin.Z };
    30     tag_t NoteTag = NULL_TAG;
    31     UF_DRF_create_note(1, TextString, Origin3d, 0, &NoteTag);
    32   
    33     NXOpen::Annotations::Note *note1(dynamic_cast<NXOpen::Annotations::Note *>(NXOpen::NXObjectManager::Get(NoteTag)));
    34     NXOpen::Annotations::DraftingNoteBuilder *draftingNoteBuilder1;
    35     draftingNoteBuilder1 = workPart->Annotations()->CreateDraftingNoteBuilder(note1);
    36 
    37     //设置原点在右上角
    38     draftingNoteBuilder1->Origin()->SetAnchor(NXOpen::Annotations::OriginBuilder::AlignmentPositionBottomLeft);
    39 
    40     //字体
    41     int fontIndex2;
    42     fontIndex2 = workPart->Fonts()->AddFont("FangSong_GB2312", NXOpen::FontCollection::TypeStandard);
    43     draftingNoteBuilder1->Style()->LetteringStyle()->SetGeneralTextFont(fontIndex2);
    44 
    45     //字体大小
    46     draftingNoteBuilder1->Style()->LetteringStyle()->SetGeneralTextSize(20.0);
    47 
    48     //坐标点
    49     NXOpen::View *nullNXOpen_View(NULL);
    50     draftingNoteBuilder1->Origin()->Origin()->SetValue(NULL, nullNXOpen_View, Origin);
    51 
    52     //创建
    53     NXOpen::NXObject *nXObject1;
    54     nXObject1 = draftingNoteBuilder1->Commit();
    55 
    56     //销毁
    57     draftingNoteBuilder1->Destroy();
    58 
    59 }
    60 
    61 Caesar卢尚宇
    62 2019年10月18日
  • 相关阅读:
    [Err] 1055
    java -jar 时指定内存大小
    mysql判断是否存在数据库和表,进行删除和创建
    更新element-ui版本
    js 数组操作
    vue router 常用操作
    [algorithm] 汉诺塔问题
    【algorithm】 二分查找算法
    [algorithm] Dijkstra双栈算法表达式求值算法
    【hive】 hive 加载数据
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/10957200.html
Copyright © 2020-2023  润新知