liuyang77177 发表于 2015-5-21 18:40:22

运动仿真动画播放

大神们好 - - 我又来问问题了

我已经把程序的基本架构代码弄好了,扫掠问题已经解决了,现在我们这项目走到了最后一步,不过似乎做不下去了。

我要做一个运动仿真带干涉分析,但是nxopen++不给提供运动按钮的ja录制,我似乎也找不到如何可以通过语句使得运动自动进行,求助各位大神了,是否可以通过某语句使得动画开始或者做一个步进动画,还是我应当如何把我的open++里面的语句转到ufun语句的架构下来做动画,谢谢老师们的解答。

一段ja录制代码:

        Motion::MotionSolution *nullMotion_MotionSolution(NULL);
        Motion::MotionSolutionBuilder *motionSolutionBuilder1;
        motionSolutionBuilder1 = workPart->MotionManager()->MotionSolutions()->CreateSolutionBuilder(nullMotion_MotionSolution);


        motionSolutionBuilder1->SetTime(10.0);
        motionSolutionBuilder1->SetStep(500);
        motionSolutionBuilder1->SetName("Solution_1");
        motionSolutionBuilder1->RecurdynSolverProperty()->SetStaticIntegratorType(Motion::RecurdynSolverProperty::StaticIntegratorTypesRobustNewtonRapson);



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

        NXObject *nXObject1;
        nXObject1 = motionSolutionBuilder1->Commit();
        motionSolutionBuilder1->Destroy();
       
        Motion::MotionSolution *motionSolution1(dynamic_cast<Motion::MotionSolution *>(nXObject1));
        motionSolution1->SolveNormalRunSolution();



就是我想通过我建立的这个motionsolution (在nx程序里是result) 通过语句命令开始动,然后动画结束之后删掉部件云云...

liuyang77177 发表于 2015-5-21 22:27:05

再补一段前面建立连杆和运动副的代码....再前面还有建立实体的代码就不贴了....就是还想问一下...我的nxopen++里面的实体nxobject和featrue::feature以及body如何兼容ufun函数编程啊,可能ufun函数有一些可以用的代码但我接不上这样子

