コード例 #1
0
ファイル: Model.cs プロジェクト: Vinoth-Elnat/solidworks-api
        /// <summary>
        /// Saves a file to the specified path, with the specified options
        /// </summary>
        /// <param name="savePath">The path of the file to save as</param>
        /// <param name="version">The version</param>
        /// <param name="options">Any save as options</param>
        /// <param name="pdfExportData">The PDF Export data if the save as type is a PDF</param>
        /// <returns></returns>
        public ModelSaveResult SaveAs(string savePath, SaveAsVersion version = SaveAsVersion.CurrentVersion, SaveAsOptions options = SaveAsOptions.None, PdfExportData pdfExportData = null)
        {
            // Start with a successful result
            var results = new ModelSaveResult();

            // Set errors and warnings to none to start with
            var errors   = 0;
            var warnings = 0;

            // Wrap any error
            return(SolidDnaErrors.Wrap(() =>
            {
                // Try and save the model using the SaveAs method
                mBaseObject.Extension.SaveAs(savePath, (int)version, (int)options, pdfExportData?.ExportData, ref errors, ref warnings);

                // If this fails, try another way
                if (errors != 0)
                {
                    mBaseObject.SaveAs4(savePath, (int)version, (int)options, ref errors, ref warnings);
                }

                // Add any warnings
                results.Warnings = (SaveAsWarnings)warnings;

                // Add any errors
                results.Errors = (SaveAsErrors)errors;

                // If successful...
                if (results.Successful)
                {
                    // Reload model data
                    ReloadModelData();
                }

                // Return result
                return results;
            },
                                       SolidDnaErrorTypeCode.SolidWorksModel,
                                       SolidDnaErrorCode.SolidWorksModelSaveAsError,
                                       Localization.GetString("SolidWorksModelGetMaterialError")));
        }
コード例 #2
0
ファイル: Model.cs プロジェクト: zuozhu315/solidworks-api
        /// <summary>
        /// Saves a file to the specified path, with the specified options
        /// </summary>
        /// <param name="savePath">The path of the file to save as</param>
        /// <param name="version">The version</param>
        /// <param name="options">Any save as options</param>
        /// <param name="pdfExportData">The PDF Export data if the save as type is a PDF</param>
        /// <returns></returns>
        public ModelSaveResult SaveAs(string savePath, SaveAsVersion version = SaveAsVersion.CurrentVersion, SaveAsOptions options = SaveAsOptions.None, PdfExportData pdfExportData = null)
        {
            // Start with a successful result
            var results = new ModelSaveResult();

            // Set errors and warnings to none to start with
            var errors   = 0;
            var warnings = 0;

            // Wrap any error
            return(SolidDnaErrors.Wrap(() =>
            {
                // Try and save the model using the SaveAs method
                BaseObject.Extension.SaveAs(savePath, (int)version, (int)options, pdfExportData?.ExportData, ref errors, ref warnings);

                // If this fails, try another way
                if (errors != 0)
                {
                    BaseObject.SaveAs4(savePath, (int)version, (int)options, ref errors, ref warnings);
                }

                // Add any warnings
                results.Warnings = (SaveAsWarnings)warnings;

                // Add any errors
                results.Errors = (SaveAsErrors)errors;

                // If successful, and this is not a new file
                // (otherwise the RCW changes and SolidWorksApplication has to reload ActiveModel)...
                if (results.Successful && HasBeenSaved)
                {
                    // Reload model data
                    ReloadModelData();
                }

                // If we have not been saved, SolidWorks never fires any FileSave events at all
                // so request a refresh of the ActiveModel. That is the best we can do
                // as this RCW is now invalid. If this model is not active when saved then
                // it will simply reload the active models information
                if (!HasBeenSaved)
                {
                    SolidWorksEnvironment.Application.RequestActiveModelChanged();
                }

                // Return result
                return results;
            },
                                       SolidDnaErrorTypeCode.SolidWorksModel,
                                       SolidDnaErrorCode.SolidWorksModelSaveAsError,
                                       Localization.GetString("SolidWorksModelGetMaterialError")));
        }