• NX二次开发-NXOpen获取边的端点NXOpen::Edge::GetVertices


     1     NX9+VS2012
     2     
     3     #include <NXOpen/Features_BlockFeatureBuilder.hxx>
     4     #include <NXOpen/Features_FeatureCollection.hxx>
     5     #include <NXOpen/NXException.hxx>
     6     #include <NXOpen/Body.hxx>
     7     #include <NXOpen/BodyCollection.hxx>
     8     #include <NXOpen/PartCollection.hxx>
     9     #include <NXOpen/Edge.hxx>
    10     #include <NXOpen/ListingWindow.hxx>
    11     #include <NXOpen/NXObjectManager.hxx>
    12     #include <NXopen/UI.hxx>
    13     #include <NXOpen/DisplayManager.hxx>
    14     
    15     using namespace NXOpen;
    16 
    17     NXOpen::Session *theSession = NXOpen::Session::GetSession();
    18     NXOpen::Part *workPart(theSession->Parts()->Work());
    19     NXOpen::Part *displayPart(theSession->Parts()->Display());
    20 
    21     ListingWindow *lw;
    22     lw = theSession->ListingWindow();
    23 
    24 
    25     //NXOpen方式创建块
    26     NXOpen::Features::Feature *nullNXOpen_Features_Feature(NULL);
    27     NXOpen::Features::BlockFeatureBuilder *blockFeatureBuilder1;
    28     blockFeatureBuilder1 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
    29 
    30     std::vector<NXOpen::Body *> targetBodies1(1);
    31     NXOpen::Body *nullNXOpen_Body(NULL);
    32     targetBodies1[0] = nullNXOpen_Body;
    33     blockFeatureBuilder1->BooleanOption()->SetTargetBodies(targetBodies1);
    34 
    35     blockFeatureBuilder1->SetType(NXOpen::Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);//设置创建类型
    36 
    37     NXOpen::Point3d originPoint1(120.0, 103.0, 154.0);
    38     blockFeatureBuilder1->SetOriginAndLengths(originPoint1, "142", "132", "118");//设置原点
    39 
    40     blockFeatureBuilder1->SetBooleanOperationAndTarget(NXOpen::Features::Feature::BooleanTypeCreate, nullNXOpen_Body);//设置布尔
    41 
    42     NXOpen::Features::Feature *feature1;
    43     feature1 = blockFeatureBuilder1->CommitFeature();
    44 
    45     
    46 
    47     //NXOpen方式设置颜色
    48     NXOpen::DisplayModification *displayModification1;
    49     displayModification1 = theSession->DisplayManager()->NewDisplayModification();
    50 
    51     displayModification1->SetNewColor(108);//设置颜色
    52 
    53     std::vector<NXOpen::DisplayableObject *> objects1(1);
    54     NXOpen::Body *body1(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));
    55     objects1[0] = body1;
    56     displayModification1->Apply(objects1);
    57 
    58 
    59     //NXOpen特征获取体
    60     NXOpen::Body *MyBody(dynamic_cast<NXOpen::Body *>(workPart->Bodies()->FindObject(feature1->JournalIdentifier())));
    61 
    62 
    63     //NXOpen体获取边
    64     std::vector<NXOpen::Edge*> MyEdge = MyBody->GetEdges();
    65     
    66     char msg1[256];
    67     char msg2[256];
    68     sprintf_s(msg1, "当前体有%d条边
    每条边的两个端点如下:
    ", MyEdge.size());//转换
    69 
    70     //打印
    71     lw->Open();
    72     lw->WriteLine(msg1);
    73 
    74     for (int i = 0; i < MyEdge.size(); i++)
    75     {
    76         MyEdge[i]->Highlight();//高亮所有边
    77         NXOpen::Point3d Vertex1[3];//端点1
    78         NXOpen::Point3d Vertex2[3];//端点2
    79         MyEdge[i]->GetVertices(Vertex1, Vertex2);//由边获取端点
    80     
    81         sprintf_s(msg2, "X坐标:%.0f,  Y坐标:%.0f, Z坐标:%.0f
    X坐标:%.0f,  Y坐标:%.0f,  Z坐标:%.0f
    ", Vertex1->X, Vertex1->Y, Vertex1->Z, Vertex2->X, Vertex2->Y, Vertex2->Z);//转换
    82         lw->WriteLine(msg2);//打印
    83     }

  • 相关阅读:
    Kotlin扩展深入解析及注意事项和可见性
    Kotlin属性揭秘与延迟初始化特性
    Kotlin伴生对象及其字节码内幕详解
    Kotlin继承与重写重要特性剖析
    Kotlin构造方法详解与初始化过程分析
    Range与面向对象的Kotlin
    Kotlin编译器优化与when关键字详解
    Kotlin基础特性深入讲解
    java读取mysql表的注释及字段注释
    mysql导入导出sql文件
  • 原文地址:https://www.cnblogs.com/nxopen2018/p/10957467.html
Copyright © 2020-2023  润新知