PartSaveStatus *partSaveStatus1;
        partSaveStatus1 = workPart->Save(BasePart::SaveComponentsTrue, BasePart::CloseAfterSaveFalse);

        delete partSaveStatus1;


        theSession->DataManager()->LoadFile("G:\\UG\\UGII\\motion_try\\motion_try.afu");



        theSession->MotionSession()->Environments()->SetAnalysisType(Motion::MotionEnvironment::AnalysisDynamics);

        theSession->MotionSession()->Environments()->CheckMotorLicense(false);

        theSession->MotionSession()->Environments()->CheckCosimLicense(false);

        theSession->MotionSession()->Environments()->CheckFlexbodyLicense(false);

        theSession->MotionSession()->Environments()->SetComponentBasedMechanism(false);


        NXString motionSimName1;
        motionSimName1 = theSession->MotionSession()->CreateNamingSimulation(workPart, "motion_1");

        workPart = theSession->Parts()->Work();
        displayPart = theSession->Parts()->Display();
        Motion::PhysicsConversionBuilder *physicsConversionBuilder1;
        physicsConversionBuilder1 = theSession->MotionSession()->CreatePhysicsConversionBuilder(workPart);

        physicsConversionBuilder1->Destroy();

        theSession->MotionSession()->InitializeMechanisms();

        Motion::Link *nullMotion_Link(NULL);
        Motion::LinkBuilder *linkBuilder1;
        linkBuilder1 = workPart->MotionManager()->Links()->CreateLinkBuilder(nullMotion_Link);

        Unit *unit1(dynamic_cast<Unit *>(workPart->UnitCollection()->FindObject("MilliMeter")));

        linkBuilder1->MassProperty()->MassExpression()->SetRightHandSide("0");

        linkBuilder1->MassProperty()->IxxExpression()->SetRightHandSide("0");

        linkBuilder1->MassProperty()->IyyExpression()->SetRightHandSide("0");

        linkBuilder1->MassProperty()->IzzExpression()->SetRightHandSide("0");

        linkBuilder1->MassProperty()->IxyExpression()->SetRightHandSide("0");

        linkBuilder1->MassProperty()->IxzExpression()->SetRightHandSide("0");

        linkBuilder1->MassProperty()->IyzExpression()->SetRightHandSide("0");

       

        linkBuilder1->SetName("L001");


        Assemblies::Component *component1(dynamic_cast<Assemblies::Component *>(workPart->ComponentAssembly()->RootComponent()->FindObject("COMPONENT motion_try 1")));
        Body *body1(dynamic_cast<Body *>(component1->FindObject("PROTO#.Bodies|"+obname)));
        bool added1;
        added1 = linkBuilder1->Geometries()->Add(body1);

        Direction *nullDirection(NULL);
        linkBuilder1->InitialVelocity()->SetTranslateVector(nullDirection);

        linkBuilder1->InitialVelocity()->SetRotateVector(nullDirection);

        NXObject *linkObject;
        linkObject = linkBuilder1->Commit();


        linkBuilder1->Destroy();




       

        Motion::Joint *nullMotion_Joint(NULL);
        Motion::JointBuilder *jointBuilder1;
        jointBuilder1 = workPart->MotionManager()->Joints()->CreateJointBuilder(nullMotion_Joint);



        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->DisplacementExpression()->SetRightHandSide("0");
        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->VelocityExpression()->SetRightHandSide("20");
        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->AccelerationExpression()->SetRightHandSide("0");
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->DisplacementExpression()->SetRightHandSide("0");
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->VelocityExpression()->SetRightHandSide("20");
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->AccelerationExpression()->SetRightHandSide("0");

        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionPointOnCurve()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionPointOnCurve()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->VelocityExpression()->SetRightHandSide("0");
        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->VelocityExpression()->SetRightHandSide("0");
        jointBuilder1->JointMultiDrivers()->MotionTranslationZ()->SetFunction(nullNXObject);
        jointBuilder1->JointMultiDrivers()->MotionPointOnCurve()->SetFunction(nullNXObject);

        Motion::Link *link1(dynamic_cast<Motion::Link *>(workPart->MotionManager()->Links()->FindObject("L001")));
        jointBuilder1->JointDefine()->SetFirstLink(link1);


        NXMatrix *nullNXMatrix(NULL);
        jointBuilder1->JointDefine()->SetSecondMatrix(nullNXMatrix);

        Part *part1(dynamic_cast<Part *>(theSession->Parts()->FindObject("motion_try")));
        PartLoadStatus *partLoadStatus1;
        partLoadStatus1 = part1->LoadFeatureDataForSelection();

        delete partLoadStatus1;
        Scalar *scalar3;
        scalar3 = workPart->Scalars()->CreateScalar(0.46951534452273, Scalar::DimensionalityTypeNone, SmartObject::UpdateOptionAfterModeling);

        Scalar *scalar4;
        scalar4 = workPart->Scalars()->CreateScalar(0.440129914258558, Scalar::DimensionalityTypeNone, SmartObject::UpdateOptionAfterModeling);

        Features::SweepAlongGuide *sweepAlongGuide1(dynamic_cast<Features::SweepAlongGuide *>(part1->Features()->FindObject("SWEEP(7)")));
        Face *face3(dynamic_cast<Face *>(sweepAlongGuide1->FindObject("FACE 10000000 {(-0,0,0) SWEEP(7)}")));
        Point *point3;
        point3 = workPart->Points()->CreatePoint(face3, scalar3, scalar4, SmartObject::UpdateOptionAfterModeling);


        NXObject *nXObject12;
        Xform *xform1;
        xform1 = workPart->Xforms()->CreateExtractXform(face3, SmartObject::UpdateOptionAfterModeling, false, &nXObject12);

        Point *point4;
        point4 = workPart->Points()->CreatePoint(point3, xform1, SmartObject::UpdateOptionAfterModeling);

        jointBuilder1->JointDefine()->SetFirstOrigin(point4);


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

        jointBuilder1->JointDefine()->SetFirstVector(direction1);

        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->SetTypeOption(Motion::DriverOperation::TypeConstant);

        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->SetFunction(nullNXObject);

        jointBuilder1->JointMultiDrivers()->MotionEulerAngle1()->VelocityExpression()->SetRightHandSide("20");


        NXObject *nXObject3;
        nXObject3 = jointBuilder1->Commit();

        jointBuilder1->Destroy();

liuyang77177 发表于 2015-5-21 22:30:13

为什么会有表情 - -!

有一段ufun实现步进运动的代码请老师们指点,如何兼容已有的nxopen++代码

.....

UF_MOTION_init_articulation();
for(int i=0;i<360;i++){
UF_MOTION_step_articulation(1,&i_ret);
}
UF_MOTION_terminate_articulation();
UF_MOTION_terminate();
页: [1]
查看完整版本: 运动仿真动画播放