Пример #1
0
        private void TraverseFile(DirectoryInfo dir, string OldName, string NewName)
        {
            foreach (FileInfo fi in dir.GetFiles())
            {
                if (fi.Extension.ToLower() != ".drwdot" && fi.Extension.ToLower() != ".slddrw")
                {
                    continue;                                                                            //slddrt.
                }
                string    str     = fi.FullName;
                ModelDoc2 swModel = (ModelDoc2)AllData.iSwApp.OpenDoc(str, (int)swDocumentTypes_e.swDocDRAWING);
                if (swModel == null)
                {
                    iErr++; continue;
                }
                DrawingDoc swDraw = (DrawingDoc)swModel;
                if (swDraw == null)
                {
                    iErr++; continue;
                }

                swDraw.EditTemplate();

                SolidWorks.Interop.sldworks.View swView = (SolidWorks.Interop.sldworks.View)swDraw.GetFirstView();
                Note swnote = (Note)swView.GetFirstNote();
                while (swnote != null)
                {
                    string s = swnote.GetText().ToString();
                    if (s == OldName)
                    {
                        swnote.SetText(NewName);
                        iOK++;
                        //这里需要保存
                        swDraw.EditSheet();
                        swModel.Save();
                    }
                    swnote = (Note)swnote.GetNext();
                }
                AllData.iSwApp.CloseDoc(swModel.GetTitle());
            }

            foreach (DirectoryInfo dirsub in dir.GetDirectories())
            {
                TraverseFile(dirsub, OldName, NewName);
            }
        }