3 Replies Latest reply on Feb 16, 2017 3:47 PM by Guillermo Oliver

    swGenericSaveError when saving as DWG

    Marc Christenson

      I have the following code that saves a drawing as a different format. It is a method in a larger class.

       

      private string ExportFile(string extension)
      {
          var dxfOutputNoScale = (int)swUserPreferenceIntegerValue_e.swDxfOutputNoScale;
          var setPreferenceResult = mSWApplication.SetUserPreferenceIntegervalue(dxfOutputNoScale, 0);
      
          // doc is a ModelDoc2 referencing the active drawing document
          var newName = doc.GetPathName() + "." + extension;
          var saveAsVersion = (int)swSaveAsVersion_e.swSaveAsCurrentVersion;
          var saveAsOptions = (int)swSaveAsOptions_e.swSaveAsOptions_Silent;
          var errorMask = 0;
          var warningMask = 0;
          var saveAsResult = doc.Extension.SaveAs(newName, saveAsVersion, saveAsOptions, null, ref errorMask, ref warningMask);
          if (saveAsResult)
          {
              return newName;
          }
      
          var errors = (swFileSaveError_e)errorMask;
          var errorList = Enum.GetValues(typeof(swFileSaveError_e)).Cast<swFileSaveError_e>().Where(v => errors.HasFlag(v)).ToList();
          var warnings = (swFileSaveWarning_e)warningMask;
          var warningList = Enum.GetValues(typeof(swFileSaveWarning_e)).Cast<swFileSaveWarning_e>().Where(v => warnings.HasFlag(v)).ToList();
          var m = "Error while creating " + extension + "\n\n" + string.Join("\n", errorList) + "\n" + string.Join("\n", warningList);
          MessageBox.Show(m, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
          return string.Empty;
      }
      

       

      When I call this method with "pdf" as the extension, everything works fine. But when I use "DWG" as the extension, the SaveAs fails with a swGenericSaveError. If I manually save the drawing as a DWG, I don't get an error.

       

      What can I do to troubleshoot this swGenericSaveError?