您的位置:首页 > 新闻 > 资讯 > 湖南省建三公司官网_营销型网站建设公司排名_无锡网站制作_郑州seo技术服务顾问

湖南省建三公司官网_营销型网站建设公司排名_无锡网站制作_郑州seo技术服务顾问

2024/10/17 19:19:11 来源:https://blog.csdn.net/yongshiqq/article/details/142631990  浏览:    关键词:湖南省建三公司官网_营销型网站建设公司排名_无锡网站制作_郑州seo技术服务顾问
湖南省建三公司官网_营销型网站建设公司排名_无锡网站制作_郑州seo技术服务顾问

 本例通过for循环创建255条线,颜色不同,并在线的右端点处注记文字。

效果如下:

本文有个事务的封装函数,如下:

  private ObjectId AppendEntity(Entity  entity)
  {
      ObjectId objectId;
      Database db = HostApplicationServices.WorkingDatabase;
          using (Transaction tr = db.TransactionManager.StartTransaction())
          {
              BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
              BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace ], OpenMode.ForWrite );
              objectId = btr.AppendEntity(entity);
              tr.AddNewlyCreatedDBObject(entity, true);
              tr.Commit ();   
          }
              return objectId;  
  }

完整代码如下:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AcTools;
namespace AcTools
{public class Class1{private ObjectId AppendEntity(Entity  entity){ObjectId objectId;Database db = HostApplicationServices.WorkingDatabase;using (Transaction tr = db.TransactionManager.StartTransaction()){BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace ], OpenMode.ForWrite );objectId = btr.AppendEntity(entity);tr.AddNewlyCreatedDBObject(entity, true);tr.Commit ();   }return objectId;  }private Entity[]  Mydemol( List <Line > mya ){   Entity[] ent = new Entity[mya.Count ];for (int i = 0; i < mya.Count; i++){mya[i].ColorIndex = i;ent[i] = (Entity)mya[i];   };return ent;}private Entity[] Mydemot(List<DBText > mya){Entity[] ent = new Entity[mya.Count];for (int i = 0; i < mya.Count; i++){mya[i].ColorIndex = i;ent[i] = (Entity)mya[i];};return ent;}[CommandMethod("xx")]public void Caddemo(){///Database db = HostApplicationServices.WorkingDatabase;//for (int i = 0; i < 1000; i++)//{// Circle circle = new Circle(new Point3d(0,0,0),new Vector3d (0,0,1),(double)i);//    AppendEntity(circle);//    Line line = new Line(new Point3d(i, i, 0), new Point3d(i + 100, i + 100, 0));//    AppendEntity(line );//   // AddEntityTools .AddEntityToModeSpace (db,line);//}CircularArc3d c3 = new CircularArc3d(new Point3d(0, 0, 0), new Point3d(0, 100, 0), new Point3d(100, 100, 0));//Line[] line = new Line[100]; List<Line> line1  = new List<Line>();List <DBText > text1 = new List<DBText>();for (int i = 0; i < 255; i++){Line  line = new Line(new Point3d(0, i, 0), new Point3d(100, i , 0));line.ColorIndex = i;DBText text = new DBText();text.TextString  = i.ToString();text.Position = new Point3d(100, i, 0); text.Height  = i / 20 + 1;text.ColorIndex = i;text1.Add(text);line1.Add(line); AppendEntity(text);AppendEntity(line);}//db.AddEntityToModeSpace ( Mydemol(line1));//db.AddEntityToModeSpace(Mydemot(text1));}}
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com