• NX二次开发-NXOPEN创建工程图表格Annotations::TableSectionBuilder *tableSectionBuilder1;


      1 NX9+VS2012
      2 
      3 
      4 #include <uf.h>
      5 #include <uf_tabnot.h>
      6 #include <NXOpen/Part.hxx>
      7 #include <NXOpen/PartCollection.hxx>
      8 #include <NXOpen/Session.hxx>
      9 #include <NXOpen/Annotations_TableSectionCollection.hxx>
     10 #include <NXOpen/Annotations_AnnotationManager.hxx>
     11 #include <NXOpen/FontCollection.hxx>
     12 
     13 
     14 UF_initialize();
     15 
     16 //创建表格注释
     17 Annotations::TableSection *nullAnnotations_TableSection(NULL);
     18 Annotations::TableSectionBuilder *tableSectionBuilder1;
     19 tableSectionBuilder1 = workPart->Annotations()->TableSections()->CreateTableSectionBuilder(nullAnnotations_TableSection);
     20 NXOpen::Point3d TablePoint(194.0, 17.0, 0.0);
     21 tableSectionBuilder1->Origin()->SetOriginPoint(TablePoint);
     22 tableSectionBuilder1->SetNumberOfColumns(2);
     23 tableSectionBuilder1->SetNumberOfRows(2);
     24 tableSectionBuilder1->SetRowHeight(20.0);
     25 tableSectionBuilder1->SetColumnWidth(50);    
     26 tableSectionBuilder1->Commit();         
     27 NXObject *nXObject1;
     28 nXObject1 = tableSectionBuilder1->Commit();
     29 tableSectionBuilder1->Destroy();
     30 
     31 //section转tag
     32 tag_t TabularNote = NULL_TAG;
     33 UF_TABNOT_ask_tabular_note_of_section(nXObject1->Tag(), &TabularNote);
     34 
     35 //获取第一行的Tag
     36 tag_t Row0Tag = NULL_TAG;
     37 UF_TABNOT_ask_nth_row(TabularNote, 0, &Row0Tag);
     38 
     39 //获取第二行的Tag
     40 tag_t Row1Tag = NULL_TAG;
     41 UF_TABNOT_ask_nth_row(TabularNote, 1, &Row1Tag);
     42 
     43 //获取第一列的Tag
     44 tag_t Column0Tag = NULL_TAG;
     45 UF_TABNOT_ask_nth_column(TabularNote, 0, &Column0Tag);
     46 
     47 //获取第二列的Tag
     48 tag_t Column1Tag = NULL_TAG;
     49 UF_TABNOT_ask_nth_column(TabularNote, 1, &Column1Tag);
     50 
     51 //得到第一行第一列单元格的Tag
     52 tag_t Cell0Tag = NULL_TAG;
     53 UF_TABNOT_ask_cell_at_row_col(Row0Tag, Column0Tag, &Cell0Tag);
     54 
     55 //得到第一行第二列单元格的Tag
     56 tag_t Cell1Tag = NULL_TAG;
     57 UF_TABNOT_ask_cell_at_row_col(Row0Tag, Column1Tag, &Cell1Tag);
     58 
     59 //得到第二行第一列单元格的Tag
     60 tag_t Cell2Tag = NULL_TAG;
     61 UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column0Tag, &Cell2Tag);
     62 
     63 //得到第二行第二列单元格的Tag
     64 tag_t Cell3Tag = NULL_TAG;
     65 UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column1Tag, &Cell3Tag);
     66 
     67 //写文本
     68 UF_TABNOT_set_cell_text(Cell0Tag, "设计者:");
     69 UF_TABNOT_set_cell_text(Cell1Tag, "卢尚宇");
     70 
     71 //合并最底下的单元格
     72 UF_TABNOT_merge_cells(Cell2Tag, Cell3Tag);
     73 
     74 //获取合并单元格的行Tag
     75 tag_t MergeRowTag = NULL_TAG;
     76 UF_TABNOT_ask_nth_row(TabularNote, 1, &MergeRowTag);
     77 
     78 //获取合并单元格的列Tag
     79 tag_t MergeColumnTag = NULL_TAG;
     80 UF_TABNOT_ask_nth_column(TabularNote, 0, &MergeColumnTag);
     81 
     82 tag_t MergeCellTag = NULL_TAG;
     83 UF_TABNOT_ask_cell_at_row_col(MergeRowTag, MergeColumnTag, &MergeCellTag);
     84 
     85 //写文本
     86 UF_TABNOT_set_cell_text(MergeCellTag, "版本号:xxxxxxxxxx");
     87 
     88 //检索默认单元格首选项
     89 UF_TABNOT_cell_prefs_t  cell_prefs;
     90 UF_TABNOT_ask_default_cell_prefs(&cell_prefs);
     91 
     92 //设置单元格首选项
     93 int fontIndex1 = workPart->Fonts()->AddFont("chinesef_fs", NXOpen::FontCollection::TypeNx);//更改字体
     94 cell_prefs.text_font = fontIndex1; //字体
     95 UF_TABNOT_set_cell_prefs(Cell0Tag, &cell_prefs);
     96 UF_TABNOT_set_cell_prefs(Cell1Tag, &cell_prefs);
     97 UF_TABNOT_set_cell_prefs(MergeCellTag, &cell_prefs);
     98 
     99 
    100 UF_terminate();

     1 void SetRange(tag_t TabularNote, int Row, int Column, char* Data)
     2 {
     3     NXOpen::Session *theSession = NXOpen::Session::GetSession();
     4     NXOpen::Part *workPart(theSession->Parts()->Work());
     5     NXOpen::Part *displayPart(theSession->Parts()->Display());
     6 
     7     //获取行的Tag
     8     tag_t RowTag = NULL_TAG;
     9     UF_TABNOT_ask_nth_row(TabularNote, Row, &RowTag);
    10 
    11     //获取列的Tag
    12     tag_t ColumnTag = NULL_TAG;
    13     UF_TABNOT_ask_nth_column(TabularNote, Column, &ColumnTag);
    14 
    15     //得到某一行和某一列单元格的Tag
    16     tag_t CellTag = NULL_TAG;
    17     UF_TABNOT_ask_cell_at_row_col(RowTag, ColumnTag, &CellTag);
    18 
    19     //写文本
    20     UF_TABNOT_set_cell_text(CellTag, Data);
    21 
    22     //检索默认单元格首选项
    23     UF_TABNOT_cell_prefs_t  cell_prefs;
    24     UF_TABNOT_ask_default_cell_prefs(&cell_prefs);
    25 
    26     //设置单元格首选项
    27     int fontIndex1;
    28     fontIndex1 = workPart->Fonts()->AddFont("FangSong", NXOpen::FontCollection::TypeStandard);//更改字体
    29     cell_prefs.text_font = fontIndex1; //字体
    30     UF_TABNOT_set_cell_prefs(CellTag, &cell_prefs);//设置字体
    31 }
  • 相关阅读:
    八皇后问题--------------------递归回溯
    排序算法06------------------------插入排序
    无重复字符最长子串----------------滑动窗口法
    排序算法05------------------------堆排序(图解)
    排序算法04------------------------归并排序
    图形学基础(一)光栅图形学_下:剪裁
    计网Top-Down 抄书笔记(二)——应用层
    图形学基础(二)图形变换_下:3D 平行投影
    图形学基础(二)图形变换_上:2D 基本变换/复合变换
    图形学基础(一)光栅图形学_上:画直线/圆、区域填充
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/10957485.html
Copyright © 2020-2023  润新知