6 Replies Latest reply on Aug 31, 2016 10:08 AM by Keith Rice

    Getting the updated center of mass in a macro

    Alexander Beebe

      Hi everyone!


      I have been developing a SolidWorks macro to record the center of mass of a part multiple times after suppressing and unsuppressing various features of the part. I have been using the CenterOfMass property of the IMassProperty interface. My code (VBA) looks something like this:



      Dim swMass As SldWorks.MassProperty


      Dim vCofM1  As Variant

      Dim vCofM2  As Variant


      vCofM1 = swMass.CenterOfMass


      'Find and suppress/unsuppress features here


      vCofM2 = swMass.CenterOfMass




      Unfortunately, no matter what I do, vCofM1 and vCofM2 end up having all of the same coordinates. I always check my model after running the code to confirm that the features were correctly suppressed and unsuppressed and have not found an issue here.


      Does anyone have any idea what the issue might be? Does the center of mass in the model not update until after the macro finishes running? Is swMass a sort of constant object field that does not reflect any changes to the actual model?