1 Reply Latest reply on Aug 8, 2017 8:08 PM by Jacob Corder

    SolidWorks crashes after DisplayDimension.GetDimension is called

    Igor Tsinman

      Based on SolidWorks SDK C# project template and this SolidWorks API Help 2015 SOLIDWORKS API Help - Macro Features and Dimensions

      I'm trying to create a macrofeature with some parameters available as display dimensions, so I inserted macro feature class into the project generated by wizard and substituted "Create Cube" command with my code creating an instance of my macrofeature.

      The problem is that I have crash after calling DisplayDimension.GetDimension function in Regenerate. The steps to reproduce: 1) start SolidWorks and load plug-in 2) Create new part 3) press "Create Cube" button and see the macrofeature is created with a cylinder body 4) close the document 5) SolidWorks crashes.

      The same code with commented DisplayDimension.GetDimension call works just fine.

       

      What can be the problem and how I can correct it?

        • Re: SolidWorks crashes after DisplayDimension.GetDimension is called
          Jacob Corder

          Hi I have had this problem in the past. The fix is before you the regenerate function is done, right at the end, add this

          Gc.collect

          Gc.waitforpendingfinalizers

          Gc.collect

          Gc.waitforpendingfinalizers

           

          And like magic, your problem is solved. I don't think many people are using dimensions in macrofeatures so this issue hasn't been resolved yet. I have had an open case for 4 years on this. Their fix is to add the note in the API guide to add this code at the end of the regenerate function.  This is really bad for performance especially when you have hundreds of macrofeatures in one model. Some of our models have more than 1000 macrofeatures.

           

          Also keep in mind that solidworks will instantiate a new instance of the class that implements ISwComFeature. So if this is in your main addin class, it will create a new one that is separate from your addin.