用VB或C#.NET实现任意两点画线
本帖最后由 作者 于 2010-11-1 22:28:08 编辑 <br /><br /> <p><font face="Verdana">刚结束NET做CAD二次开发,<font face="Verdana">请教高手指点以下问题!!</font></font></p><p><font face="Verdana">用VB或C#.NET如何实现指定任意两点画线</font> </p> 以下是C#的实例代码,跟你Lisp代码类似,可惜我对几何类不熟悉,不然可能还更加简练一些.关于几何类,可以向孤哥多请教.
public void LzxTest()
{
using (Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.LockDocument())
{
Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
PromptPointOptions proOne = new PromptPointOptions("\n请选取第一个点:");
//定义第一个点
Point3d ptOne = new Point3d();
//定义第二个点
Point3d ptTwo = new Point3d();
PromptPointResult resOne = ed.GetPoint(proOne);
if (resOne.Status == PromptStatus.OK)
{
ptOne = resOne.Value;
PromptPointOptions proTwo = new PromptPointOptions("\n请选取第二个点:");
proTwo.BasePoint = ptOne;
proTwo.UseBasePoint = true;
PromptPointResult resTwo = ed.GetPoint(proTwo);
if (resTwo.Status == PromptStatus.OK)
{
ptTwo = resTwo.Value;
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead, false);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite, false);
Line lineObject = new Line(ptOne, ptTwo);
double douLineAngle = lineObject.Angle;
#region 计算双重线的起终点坐标
//----------------------------------------------------------------------------------------------
double douDis = 0.5;
Point3d ptLineBen1 = new Point3d(ptOne.X + douDis * Math.Cos(douLineAngle + Math.PI / 2),
ptOne.Y + douDis * Math.Sin(douLineAngle + Math.PI / 2),
ptOne.Z);
Point3d ptLineEnd1 = new Point3d(ptTwo.X + douDis * Math.Cos(douLineAngle + Math.PI / 2),
ptTwo.Y + douDis * Math.Sin(douLineAngle + Math.PI / 2),
ptTwo.Z);
Point3d ptLineBen2 = new Point3d(ptOne.X + douDis * Math.Cos(douLineAngle - Math.PI / 2),
ptOne.Y + douDis * Math.Sin(douLineAngle - Math.PI / 2),
ptOne.Z);
Point3d ptLineEnd2 = new Point3d(ptTwo.X + douDis * Math.Cos(douLineAngle - Math.PI / 2),
ptTwo.Y + douDis * Math.Sin(douLineAngle - Math.PI / 2),
ptTwo.Z);
//----------------------------------------------------------------------------------------------
#endregion
Line lineObject1 = new Line(ptLineBen1, ptLineEnd1);
Line lineObject2 = new Line(ptLineBen2, ptLineEnd2);
btr.AppendEntity(lineObject1);
btr.AppendEntity(lineObject2);
trans.AddNewlyCreatedDBObject(lineObject1, true);
trans.AddNewlyCreatedDBObject(lineObject2, true);
lineObject.Dispose();
trans.Commit();
}
}
}
}
}
<p>非常感谢版主的热心帮助!!!</p>
<p>我刚测试了一下,这正是我需要实现的效果</p> 本帖最后由 作者 于 2010-10-31 15:01:57 编辑 <br /><br /> <p>另外再请教一个问题</p>
<p>C#中类似LISP中的(<font face="Verdana">polar</font>)相对点是那个函数</p>
页:
[1]