2 Replies Latest reply on Jul 27, 2017 4:53 AM by Hans Björk

    How to get information from an Animation with MotionStudyResult  GetLinearVelocity

    Hans Björk

      I have a simple assy with an Animation that moves a few components.

       

      I try to get motion data from the animation with GetLinearVelocity, but I get only vectors of { 0.0, 0.0, 0.0 }.

      The code looks something like (c++):

      CComPtr<IMotionStudyResults> pResults = NULL;

      hRes = pMotionStudy->GetResults( lStudyType, & pResults );

       

      hRes = theRootComp->GetChildren( & vChildren );

       

      // Iterate over the children of the root component of the ModelDoc, and over the duration of the animation

      CComPtr<IComponent2> pComp;  // From theRootComp->GetChildren( & vChildren ); above

      double dRequestedTime; // Iterator, increase in small steps in the duration of the animation

      hRes = pResults->GetLinearVelocity( dRequestedTime, pComp, &pReturnVV );

       

      The returned MathVector in pReturnVV is always { 0.0, 0.0, 0.0 }. I get no error codes.

       

      Anyone has any idea what I'm doing wrong?

        • Re: How to get information from an Animation with MotionStudyResult  GetLinearVelocity
          Hans Björk

          I can add some neater psuedo-code if it help understand what I'm trying to do:

           

          hRes = pModExt->GetMotionStudyManager( & pReturnObj );

            CComPtr<IMotionStudyManager> pMotStuMgr;

            hRes = pReturnObj->QueryInterface( __uuidof(IMotionStudyManager), (void**) &pMotStuMgr );

           

            hRes = pMotStuMgr->GetMotionStudyNames( & vStudyNames );

           

            for( bsName in vStudyNames )

           

          CComPtr<IMotionStudy> pMotionStudy = NULL;
          hRes = pMotStuMgr->GetMotionStudy( bsName, & pMotionStudy );

           

          hRes = pMotionStudy->GetDuration( & dDuration );  // This is correct, accessing the animation works!

           

          hRes = pMotionStudy->Activate( & vbRet );
          hRes = pMotionStudy->Calculate( & vbRet );

           

          CComPtr<IMotionStudyResults> pResults = NULL;
          hRes = pMotionStudy->GetResults( swMotionStudyTypeAssembly, & pResults ); // Get the result for this Animation.
          hRes = pResults->IsOutOfDate( & vbIsOutOfDate );  // returns not out of date

           

          // Get components in the model...
          hRes = pRootComp->GetChildren( & vChildren );

           

          for( CComPtr<IComponent2> pComp  in  vChildren  )

              for(  double dIter=0.0;  dIter <= dDuration+0.001;  dIter += 0.1  )

           

              hRes = pResults->GetLinearVelocity( dIter, pComp, &pReturnVV ); // Is this the correct component?

           

              hRes = pVelocityV->get_IArrayData( & oaVelocity );

           

          Result: x == y == z == 0.0? Always, for all times and components, even out of bounds times
          The same for GetAngularVelocity() and GetCMPosition
            • Re: How to get information from an Animation with MotionStudyResult  GetLinearVelocity
              Hans Björk

              With a bit of experimenting I have found that only Motion Studies of type Motion Analysis return any values, but the same values for any value of time, regardless of how the components move. GetLinearVelocity, GetLinearAcceleration and GetCMPosition returns the same vector for all values of argument Time.

               

              And if I ask for a IMotionStudyResult of type swMotionStudyTypeCosmosMotion from an IMotionStudy of type swMotionStudyTypeAssembly and then call GetLinearVelocity, SolidWorks crashes on the GetLinearVelocity call.

               

              Obviously IMotionStudyResult does not even remotely work the way I had imagined after reading the documentation.