1 Reply Latest reply on Nov 3, 2015 3:37 AM by Willie Roelofs

    Update Initial Animation State

    Willie Roelofs

      Hi all,


      I've currently written a macro that does an animation render for each and every configuration the assembly contains.

      - Before rendering the assebly gets a rebuild.

      - Created a separate sub to do the rendering work.

      - Created a function to wait untill the animation render is done.

      - Used the function SaveToAvi(filename,outputtype) as animation render.


      Each configuration has the exact same Animation (a simple rotate on the y-axis for 10 seconds), that was made by animation wizard.


      Currently I can't open the macro, Solidworks crashes instantly without warning. I guess I have to retype is...


      Anyway, I opened each an every image, and altough all images were rendered, all configuration except the first are off. Some parts are where they shouldn't be for instance. Also I created a floor plane driven by a design table. The assembly gets sometimes rendered with the wheels burried in the floor.


      Every time I open a configuration I get a notification by Solidworks called "Update Initial Animation State". Saying: "Due to model changes, the following components or features cannot be set to their previously-specified locations or values at the start of the animation".

      I always want to update the affected keys, but the checkbox [don't show again] isn't there.


      Is there another way to always "Update Initial Animation State"? Could anyone help me?



      Kind regards,

      Willie Roelofs

        • Re: Update Initial Animation State
          Willie Roelofs

          Quickly rewritten the macro.


          I've written a code to get past the initial update part. But that's only because the animation is really easy to make:

          - Create a new motion study.

          - Make a brand new animation

          - Render that animation

          - Delete the animation

          - Get a new configuration and repeat.


          If the animation is complex, like multiple moving parts, moving camera, etc. This could get ugly really quick.



          Dim swApp               As SldWorks.SldWorks
          Dim swModel             As SldWorks.ModelDoc2
          Dim swConfig            As SldWorks.Configuration
          Dim swModelDocExt       As SldWorks.ModelDocExtension
          Dim swMotionMgr         As SwMotionStudy.MotionStudyManager
          Dim swMotionStudy1      As SwMotionStudy.MotionStudy
          Dim swSaveBMPData       As SwMotionStudy.AVIParameter
          Dim vConfigName         As Variant


          Sub main()


          Set swApp = CreateObject("SldWorks.Application")
          Set swModel = swApp.ActiveDoc
          Set swConfig = swModel.GetActiveConfiguration


          'Get all configuration names.

          vConfigName = swModel.GetConfigurationNames


          'Create a loop based on the number of configuration names.

          For i = 0 To UBound(vConfigName)


          'During loop open configuration, rebuild and set view.

              sConfigName = vConfigName(i)
              Set swConfig = swModel.GetConfigurationByName(sConfigName)
              bRet = swModel.ShowConfiguration2(sConfigName)
              'bRet = swModel.ForceRebuild3(TopOnly)


          'During loop create a new motion manager create a animation rotating counterclockwise about the y-axis

          Next i


          End Sub


          Sub CreateAndRenderAnimation()


          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swModelDocExt = swModel.Extension
          Set swMotionMgr = swModelDocExt.GetMotionStudyManager()
          Set swMotionStudy1 = swMotionMgr.GetMotionStudy("Motion Study 1")


          If (swMotionStudy1 Is Nothing) Then
              Set swMotionStudy1 = swMotionMgr.CreateMotionStudy()
          End If


          bRet = swMotionStudy1.CreateByRotateModel(True, swAnimatorAxisOfRotation_e.swRotationAboutYAxis, 1, swAnimatorDirectionOfRotation_e.swRotationCounterClockwise, 10, 0)
          WaitFor (swMotionStudy1)


          For j = 0 To 5
              bRet = swMotionStudy1.SetTime(j * 2)
          Next j


          bRet = swMotionStudy1.Calculate
          WaitFor (swMotionStudy1)


          'During loop setup the "Save Animation" and Save the animation in bmp.


          'Delete the motion study.
          bRet = swMotionMgr.DeleteMotionStudy("Motion Study 1")


          'Return to model
          bRet = swMotionMgr.ActivateMotionStudy("Model")

          End Sub


          Sub SaveAsBMP()


          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swModelDocExt = swModel.Extension
          Set swMotionMgr = swModelDocExt.GetMotionStudyManager()
          Set swMotionStudy1 = swMotionMgr.GetMotionStudy("Motion Study 1")
              swSaveBMPData = swMotionMgr.CreateAVIParameter()
              swSaveBMPData.FramePerSecond = 6
              swSaveBMPData.SaveEntireAnimation = True
              swSaveBMPData.OutputType = swAnimationOutputType_e.swAnimationOutput_Series_of_BMP
              swSaveBMPData.RendererType = swRendererType_e.swRendererType_Photoworks_Buffer
              swSaveBMPData.MotionBlur = False
          bRet = swMotionStudy1.SaveToAVI("C:\test\Anim1.bmp", swSaveBMPData)


          'Do nothing while saving animations
          WaitFor (swMotionStudy1)


          End Sub


          Private Sub WaitFor(SwMotionStudy As MotionStudy)


          Do While SwMotionStudy.IsPlaying


          End Sub