eda 发表于 2014-6-25 14:31:47

关于NXOpen中的量测角度功能开发~~

利用JA录制的内容,    Session *theSession = Session::GetSession();
    Part *workPart(theSession->Parts()->Work());
    Part *displayPart(theSession->Parts()->Display());
    // ----------------------------------------------
    //   Menu: Analysis->Measure Angle...
    // ----------------------------------------------
    Session::UndoMarkId markId1;
    markId1 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");

    NXObject *nullNXObject(NULL);
    MeasureAngleBuilder *measureAngleBuilder1;
    measureAngleBuilder1 = workPart->MeasureManager()->CreateMeasureAngleBuilder(nullNXObject);

    theSession->SetUndoMarkName(markId1, NXString("Measure Angle \345\260\215\350\251\261\346\226\271\345\241\212", NXString::UTF8));

    measureAngleBuilder1->SetObjtype1(MeasureAngleBuilder::ObjectTypeVector);

    Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));
    Expression *expression1;
    expression1 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);

    Line *line1(dynamic_cast<Line *>(workPart->Lines()->FindObject("HANDLE R-12231")));
    Direction *direction1;
    direction1 = workPart->Directions()->CreateDirection(line1, SenseReverse, SmartObject::UpdateOptionAfterModeling);

    measureAngleBuilder1->SetVector1(direction1);

    measureAngleBuilder1->SetObjtype2(MeasureAngleBuilder::ObjectTypeVector);

    Expression *expression2;
    expression2 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);

    Point3d origin1(0.0, 0.0, 0.0);
    Vector3d vector1(1.0, 0.0, 0.0);
    Direction *direction2;
    direction2 = workPart->Directions()->CreateDirection(origin1, vector1, SmartObject::UpdateOptionAfterModeling);

    measureAngleBuilder1->SetVector2(direction2);

    measureAngleBuilder1->SetAnnotationMode(MeasureBuilder::AnnotationTypeShowDimension);

    Session::UndoMarkId markId2;
    markId2 = theSession->SetUndoMark(Session::MarkVisibilityInvisible, "Measure Angle");

    theSession->DeleteUndoMark(markId2, NULL);

    theSession->SetUndoMarkName(markId1, "Measure Angle");

    measureAngleBuilder1->Destroy();

    workPart->Expressions()->Delete(expression1);

    workPart->Expressions()->Delete(expression2);

    Session::UndoMarkId markId3;
    markId3 = theSession->SetUndoMark(Session::MarkVisibilityVisible, "Start");

    MeasureAngleBuilder *measureAngleBuilder2;
    measureAngleBuilder2 = workPart->MeasureManager()->CreateMeasureAngleBuilder(nullNXObject);

    measureAngleBuilder2->SetAnnotationMode(MeasureBuilder::AnnotationTypeShowDimension);

    measureAngleBuilder2->SetObjtype1(MeasureAngleBuilder::ObjectTypeVector);

    measureAngleBuilder2->SetObjtype2(MeasureAngleBuilder::ObjectTypeVector);

    theSession->SetUndoMarkName(markId3, NXString("Measure Angle \345\260\215\350\251\261\346\226\271\345\241\212", NXString::UTF8));

    Point3d origin2(0.0, 0.0, 0.0);
    Vector3d vector2(1.0, 0.0, 0.0);
    Direction *direction3;
    direction3 = workPart->Directions()->CreateDirection(origin2, vector2, SmartObject::UpdateOptionAfterModeling);

    measureAngleBuilder2->SetVector2(direction3);

    // ----------------------------------------------
    //   Dialog Begin Measure Angle
    // ----------------------------------------------
    Expression *expression3;
    expression3 = workPart->Expressions()->CreateSystemExpressionWithUnits("0", unit1);

    measureAngleBuilder2->Destroy();

    workPart->Expressions()->Delete(expression3);

    theSession->UndoToMark(markId3, NULL);

    theSession->DeleteUndoMark(markId3, NULL);

    // ----------------------------------------------
    //   Menu: Tools->Journal->Stop Recording
    // ----------------------------------------------




于VS中写入了以下内容

Session *theSession = Session::GetSession();
                Part *workPart(theSession->Parts()->Work());
                Part *displayPart(theSession->Parts()->Display());
                ListingWindow *lw = theSession->ListingWindow();

                NXObject *nullNXObject(NULL);
                MeasureAngleBuilder *measureAngleBuilder1;
                measureAngleBuilder1 = workPart->MeasureManager()->CreateMeasureAngleBuilder(nullNXObject);

                measureAngleBuilder1->SetAnnotationMode(MeasureBuilder::AnnotationTypeShowDimension);

                measureAngleBuilder1->SetObjtype2(MeasureAngleBuilder::ObjectTypeVector);

                Point3d origin1(0.0, 0.0, 0.0);
                Vector3d vector1(1.0, 0.0, 0.0);
                Direction *direction1;
                direction1 = workPart->Directions()->CreateDirection(origin1, vector1, SmartObject::UpdateOptionAfterModeling);

                measureAngleBuilder1->SetVector2(direction1);

                measureAngleBuilder1->SetObjtype1(MeasureAngleBuilder::ObjectTypeVector);

                BlockStyler::PropertyList *vectorProperty = vector0->GetProperties();
                Vector3d vec = vectorProperty->GetVector("Vector");
                delete vectorProperty;
                vectorProperty = NULL;

                Direction *direction2 = dynamic_cast< Direction*>(vectorProperty);

                measureAngleBuilder1->SetVector1(direction2);

运行后无报错,但却无法得知正确量测出来的角度数值,以上内容不知那里有误,请大侠们指点



花在人间 发表于 2014-6-25 22:28:12

获取属性用"SelectedObjects",教学视频里有类似的

admin 发表于 2014-6-26 09:13:09

这明显是错的
Direction *direction2 = dynamic_cast< Direction*>(vectorProperty);

看论坛视频吧

eda 发表于 2014-6-27 12:40:38

感谢,测试中~~~
页: [1]
查看完整版本: 关于NXOpen中的量测角度功能开发~~