Esempio n. 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);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 如果不是数字冲排序,而是重新指定文字,特别是一些复杂的组合,如【项目数X代号】
        /// </summary>
        private void SaidiResortOneView(SolidWorks.Interop.sldworks.View swView, ModelDoc2 swModel)
        {
            //101,$数量×$图号  ,$数量($属性名)等等各种格式
            string strText = this.cmbStartIndex.Text;

            //是否需要进行赛迪处理-页码-页数的时候,如果页数=1不显示,否则显示页码
            bool bSaidiCheck = false;


            char[]   carr   = new char[] { '(', ')', '×', 'x', 'X', '-', '_', '=', '(', ')', '[', ']', ' ', '/', '"' };
            string[] strArr = strText.Split(carr);

            //执行完切割后,要去掉引号,因为下面还要加引号
            strText = strText.Replace("\"", "");

            foreach (string s in strArr)
            {
                if (s != "$项目数" && s != "$项目号" && s.Length > 1)
                {
                    strText = strText.Replace(s, "$PRPMODEL:\"" + s.Trim(new char[] { '$' }) + "\"");//如"$项目数×$PRPMODEL:\"名称\"";
                }
            }
            bool bXMS = (strText.IndexOf("$项目数") != -1);
            bool bXMH = (strText.IndexOf("$项目号") != -1);

            int iTextQuantity = (int)swDetailingNoteTextContent_e.swDetailingNoteTextQuantity;       //数量
            int iTextNumber   = (int)swDetailingNoteTextContent_e.swDetailingNoteTextItemNumber;     //项目号
            int iTextProperty = (int)swDetailingNoteTextContent_e.swDetailingNoteTextCustomProperty; //属性

            //遍历注释
            Note not = (Note)swView.GetFirstNote();

            while (not != null)
            {
                if (not.IsBomBalloon())                               //只有符号这个条件才可以
                {
                    Annotation ann = (Annotation)not.GetAnnotation(); //必须要有Annotation
                    if (ann == null)
                    {
                        goto ABC;
                    }
                    object[] obArr = (object[])ann.GetAttachedEntities2();//必须要有Entities
                    if (obArr == null || obArr.Length == 0)
                    {
                        goto ABC;
                    }

                    Entity     ent  = (Entity)obArr[0];
                    Component2 comp = (Component2)ent.GetComponent();

                    //看看是否有重复的,一个配置只允许标注一次,如果需要多次标注,只能用不同的配置。
                    string FullPath = comp.GetPathName() + comp.ReferencedConfiguration;

                    //先复制一份值
                    string thisTxt = strText;
                    //如果有项目数,读取项目数
                    if (bXMS)
                    {
                        //选中这个注释,然后设为项目数
                        swModel.Extension.SelectByID2(not.GetName() + "@" + swView.Name, "NOTE", 0, 0, 0, true, 0, null, 0);
                        not.SetBomBalloonText(iTextQuantity, "", iTextQuantity, "");
                        string txt = not.GetText();
                        if (txt.Length > 0)
                        {
                            thisTxt = thisTxt.Replace("$项目数", txt);
                        }
                    }
                    //如果有项目号,读取项目号
                    if (bXMH)
                    {
                        //选中这个注释,然后设为项目号
                        swModel.Extension.SelectByID2(not.GetName() + "@" + swView.Name, "NOTE", 0, 0, 0, true, 0, null, 0);
                        not.SetBomBalloonText(iTextNumber, "", iTextNumber, "");
                        string txt = not.GetText();
                        if (txt.Length > 0)
                        {
                            thisTxt = thisTxt.Replace("$项目号", txt);
                        }
                    }

                    //如果是赛迪,当页数>1时,加上-页码,否侧不加-页码
                    //先列出-页数-页码来,然后再去掉-1-1
                    if (bSaidiCheck)
                    {
                        //先设置页数属性链接
                        not.SetBomBalloonText(iTextProperty, "$PRPMODEL:\"页数\"", iTextProperty, "$PRPMODEL:\"页数\"");
                        string s = not.GetText();
                        if (s.Length > 0 && s.Length < 4 && s != "1" && s != "0")
                        {
                            thisTxt = thisTxt.Replace("-$PRPMODEL:\"页数\"", "");
                        }
                        else
                        {
                            thisTxt = thisTxt.Replace("-$PRPMODEL:\"页码\"-$PRPMODEL:\"页数\"", "");
                        }
                    }

                    //最后设置新的文本
                    not.SetBomBalloonText(iTextProperty, thisTxt, iTextProperty, thisTxt);
                }
ABC:
                not = (Note)not.GetNext();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 对于一个视图进行重排序,返回序号已经排到哪了
        /// </summary>
        private int ReSortOneView(int abc, SolidWorks.Interop.sldworks.View swView, ModelDoc2 swModel)
        {
            //先得到视图的对角线的三点坐标和比例//初始化视图
            this.GetViewThreePointAndScale(swView);

            //排序用
            ArrayList arSort = new ArrayList();
            //保存数据
            Hashtable ht = new Hashtable();
            //保存数据
            Hashtable ht2 = new Hashtable();
            //是否有在右上方的//如果没有则为0,否则保在最上方的最大值,如果最大值<0.15,说明虽然有在上方的,但可以忽略,因为离左上角很进.
            double dAtTopMaxValue = 0;


            //遍历注释
            Note not = (Note)swView.GetFirstNote();

            while (not != null)
            {
                if (not.IsBomBalloon())                               //只有符号这个条件才可以
                {
                    Annotation ann = (Annotation)not.GetAnnotation(); //必须要有Annotation
                    if (ann == null)
                    {
                        goto ABC;
                    }
                    object[] obArr = (object[])ann.GetAttachedEntities2();//必须要有Entities
                    if (obArr == null || obArr.Length == 0)
                    {
                        goto ABC;
                    }

                    Entity     ent  = (Entity)obArr[0];
                    Component2 comp = (Component2)ent.GetComponent();

                    //看看是否有重复的,一个配置只允许标注一次,如果需要多次标注,只能用不同的配置。
                    string FullPath = comp.GetPathName() + comp.ReferencedConfiguration;
                    if (arCheckRepect.Contains(FullPath))
                    {
                        goto ABC;
                    }
                    else
                    {
                        arCheckRepect.Add(FullPath);
                    }

                    //string txt = not.GetText();
                    double[] dbArr = (double[])not.GetTextPoint2();

                    //计算角度
                    double dAngle = GetAngelByNotePoint(dbArr[0], dbArr[1]);

                    if (CheckUnderOrUpTheLine(dbArr[0], dbArr[1]) == true)//在上方//升序
                    {
                        if (dAtTopMaxValue < dAngle)
                        {
                            dAtTopMaxValue = dAngle;                         //保存这个角度//这个角度是上方角度的最大值
                        }
                    }
                    else//下方的//降序
                    {
                        dAngle = 15 - dAngle;//dAngle一般不会大于二
                    }

                    arSort.Add(dAngle);    //排序
                    ht.Add(dAngle, not);   //保存数据
                    ht2.Add(dAngle, comp); //防止再算一遍
                }
ABC:
                not = (Note)not.GetNext();
            }

            ///////////////////////////////////////////////////////////////////////////////////////////////
            arSort.Sort();//排序
            if (dAtTopMaxValue < 0.15)
            {
                arSort.Reverse();                       //如果上方没有,或靠近左上角的地方有一两个(Angle<0.15),下方的也不会按DESC排序
            }
            /////////////////////////////////////////////////////////////////////////////////////////////////


            //序号为项目号,还是零件属性,还是文本
            int    iTextContent = -1;
            string strText      = "";

            if (this.rdoTemp1.Checked)
            {
                iTextContent = (int)swDetailingNoteTextContent_e.swDetailingNoteTextItemNumber;
                strText      = "";
            }
            else if (this.rdoTemp2.Checked)
            {
                iTextContent = (int)swDetailingNoteTextContent_e.swDetailingNoteTextCustomProperty;
                strText      = "$PRPMODEL:\"序号\"";
            }
            else if (this.rdoTemp3.Checked)
            {
                iTextContent = (int)swDetailingNoteTextContent_e.swDetailingNoteTextCustom;
                strText      = "";
            }
            else if (this.rdoTemp4.Checked)
            {
                iTextContent = (int)swBalloonTextContent_e.swBalloonTextQuantity;
                strText      = "0";
            }


            //开始修改
            for (int i = 0; i < arSort.Count; i++)
            {
                Note       notsub = (Note)ht[arSort[i]];
                Component2 comp   = (Component2)ht2[arSort[i]];

                //选中这个注释
                swModel.Extension.SelectByID2(notsub.GetName() + "@" + swView.Name, "NOTE", 0, 0, 0, true, 0, null, 0);

                if (this.rdoTemp2.Checked)
                {
                    this.swm.SetAtrByCompAndAtrName(comp, "序号", abc);//设置属性,并保存到零件
                }
                else
                {
                    strText = abc.ToString();//序号
                }

                //notsub.PropertyLinkedText = "$PRPMODEL:\"序号\"";//这样可能也可以
                notsub.SetBomBalloonText(iTextContent, strText, iTextContent, strText);

                //////////////////////////////////////////////////////////////////////
                //检查看看是否正确,如果不正确,再设置,这里没起到任何作用
                string txt = notsub.GetText();
                if (txt != abc.ToString())
                {
                    notsub.SetText(abc.ToString());
                }
                ///////////////////////////////////////////////////////////////////////

                abc++;
            }
            return(abc);
        }