zoukankan      html  css  js  c++  java
  • NX二次开发 工程图创建孔表功能

    VS2010 NX8.5

    void HoleTable::CheckApplicationModule() //检查所在模块
    {
    try
    {
    UF_initialize();

    //int ModuleId ; //定义模块值
    UF_ask_application_module(&ModuleId);//获取当前所在的模块
    //sprintf(msg,"%d",ModuleId);
    //theSession->ListingWindow()->WriteLine(msg);
    if (ModuleId !=1)
    {
    theUI->NXMessageBox()->Show("提示", NXOpen::NXMessageBox::DialogTypeInformation, "当前不在制图环境,请切换到制图环境再使用本工具");
    }

    UF_terminate();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    HoleTable::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    void HoleTable::displayModule() //显示模型
    {
    try
    {
    UF_initialize();
    UF_DRAW_set_display_state(1);//1=显示模型,2=显示图纸
    UF_terminate();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    HoleTable::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    void HoleTable::displayDrawing() //显示图纸
    {
    try
    {
    UF_initialize();
    UF_DRAW_set_display_state(2);//1=显示模型,2=显示图纸
    UF_terminate();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    HoleTable::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    void HoleTable::createTable()//工程图创建表格
    {
    try
    {
    getnodes();//获取节点内容
    GetUI(); //获取UI

    //创建表格

    Annotations::TableSection *nullAnnotations_TableSection(NULL);
    Annotations::TableSectionBuilder *tableSectionBuilder1;
    tableSectionBuilder1 = workPart->Annotations()->TableSections()->CreateTableSectionBuilder(nullAnnotations_TableSection);
    tableSectionBuilder1->Origin()->Plane()->SetPlaneMethod(Annotations::PlaneBuilder::PlaneMethodTypeXyPlane);

    tableSectionBuilder1->Origin()->SetInferRelativeToGeometry(true);
    tableSectionBuilder1->SetNumberOfColumns(8);//设置列数
    tableSectionBuilder1->SetNumberOfRows((int)allnodes.size()+3);//设置行数
    tableSectionBuilder1->SetColumnWidth(12.0);//设置列宽
    tableSectionBuilder1->SetRowHeight(7.0);//设置行高
    tableSectionBuilder1->Style()->TableSectionStyle()->SetAlignmentPosition(Annotations::TableSectionStyleBuilder::AlignmentPositionTypeTopLeft);
    tableSectionBuilder1->Origin()->Plane()->SetPlaneMethod(Annotations::PlaneBuilder::PlaneMethodTypeXyPlane);
    tableSectionBuilder1->Origin()->SetInferRelativeToGeometry(true);
    Annotations::LeaderData *leaderData1;
    leaderData1 = workPart->Annotations()->CreateLeaderData();
    leaderData1->SetStubSize(2.0);
    tableSectionBuilder1->Leader()->Leaders()->Append(leaderData1);
    leaderData1->SetStubSide(Annotations::LeaderSideInferred);
    tableSectionBuilder1->Origin()->SetInferRelativeToGeometry(true);
    tableSectionBuilder1->Origin()->SetInferRelativeToGeometry(true);

    Annotations::Annotation::AssociativeOriginData assocOrigin1;
    assocOrigin1.OriginType = Annotations::AssociativeOriginTypeDrag;
    View *nullView(NULL);
    assocOrigin1.View = nullView;
    assocOrigin1.ViewOfGeometry = nullView;
    Point *nullPoint(NULL);
    assocOrigin1.PointOnGeometry = nullPoint;
    assocOrigin1.VertAnnotation = NULL;
    assocOrigin1.VertAlignmentPosition = Annotations::AlignmentPositionTopLeft;
    assocOrigin1.HorizAnnotation = NULL;
    assocOrigin1.HorizAlignmentPosition = Annotations::AlignmentPositionTopLeft;
    assocOrigin1.AlignedAnnotation = NULL;
    assocOrigin1.DimensionLine = 0;
    assocOrigin1.AssociatedView = nullView;
    assocOrigin1.AssociatedPoint = nullPoint;
    assocOrigin1.OffsetAnnotation = NULL;
    assocOrigin1.OffsetAlignmentPosition = Annotations::AlignmentPositionTopLeft;
    assocOrigin1.XOffsetFactor = 0.0;
    assocOrigin1.YOffsetFactor = 0.0;
    assocOrigin1.StackAlignmentPosition = Annotations::StackAlignmentPositionAbove;
    tableSectionBuilder1->Origin()->SetAssociativeOrigin(assocOrigin1);

    Point3d point1(tablePoint1);//定义点
    tableSectionBuilder1->Origin()->Origin()->SetValue(NULL, nullView, point1);//设置表放置位置
    tableSectionBuilder1->Origin()->SetInferRelativeToGeometry(true);

    NXObject *nXObject1;
    nXObject1 = tableSectionBuilder1->Commit();

    std::vector<NXObject *> objects1;
    objects1 = tableSectionBuilder1->GetCommittedObjects();

    tableSectionBuilder1->Destroy();

    UF_initialize();

    tag_t TabularNote1 = NULL_TAG;
    UF_TABNOT_ask_tabular_note_of_section(nXObject1->Tag(), &TabularNote1);//获取表格TAG

    tag_t Row0Tag = NULL_TAG;
    UF_TABNOT_ask_nth_row(TabularNote1, 0, &Row0Tag);//获取第一行的Tag
    tag_t Row1Tag = NULL_TAG;
    UF_TABNOT_ask_nth_row(TabularNote1, 1, &Row1Tag);//获取第二行的Tag

    tag_t Column0Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 0, &Column0Tag);//获取第一列的Tag
    tag_t Column1Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 1, &Column1Tag);//获取第二列的Tag
    tag_t Column2Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 2, &Column2Tag);//获取第三列的Tag
    tag_t Column3Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 3, &Column3Tag);//获取第四列的Tag
    tag_t Column4Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 4, &Column4Tag);//获取第五列的Tag
    tag_t Column5Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 5, &Column5Tag);//获取第六列的Tag
    tag_t Column6Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 6, &Column6Tag);//获取第七列的Tag
    tag_t Column7Tag = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 7, &Column7Tag);//获取第八列的Tag

    tag_t CellRow0Column0Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row0Tag, Column0Tag, &CellRow0Column0Tag);//得到第一行第一列单元格的Tag
    tag_t CellRow0Column7Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row0Tag, Column7Tag, &CellRow0Column7Tag);//得到第一行第六列单元格的Tag

    tag_t CellRow1Column0Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column0Tag, &CellRow1Column0Tag);//得到第二行第一列单元格的Tag
    tag_t CellRow1Column1Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column1Tag, &CellRow1Column1Tag);//得到第二行第二列单元格的Tag
    tag_t CellRow1Column2Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column2Tag, &CellRow1Column2Tag);//得到第二行第三列单元格的Tag
    tag_t CellRow1Column3Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column3Tag, &CellRow1Column3Tag);//得到第二行第四列单元格的Tag
    tag_t CellRow1Column4Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column4Tag, &CellRow1Column4Tag);//得到第二行第五列单元格的Tag
    tag_t CellRow1Column5Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column5Tag, &CellRow1Column5Tag);//得到第二行第六列单元格的Tag
    tag_t CellRow1Column6Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column6Tag, &CellRow1Column6Tag);//得到第二行第七列单元格的Tag
    tag_t CellRow1Column7Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column7Tag, &CellRow1Column7Tag);//得到第二行第八列单元格的Tag

    UF_TABNOT_merge_cells(CellRow0Column0Tag, CellRow0Column7Tag);//合并单元格(第一列到第六列)
    tag_t MergeRowTag1 = NULL_TAG;
    UF_TABNOT_ask_nth_row(TabularNote1, 0, &MergeRowTag1);//获取合并单元格的行Tag
    tag_t MergeColumnTag1 = NULL_TAG;
    UF_TABNOT_ask_nth_column(TabularNote1, 0, &MergeColumnTag1);//获取合并单元格的列Tag
    tag_t MergeCellTag1 = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(MergeRowTag1, MergeColumnTag1, &MergeCellTag1);//获取合并单元格的Tag

    tag_t Cell2Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column0Tag, &Cell2Tag);//得到第二行第一列单元格的Tag

    tag_t Cell3Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(Row1Tag, Column1Tag, &Cell3Tag);//得到第二行第二列单元格的Tag

    //检索默认单元格首选项
    UF_TABNOT_cell_prefs_t cell_prefs;//结构体(单元格的格式)
    UF_TABNOT_ask_default_cell_prefs(&cell_prefs);

    //设置单元格首选项(单元格的格式)
    cell_prefs.text_color = 186; //字的颜色
    cell_prefs.horiz_just=UF_TABNOT_just_center;//水平居中
    cell_prefs.text_density = 1;//字的线条粗细(1标准,2粗体,3细)
    cell_prefs.text_height = 4.0;//设置字的高度
    UF_TABNOT_set_cell_prefs(MergeCellTag1, &cell_prefs);

    //标头设置
    string TabTitle1=thestringTitle1.GetLocaleText();
    string TabTitle2=thestringTitle2.GetLocaleText();
    string TabTitle=TabTitle1+"("+TabTitle2+")";

    UF_TABNOT_set_cell_text(MergeCellTag1, TabTitle.c_str());//写文本
    UF_TABNOT_set_cell_text(CellRow1Column0Tag, "序号");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column1Tag, "规格");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column2Tag, "座标 X");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column3Tag, "座标 Y");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column4Tag, "深度");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column5Tag, "杯头直径");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column6Tag, "杯头深度");//写文本
    UF_TABNOT_set_cell_text(CellRow1Column7Tag, "备注");//写文本

    //写入加工对象内容
    if((int)allnodes.size()>0)
    {
    for (int i = 0; i < (int)allnodes.size(); i++ )
    {
    tag_t RowTag = NULL_TAG;
    UF_TABNOT_ask_nth_row(TabularNote1, i+2, &RowTag);//获取第i+3行的Tag

    nodetxt= allnodes[i]->GetColumnDisplayText(0);//获取例的内容
    tag_t CellRow1Columni0Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column0Tag, &CellRow1Columni0Tag);//得到第i+2行第一列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni0Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(1);//获取例的内容
    tag_t CellRow1Columni1Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column1Tag, &CellRow1Columni1Tag);//得到第i+2行第二列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni1Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(2);//获取例的内容
    tag_t CellRow1Columni2Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column2Tag, &CellRow1Columni2Tag);//得到第i+2行第三列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni2Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(3);//获取例的内容
    tag_t CellRow1Columni3Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column3Tag, &CellRow1Columni3Tag);//得到第i+2行第四列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni3Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(4);//获取例的内容
    tag_t CellRow1Columni4Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column4Tag, &CellRow1Columni4Tag);//得到第i+2行第五列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni4Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(5);//获取例的内容
    tag_t CellRow1Columni5Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column5Tag, &CellRow1Columni5Tag);//得到第i+2行第六列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni5Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(6);//获取例的内容
    tag_t CellRow1Columni6Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column6Tag, &CellRow1Columni6Tag);//得到第i+2行第七列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni6Tag, nodetxt.GetLocaleText());//写文本

    nodetxt= allnodes[i]->GetColumnDisplayText(7);//获取例的内容
    tag_t CellRow1Columni7Tag = NULL_TAG;
    UF_TABNOT_ask_cell_at_row_col(RowTag, Column7Tag, &CellRow1Columni7Tag);//得到第i+2行第八列单元格的Tag
    UF_TABNOT_set_cell_text(CellRow1Columni7Tag, nodetxt.GetLocaleText());//写文本

    }
    }


    UF_terminate();
    }
    catch(exception& ex)
    {
    //---- Enter your exception handling code here -----
    HoleTable::theUI->NXMessageBox()->Show("Block Styler", NXOpen::NXMessageBox::DialogTypeError, ex.what());
    }
    }

    怡宁塑胶模具设计
  • 相关阅读:
    2.1 JavaScript应用开发实践指南
    2 JavaScript应用开发实践指南
    一 JavaScript应用开发实践指南
    工作“触雷”经历与总结--记博弈论的应用
    设计模式之 简单工厂,工厂方法,抽象工厂
    C#5.0之后推荐使用TPL(Task Parallel Libray 任务并行库) 和PLINQ(Parallel LINQ, 并行Linq). 其次是TAP(Task-based Asynchronous Pattern, 基于任务的异步模式)
    C语言知识结构
    Visual Studio 项目和解决方案 路径修改(解决部分模板丢失的问题)
    C#静态方法和实例方法的内存分配测试
    Java字符串String
  • 原文地址:https://www.cnblogs.com/hqsalanhuang/p/14677872.html
Copyright © 2011-2022 走看看