NXOpen创建block,设置颜色,遍历边,倒角

采用 openc++编程,首先使用代码录制的方法得到相应代码,通过对代码的分析,然后修改。可以大大减轻开发的难度。

UF_initialize();
    //环境
    Session *theSession = Session::GetSession();
    //创建空特征
    Features::Feature *nullNXOpen_Features_Feature(NULL);       
    //创建块,获取工作部件
    Features::BlockFeatureBuilder *blockFeatureBuilder1;
    blockFeatureBuilder1 = workPart->Features()->CreateBlockFeatureBuilder(nullNXOpen_Features_Feature);
    //设置block参数
    blockFeatureBuilder1->SetType(Features::BlockFeatureBuilder::TypesOriginAndEdgeLengths);
    Point3d originPoint1(0.0, 0.0, 0.0);
    blockFeatureBuilder1->SetOriginAndLengths(originPoint1, "30", "50", "70");
    //创建
    Features::Feature *feature1;
    feature1 = blockFeatureBuilder1->CommitFeature();

//染颜色
    //转换
    Features::BodyFeature *bodyFeatObject(dynamic_cast (feature1));       //特征转换body
    //显示特征更改
    DisplayModification *displayModification1;
    displayModification1 = theSession->DisplayManager()->NewDisplayModification();
    displayModification1->SetNewColor(31);          //设置rgb值
    vector objects1(1);        //存放body
    vector BodyArray(1);
    vector EdgeArray ;
    vector FaceArray;

    if(bodyFeatObject != NULL)
    {
        BodyArray = bodyFeatObject->GetBodies();
        EdgeArray = bodyFeatObject->GetEdges();     
        FaceArray = bodyFeatObject->GetFaces();     
    }
    objects1[0] = BodyArray[0];
    displayModification1->Apply(objects1);      //应用



//输出所有线的信息
    theSession->ListingWindow()->Open();  //打开信息窗口
    Edge *edge1;
    NXOpen::Edge::EdgeType type;
    double len;
    char msg[60];
    Point3d p1,p2;
    for(int i=0;i < EdgeArray.size();i++ )
    {
        edge1 = EdgeArray[i];
        type = edge1->SolidEdgeType();      //获取类型
        len = edge1->GetLength();           //获取长度
        edge1->GetVertices(&p1,&p2);        //获取断点
        sprintf(msg,"长:%.3f.\n",len);
        theSession->ListingWindow()->WriteLine(msg);
        sprintf(msg,"x:%.3f.y:%.3f.z:%.3f.\n",p1.X,p1.Y,p1.Z);
        theSession->ListingWindow()->WriteLine(msg);
        sprintf(msg,"x:%.3f.y:%.3f.z:%.3f.\n\n",p2.X,p2.Y,p2.Z);
        theSession->ListingWindow()->WriteLine(msg);
    }





//创建倒圆
    Feature *nullNXOpen_Features_Feature5(NULL);        //创建空特征
   //创建倒圆特征,设置工作部件
    EdgeBlendBuilder *edgeBlendBuilder1;    
    edgeBlendBuilder1 = workPart->Features()->CreateEdgeBlendBuilder(nullNXOpen_Features_Feature5);

    //创建集合
    NXOpen::ScCollector *scCollector1;
    scCollector1 = workPart->ScCollectors()->CreateCollector();

    //线数组加到
    EdgeMultipleSeedTangentRule *edgeMultipleSeedTangentRule1;
    edgeMultipleSeedTangentRule1 = workPart->ScRuleFactory()->CreateRuleEdgeMultipleSeedTangent(EdgeArray, 0.05, true);

        vector rules1(1);
        rules1[0] = edgeMultipleSeedTangentRule1;
        scCollector1->ReplaceRules(rules1, false);

    edgeBlendBuilder1->AddChainset(scCollector1, "5");      //设置半径
    Features::Feature *feature5 = edgeBlendBuilder1->CommitFeature();       //创建


    edgeBlendBuilder1->Destroy();       //释放倒圆
    blockFeatureBuilder1->Destroy();    //释放block
    delete displayModification1;        //删除特征

UF_terminate();

你可能感兴趣的:(ug开发)