- 积分
- 8245
- 明经币
- 个
- 注册时间
- 2005-2-21
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2010-10-30 14:01:00
|
显示全部楼层
以下是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[BlockTableRecord.ModelSpace], 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();
- }
- }
- }
- }
- }
|
|