10 Replies Latest reply on Feb 17, 2015 11:43 AM by Uriel Avron

    SaveAs3 crashes Solidworks 2013

    Uriel Avron



      Please take a look at the following snippet (C# API for SolidWorks 2013):


      fullName = currSW3D.GetPathName();


      MessageBox.Show ( "Current 3D object identified as: " + currSW3D.GetTitle () );


      warns = currSW3D.GetType();



      The Current model is correctly identified by its name and its type is a part. The messagebox correctly states the name of the model without the extension and the model type is correctly identified as a part. Nonetheless, when the program reaches the SaveAs3 command, Solidworks get completely stuck and I have to stop it through the Task Manager.

      Interestingly, the STEP file is successfully created, but the program hangs.

      What am I doing wrong?


      Thank you

        • Re: SaveAs3 crashes Solidworks 2013
          Adam Hoffman

          I'm not a C# guy but you should probably be using the modeldoc.Extension.SaveAs namespace. Here is what I use to save a step file in VB.Net:


          Dim bRet as Boolean = False

          Dim iErrors as New Integer

          Dim iWarnings as new Integer


          bRet = currSW3D.Extension.SaveAs(fullName + ".STEP", _

                                                                      swSaveAsVersion_e.swSaveAsCurrentVersion, _

                                                                      swSaveAsOptions_e.swSaveAsOptions_Silent, _

                                                                      Nothing, iErrors, iWarnings)


          Hope this helps.

            • Re: SaveAs3 crashes Solidworks 2013
              Uriel Avron

              Hi Adam,


              Thank you for your reply.

              Initially I have encountered the problem when using the SaveAs method as you have suggested. I hoped that an older method would behave differently, but obviously I was wrong.

              I am sure that the issue lies with the way I am preparing the model for conversion. I base this assumption on the fact that using the same processes, I am capable of creating X_T and PDF files without a hitch. Funnily enough, the STEP file is created successfully too, only that Solidworks hangs immediately after creating the STEP file.

              I am aware of the fact that the 3D model has to be activated before creating the STEP file and I do that, but maybe there is something else I am not aware of.

              Thank you for your time.

                • Re: SaveAs3 crashes Solidworks 2013
                  Adam Hoffman

                  The only thing about the code you provided that throws a red flag to me is you might try and make sure there is a period in front of STEP. Right now you are showing "STEP". So you might try ".STEP". I have also found it is better to break up the directory and filename to separate variables when saving out files. Like this:


                  Dim sPath As String = Path.GetDirectoryName(currSW3D.GetPathName)

                  Dim sFileName As String = Path.GetFileNameWithoutExtension(currSW3D.GetPathName)

                  Dim fullName As String = sPath + "\" + sFileName + ".STEP"


                  This provides better use if you wanted to use this sub or program for a batch file program in the future. But it is just a suggestion. You might also check for the step file's existence before saving it out. If it exists, then delete it before saving a new version. I have found SolidWorks does not like to overwrite existing files and keep working properly when writing my own programs. Good Luck!

              • Re: SaveAs3 crashes Solidworks 2013
                Jim Sculley

                SaveAs3 is marked as obsolete in the API documentation.  You should be using IModelDocExtension::SaveAs.


                Jim S.

                • Re: SaveAs3 crashes Solidworks 2013
                  Keith Rice



                  Record yourself saving the model as a step file using the macro recorder in C#:


                  1. Tools-->Macro-->Record

                  2. Perform the save

                  3. Tools-->Macro-->Stop

                  4. When the save dialog appears, choose C# as the "save as" type.


                  Was the save successful? If yes, then replay the macro and see if the crash occurs. If it works, then there is something wrong with your code and you should compare it to the macro recorder code to see the difference. If the macro recorder code still causes a crash, then there is something else wrong and you should provide the model for us to test.


                  Please also post a complete macro, not just a snippet. It makes it easier for us to help you.



                  SolidWorks API Tutorials

                    • Re: SaveAs3 crashes Solidworks 2013
                      Uriel Avron

                      Hi Keith,

                      Thank you for your reply.

                      The code was initially created from a Macro (that BTW, uses SaveAs3) and I have changed it according to my needs. The full program is huge and involves a lot of methods, posting it here is not a real option, though I will be happy to send it to anyone who is interested in it.

                      Thank you very much for your time.

                      All the best


                        • Re: SaveAs3 crashes Solidworks 2013
                          Keith Rice

                          Correct, you shouldn't post the entire program. But you should post a working macro in which your problem is repeated. That gives us everything we need to understand your code but not more than we need.


                          I'll ask my question again:


                          Does the code recorded by the macro recorder cause a crash or does the crash occur only after you modify the code (or insert into your main program)? That is critical information to isolating the cause of your problem.



                          SolidWorks API Tutorials

                      • Re: SaveAs3 crashes Solidworks 2013
                        Uriel Avron

                        Summary of the issue.

                        Solidworks rep suggested to compile the program using the Loader Lock exception unchecked, but it didn't help.

                        Evidently the problem was with my computer. It seems that something was really screwed up in my registry due to too many installation and removals of Solidworks and the API.

                        Trying to remove all the Solidworks related entries from the registry and deleting all the folders didn't do the job. Regcleaners and manual searching of crooked entries didn't help either. There must be some hidden, obscure and encoded registry entry that got corrupt that I could not locate.

                        Only reformatting the disk and reinstalling Solidworks and the API did the job. Now my C# Add-In runs without a hitch.

                        I hate the current situation, as I don't know when the same issue may hit me again.

                        If any of you guys/gals have a real deep knowledge about the inners of the Win7 registry I will be happy to hear from you.

                        In the meantime, thanks to all who cared to answer and tried to help.