NX二次开发-UFUN工程图表格注释写入文本内容UF_TABNOT_set_cell_text

  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();

NX二次开发-UFUN工程图表格注释写入文本内容UF_TABNOT_set_cell_text

上一篇:NX二次开发-设置对象名称函数UF_OBJ_set_name


下一篇:NX二次开发-UFUN适应窗口UF_VIEW_fit_view