CAD.net二次开发--自动调成图框位置

[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)函数在令一篇日志。

本文主要供新手学习。

时间: 2024-10-04 22:26:22

CAD.net二次开发--自动调成图框位置的相关文章

Revit 二次开发 自动选中对象

//获取选中对象 [TransactionAttribute(Autodesk.Revit.Attributes.TransactionMode.Manual)] public class setSelectEle : IExternalCommand { public Result Execute(ExternalCommandData commandData, ref string messages, ElementSet elements) { SetSelectionElement(co

PC端 Spark 二次开发 自动接收好友请求并同意

本次Spark二次开发是为了客服模块的开发, 能让用户一旦点击该客服则直接自动添加好友,而客服放则需自动添加好友,不同弹出对话框进行同意,这方便的广大客服. 现在废话不多说,直接上代码. package org.jivesoftware.spark.ui; import java.util.ArrayList; import org.jivesoftware.spark.util.log.Log; import org.jivesoftware.spark.util.ModelUtil; imp

C++ CAD Arx二次开发用户交互

展开一.本节课程Arx二次开发用户交互二.本节要讲解的知识点1.用户交互的一些函数:acedGetXXX(acedGetString.acedGetPoint.acedGetInt acedGetKword.acedGetReal). 2.动态创建多段线的实现. 3.acedGetPoint函数中使用关键字. 三.具体内容1.acedGetString:获取用户输入的字符串 acedGetPoint:获取用户输入的点 acedGetInt:获取用户输入的整型 acedGetKword:获取用户输

CAD.net二次开发--找到与制定点最近的2个实体

public static class Class2 { public static ObjectId[] fun(Point3d point) { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; Point3dCollection points = new Point3dCollection(); Li

CAD.net 二次开发--输出点名和点坐标,点类型

[CommandMethod("aa", CommandFlags.UsePickSet)] public void aa() { Database db = HostApplicationServices.WorkingDatabase; Document doc = Application.DocumentManager.MdiActiveDocument; Editor ed = Application.DocumentManager.MdiActiveDocument.Edit

CAD二次开发控件,dwg控件,网页DWG控件,手机浏览编辑DWG控件

梦想绘图插件5.2(MxDraw5.2) 是国内最强,最专业的CAD开发插件(控件),不需要AutoCAD就能独立运行. 控件使用VC 2010开发,具有30万行代码规模,最早从2007年第一个版本完成,经过多年的累积已经非常稳定可靠,功能完善.有关键的空间搜索算法,并使用汇编优化,可以处理50万级实体,图形的显示和处理效率比同类产品高出很多. 梦想绘图3d插件6.0(MxDraw6.03d),使用二维控件的显示核心,基于 OpenCASCADE 几何造型引擎, 创建锥.柱.环等基本几何体, 对

手机,平板当中浏览和编辑DWG的CAD控件出来啦!支持ARX二次开发

控件2014.06.30 安卓开发最新更新 发布时间:2014-06-30 22:22:42 开发包下载地址:http://www.mxdraw.com/MxDraw6.0Android(20140630)TryVersion.exe 安卓手机上的apk安装包: http://www.mxdraw.com/MxDrawApp60.apk 安卓快速入门文档: http://www.mxdraw.com/AndroidDev.doc 1. 优化dwg显示速度,现在可以极速显示dwg,比市面上的任何软

C#进行CAD二次开发环境配置

最近被公司分配到了做CAD二次开发.也是初次接触这方面的东西,其实是有些无从下手的感觉.因为公司这边也没有人有时间带我,只能是自己看书,然后再写一些Demo,再结合实际的应用来一点点的学习.废话不多说,推荐一本我入门的书籍,就是李冠亿先生的<深居浅出AutoCAD二次开发>,写的非常不错,把这本书中的Demo自己手写一遍大概就能知道CAD二次开发到底是个什么东西了. 开发环境配置 开发环境 Win10 x64 CAD 2010 Visual Studio 2012 环境配置 首先要安装CAD软

CAD二次开发中浮动面板不浮动的问题

CAD二次开发中创建了一个浮动面板,想让它创建出来后以浮动状态显示, 但是DockSides.None设置完后,面板还是不浮动.搞了很久,最后原来是 需要先设置Visible,再设置DockSides,这样就好了. ps = new PaletteSet("PSCollectPart"); ps.Style = PaletteSetStyles.NameEditable | PaletteSetStyles.ShowPropertiesMenu | PaletteSetStyles.S