CAD.net二次開發--自動調成圖框位置

來源:互聯網
上載者:User

標籤:

[CommandMethod("mm")]        public void mm()        {            Database db = HostApplicationServices.WorkingDatabase;            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;            TypedValue[] values = new TypedValue[]            {                new TypedValue((int)DxfCode.LayerName,"TK")            };            SelectionFilter selfilter = new SelectionFilter(values);            PromptSelectionResult psr = ed.SelectAll(selfilter);            if (psr.Status == PromptStatus.OK)            {                ed.WriteMessage(psr.Value.Count.ToString());            }            else return;            SelectionSet ss = psr.Value;            List<Polyline> pls=new List<Polyline>();            Point2dCollection points = new Point2dCollection();            Polyline mypl = new Polyline();            using (Transaction trans = db.TransactionManager.StartTransaction())            {                foreach (ObjectId id in ss.GetObjectIds())                {                    Polyline ent = trans.GetObject(id, OpenMode.ForWrite) as Polyline;                    if(ent!=null)                    {                        if (!ent.Closed) ent.Closed=true;                        mypl = ent;                        for (int i = 0; i < ent.NumberOfVertices; i++)                        {                            points.Add(ent.GetPoint2dAt(i));                        }                    }                }                trans.Commit();            }            double xmin = points[0].X;            double xmax = points[0].X;            double ymin = points[0].Y;             double ymax = points[0].Y;            double basex = 0; double basex1 = 0;            double basey = 0; double basey1 = 0;                        ed.WriteMessage(mypl.NumberOfVertices.ToString());            for (int i = 0; i < mypl.NumberOfVertices; i++)            {                ed.WriteMessage(points[i].ToString());            }                for (int i = 1; i < mypl.NumberOfVertices; i++)                {                                        if (xmin > points[i].X) xmin = points[i].X;                    if (xmax < points[i].X) xmax = points[i].X;                    if (ymin > points[i].Y) ymin = points[i].Y;                    if (ymax < points[i].Y) ymax = points[i].Y;                }            ed.WriteMessage("\n" + xmin.ToString() + "\n" + ymin.ToString() + "\n" );            basex = xmin + 6.0;            basey = ymin + 6.0;            basex1 = ((int)(basex * 0.1 + 0.5))*10;            basey1 = ((int)(basey * 0.1 + 0.5))*10;            ed.WriteMessage("\n改後:"+basex1.ToString());            ed.WriteMessage("\n改後:" + basey1.ToString());            Vector3d vec = new Vector3d(basex1 - basex, basey1 - basey,0);            ////////////////////////////////////////////////////            Point3d[] p = new Point3d[4];            p[0] = new Point3d(xmin + 6.0, ymin + 6.0, 0);            p[1] = new Point3d(xmax - 6.0, ymin + 6.0, 0); double basex2 = ((int)(p[1].X * 0.1 + 0.5)) * 10; double basey2 = ((int)(p[1].Y * 0.1 + 0.5)) * 10;            p[2] = new Point3d(xmax - 6.0, ymax - 6.0, 0); double basex3 = ((int)(p[2].X * 0.1 + 0.5)) * 10; double basey3 = ((int)(p[2].Y * 0.1 + 0.5)) * 10;            p[3] = new Point3d(xmin + 6.0, ymax - 6.0, 0); double basex4 = ((int)(p[3].X * 0.1 + 0.5)) * 10; double basey4 = ((int)(p[3].Y * 0.1 + 0.5)) * 10;             ObjectId[] text1id = Class2.fun(p[0]);             //ed.WriteMessage("字串長度:"+str.Length.ToString());             using (Transaction tr = db.TransactionManager.StartTransaction())             {                                     DBText thistext1 = tr.GetObject(text1id[0], OpenMode.ForWrite) as DBText;                     thistext1.TextString = basey1.ToString();                     DBText thistext2 = tr.GetObject(text1id[1], OpenMode.ForWrite) as DBText;                     thistext2.TextString = basex1.ToString();                                 tr.Commit();             }             ObjectId[] text2id = Class2.fun(p[1]);             //ed.WriteMessage("字串長度:"+str.Length.ToString());             using (Transaction tr = db.TransactionManager.StartTransaction())             {                 DBText thistext1 = tr.GetObject(text2id[0], OpenMode.ForWrite) as DBText;                 thistext1.TextString = basey2.ToString();                 DBText thistext2 = tr.GetObject(text2id[1], OpenMode.ForWrite) as DBText;                 thistext2.TextString = basex2.ToString();                 tr.Commit();             }             ObjectId[] text3id = Class2.fun(p[2]);             //ed.WriteMessage("字串長度:"+str.Length.ToString());             using (Transaction tr = db.TransactionManager.StartTransaction())             {                 DBText thistext1 = tr.GetObject(text3id[0], OpenMode.ForWrite) as DBText;                 thistext1.TextString = basey3.ToString();                 DBText thistext2 = tr.GetObject(text3id[1], OpenMode.ForWrite) as DBText;                 thistext2.TextString = basex3.ToString();                 tr.Commit();             }             ObjectId[] text4id = Class2.fun(p[3]);             //ed.WriteMessage("字串長度:"+str.Length.ToString());             using (Transaction tr = db.TransactionManager.StartTransaction())             {                 DBText thistext1 = tr.GetObject(text4id[0], OpenMode.ForWrite) as DBText;                 thistext1.TextString = basex4.ToString();                 DBText thistext2 = tr.GetObject(text4id[1], OpenMode.ForWrite) as DBText;                 thistext2.TextString = basey4.ToString();                 tr.Commit();             }            /////////////////////////修改圖框表頭下面的代號////////////////////////             Point3d pointmid = new Point3d((xmin+xmax)*0.5,ymax,0);             ObjectId[] idmid = Class2.fun(pointmid);             using (Transaction tr = db.TransactionManager.StartTransaction())             {                 DBText textmid = tr.GetObject(idmid[0], OpenMode.ForWrite) as DBText;                 string strtemp = basey1.ToString() + basex1.ToString();                 strtemp = strtemp.Insert(3, ".");                 strtemp = strtemp.Insert(7, "-");                 strtemp = strtemp.Insert(11, ".");                 textmid.TextString = strtemp;                                  tr.Commit();             }            ///////////////////////////////////////////////////            using (Transaction tran1 = db.TransactionManager.StartTransaction())            {                Matrix3d mt = Matrix3d.Displacement(vec);                foreach (ObjectId id in ss.GetObjectIds())                {                    Entity ent = tran1.GetObject(id, OpenMode.ForWrite) as Entity;                    if (ent != null)                    {                        ent.TransformBy(mt);                    }                }                tran1.Commit();            }        }

1、選擇整個圖框,找到圖框線4個節點座標,並排序

2、將圖框放在特定位置,並修改新位置座標,程式的fun(point3d p)函數在令一篇日誌。

本文主要供新手學習。

 

CAD.net二次開發--自動調成圖框位置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.