Example #1
0
        /// <summary>
        /// Opens and saves models referenced in the open drawing.
        /// </summary>
        /// <returns>Returns a <see cref="System.Boolean"/>, should you need one.</returns>
        public Boolean ExportEDrawings()
        {
            ModelDoc2         currentDoc = swModel;
            string            docName    = currentDoc.GetPathName();
            String            sourceName = Path.GetFileNameWithoutExtension(docName);
            String            altPath    = Path.GetDirectoryName(docName).Substring(3);
            ModelDocExtension swModExt   = swModel.Extension;
            String            Rev        = GetRev(swModExt);
            String            fFormat    = String.Empty;
            List <string>     ml         = get_list_of_open_docs();
            List <String>     EdrwTarget = new List <string>();
            List <String>     STEPTarget = new List <string>();
            Boolean           measurable = true;
            Int32             options    = 0;
            Int32             errors     = 0;

            switch (modelType)
            {
            case swDocumentTypes_e.swDocASSEMBLY:
                fFormat = ".EASM";
                break;

            case swDocumentTypes_e.swDocPART:
                fFormat = ".EPRT";
                break;

            default:
                ExportPDFException e = new ExportPDFException("Document type error.");
                //e.Data.Add("who", System.Environment.UserName);
                //e.Data.Add("when", DateTime.Now);
                throw e;
            }

            swApp.ActivateDoc3(sourcePath, true, options, ref errors);
            swModel = (ModelDoc2)swApp.ActiveDoc;
            Configuration swConfig = (Configuration)swModel.GetActiveConfiguration();

            swFrame.SetStatusBarText("Positioning model.");
            swModel.ShowNamedView2("*Dimetric", 9);
            swModel.ViewZoomtofit2();

            if (!swApp.GetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEDrawingsOkayToMeasure))
            {
                swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEDrawingsOkayToMeasure, true);
                measurable = false;
            }
            else
            {
                measurable = true;
            }

            EdrwTarget.Add(String.Format("{0}{1}\\{2}{3}", APathSet.KPath, altPath, sourceName, fFormat));
            EdrwTarget.Add(String.Format("{0}{1}\\{2}{3}{4}", APathSet.GPath, altPath, sourceName, Rev, fFormat));
            if (APathSet.ExportSTEP)
            {
                STEPTarget.Add(String.Format("{0}{1}\\{2}{3}", APathSet.KPath, altPath, sourceName, @".STEP"));
                STEPTarget.Add(String.Format("{0}{1}\\{2}{3}{4}", APathSet.GPath, altPath, sourceName, Rev, @".STEP"));
            }

            Boolean success = SaveSTEPorEDrw(EdrwTarget);

            if (STEPTarget.Count > 0)
            {
                success = SaveSTEPorEDrw(STEPTarget);
            }

            if (!measurable)
            {
                swApp.SetUserPreferenceToggle((int)swUserPreferenceToggle_e.swEDrawingsOkayToMeasure, false);
            }

            if (!ml.Contains(swModel.GetPathName()))
            {
                swFrame.SetStatusBarText("Closing model.");
                swApp.CloseDoc(sourcePath);
            }
            else if (APathSet.SaveFirst)
            {
                swModel.SaveSilent();
            }
            int err = 0;

            swApp.ActivateDoc3(currentDoc.GetTitle(), true, (int)swRebuildOnActivation_e.swDontRebuildActiveDoc, ref err);

            return(success);
        }