Exemple #1
0
        public void SaveAs()
        {
            IModelDoc2        modDoc = (IModelDoc2)iSwApp.ActiveDoc;
            ModelDocExtension mDocExten;
            IModelDoc2        swModel;
            AssemblyDoc       asmDoc       = (AssemblyDoc)modDoc;
            SelectionMgr      selectionMgr = modDoc.SelectionManager;
            Component2        component;
            string            path;
            string            recentPath;
            int errors   = 0;
            int warnings = 0;

            recentPath = iSwApp.GetRecentFiles()[0].Substring(0, modDoc.GetPathName().LastIndexOf("\\"));
            int looptime = selectionMgr.GetSelectedObjectCount2(-1);

            while (looptime >= 1)
            {
                try
                {
                    looptime--;
                    component = selectionMgr.GetSelectedObject6(looptime + 1, -1);
                    swModel   = (IModelDoc2)component.GetModelDoc2();
                    mDocExten = swModel.Extension;
                    //todo:校核是否是零件类,现在是直接抛出
                    //另存为对话框
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Title            = "另存为";
                    sfd.InitialDirectory = recentPath;//更改为最近使用
                    sfd.Filter           = "零件| *.sldprt";
                    sfd.ShowDialog();

                    path = sfd.FileName;
                    if (path == "")
                    {
                        return;
                    }
                    //另存为新零件
                    mDocExten.SaveAs(path, (int)swSaveAsVersion_e.swSaveAsCurrentVersion, (int)swSaveAsOptions_e.swSaveAsOptions_Copy, null, ref errors, ref warnings);
                    //替换现有零件
                    asmDoc.ReplaceComponents(path, "", false, true);
                }
                catch
                { }
            }
        }