.NET中如何把圆转成多义线?
如何把圆转成多义线? 这样可以控制圆的线宽。没查到相关信息,在CAD命令下可以直接用ployline,选圆弧,输入直径,再选择原来的起点,好像生成的圆不是真正的圆,用bo命令可以生成,感觉不是很恰当,也没法用.net控制。
用.NET有什么其他方法吗? 就用polyline生成两节圆弧 我看到别的程序生成的好像不是2个圆弧啊,不知道怎么做的,圆环? 同楼上观点,顺便给你写个代码吧:
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace CADTest
{
public class Class1
{
public void CircleToPloyline()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction trans = db.TransactionManager.StartTransaction();
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
PromptSelectionResult psr = ed.GetSelection();
//获取选择集,这里就不过滤了
SelectionSet ss = null;
if (psr.Status == PromptStatus.OK)
{
ss = psr.Value;
foreach (SelectedObject so in ss)
{
Circle c = trans.GetObject(so.ObjectId, OpenMode.ForWrite) as Circle;
double r = c.Radius;
Point3d cc = c.Center;
Point2d p1 = new Point2d(cc.X + r, cc.Y);
Point2d p2 = new Point2d(cc.X - r, cc.Y);
Polyline poly = new Polyline();
poly.AddVertexAt(0, p1, 1, 0, 0);
poly.AddVertexAt(1, p2, 1, 0, 0);
poly.AddVertexAt(2, p1, 1, 0, 0);
btr.AppendEntity(poly);
trans.AddNewlyCreatedDBObject(poly, true);
c.Erase(true);
}
}
trans.Commit();
trans.Dispose();
}
public void GetEntityType()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("请选择一个实体");
PromptEntityResult per = null;
try
{
per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
ObjectId id = per.ObjectId;
Transaction trans = db.TransactionManager.StartTransaction();
Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead, true);
ed.WriteMessage("\n实体ObjectId为:" + ent.ObjectId + "\n实体类型为:" + ent.GetType().FullName);
trans.Commit();
trans.Dispose();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception exc)
{
ed.WriteMessage("发生异常,原因为:" + exc.Message);
}
}
}
}
这个是效果图:
如果看不了,可以上我的博客看,地址在这里 非常感谢cdinten ,提供代码和效果,效果很好,谢谢
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace CADTest
{
public class Class1
{
public void CircleToPloyline()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
Transaction trans = db.TransactionManager.StartTransaction();
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
PromptSelectionResult psr = ed.GetSelection();
//获取选择集,这里就不过滤了
SelectionSet ss = null;
if (psr.Status == PromptStatus.OK)
{
ss = psr.Value;
foreach (SelectedObject so in ss)
{
Circle c = trans.GetObject(so.ObjectId, OpenMode.ForWrite) as Circle;
double r = c.Radius;
Point3d cc = c.Center;
Point2d p1 = new Point2d(cc.X + r, cc.Y);
Point2d p2 = new Point2d(cc.X - r, cc.Y);
Polyline poly = new Polyline();
poly.AddVertexAt(0, p1, 1, 0, 0);
poly.AddVertexAt(1, p2, 1, 0, 0);
poly.AddVertexAt(2, p1, 1, 0, 0);
btr.AppendEntity(poly);
trans.AddNewlyCreatedDBObject(poly, true);
c.Erase(true);
}
}
trans.Commit();
trans.Dispose();
}
public void GetEntityType()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("请选择一个实体");
PromptEntityResult per = null;
try
{
per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
ObjectId id = per.ObjectId;
Transaction trans = db.TransactionManager.StartTransaction();
Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead, true);
ed.WriteMessage("\n实体ObjectId为:" + ent.ObjectId + "\n实体类型为:" + ent.GetType().FullName);
trans.Commit();
trans.Dispose();
}
}
catch (Autodesk.AutoCAD.Runtime.Exception exc)
{
ed.WriteMessage("发生异常,原因为:" + exc.Message);
}
}
}
}
HTML5每日一练之Canvas标签的应用-坐标变换与路径结合使用
复制代码
页:
[1]