栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

autocad.net 画多段线

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

autocad.net 画多段线

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using Autodesk.AutoCAD.DatabaseServices; // (Database, DBPoint, Line, Spline)using Autodesk.AutoCAD.Geometry; //(Point3d, Line3d, Curve3d)using Autodesk.AutoCAD.ApplicationServices; // (Application, Document)using Autodesk.AutoCAD.Runtime; // (CommandMethodAttribute, RXObject, CommandFlag)using Autodesk.AutoCAD.EditorInput; //(Editor, PromptXOptions, PromptXResult)using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

using Autodesk.AutoCAD.Colors;

namespace _05_多段线批量等间距法线绘制

{

public class Class1

{

// 获取当前活动文档 Document doc = Application.DocumentManager.MdiActiveDocument;

[CommandMethod("BCED")]

public void BatchCurveEquiDistance()

{

Database db = HostApplicationServices.WorkingDatabase;

Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;

ed.WriteMessage("欢迎使用多段线等间距绘制法线程序n");

// 单选图元 ObjectId curveId = this.SelectEntity("n请选择一个多段线对象", typeof(Polyline));

// 判断是否选取了多段线对象 if (curveId != null)

{

using (Transaction trans = db.TransactionManager.StartTransaction())

{

Curve curEnt = trans.GetObject(curveId, OpenMode.ForRead) as Curve;

// 获取多段线终点 Point3d endPoint = curEnt.EndPoint;

// 多段线长度 double lineLength = curEnt.GetDistAtPoint(endPoint);

// 间隔距离 double dis = 10;

// 第一个点距离起点距离 double myDis = dis;

while (myDis < lineLength)

{

//获取距离起点 mydis 的多段线上的一个点 Point3d point = curEnt.GetPointAtDist(myDis);

//一阶导数 即切线向量 Vector3d curVector = curEnt.GetFirstDerivative(point);

//获取切线方向的垂线向量 (从切线得到法线) Vector3d curPervector = curVector.GetPerpendicularVector();

//向量转化成标准单位向量 curPervector = curPervector.GetNormal();

//起始点+ 单位向量*距离 就是距离起始点 距离向量长度的 一个点 Point3d newPoint = point.Add(curPervector * 10);

// 绘制直线 this.CreateLine(point, newPoint, 1);

// 间隔递增 myDis = myDis + dis;

}

trans.Commit();

}

}

}

/// /// 单选实体 /// /// /// /// public ObjectId SelectEntity(string message, Type enttype)

{

PromptEntityOptions opts = new PromptEntityOptions(message);

if (enttype != null)

{

opts.SetRejectMessage("选择图元类型错误,请重新选择" + enttype.ToString());

opts.AddAllowedClass(enttype, true);

}

PromptEntityResult res = doc.Editor.GetEntity(opts);

return res.ObjectId;

}

/// /// 创建直线 /// /// 直线起点 /// 直线终点 /// 直线颜色 /// 图层名称 public void CreateLine(Point3d strartPoint, Point3d endPoint, int Color)

{

// 获得数据库 Database db = doc.Database;

// 开启事务处理 using (Transaction trans = db.TransactionManager.StartTransaction())

{

// 以读模式打开块表 BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;

// 以写模式打开当前块表记录 model空间 BlockTableRecord btr = trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;

Line line = new Line(strartPoint, endPoint);

line.ColorIndex = Color;

// 将创建的直线对象添加到Model空间 并进行事务登记 btr.AppendEntity(line);

trans.AddNewlyCreatedDBObject(line, true);

// 提交事务处理 trans.Commit();

}

}

}

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/954465.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号