- UID
- 177683
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2004-9-23
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
#region Using directives
using System;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using DBTransMan=Autodesk.AutoCAD.DatabaseServices.TransactionManager;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
#endregion
namespace ZHFArxLibrary
{
public class Arx
{
private Database db;
private DBTransMan tm;
private Transaction myT;
BlockTable bt;
BlockTableRecord btr;
public Arx()
{
db = HostApplicationServices.WorkingDatabase;
tm = db.TransactionManager;
}
#region Line
public Line AddLine(Point3d pt1, Point3d pt2)
{
Line line;
try
{
Initialize();
line = new Line(pt1, pt2);
btr.AppendEntity(line);
tm.AddNewlyCreatedDBObject(line, true);
myT.Commit();
}
finally
{
DisposeAll();
}
return line;
}
public Line AddLine(Point2d pt1, Point2d pt2)
{
Line line;
line = AddLine(new Point3d(pt1.X, pt1.Y, 0), new Point3d(pt2.X, pt2.Y, 0));
return line;
}
public Line AddLine(Point3d pt1, double x, double y)
{
Line line;
Point3d pt2 = new Point3d();
pt2.X = pt1.X + x;
pt2.Y = pt1.Y + y;
pt2.Z = pt1.Z;
line = AddLine(pt1, pt2);
return line;
}
public Line AddLineR(Point3d pt1, double angle, double length)
{
Line line;
Point3d pt2 = new Point3d();
pt2 = GetPointAR(pt1, angle, length);
line = AddLine(pt1, pt2);
return line;
}
#endregion
public void Initialize()
{
myT = tm.StartTransaction();
bt = (BlockTable)tm.GetObject(db.BlockTableId, OpenMode.ForRead, false);
btr = (BlockTableRecord)tm.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
}
public void DisposeAll()
{
bt.Close();
btr.Close();
myT.Dispose();
}
public Point3d GetPointAR(Point3d pt1,double angle,double length)
{
Point3d pt2=new Point3d();
pt2.X = pt1.X + length * Math.Cos(angle);
pt2.Y = pt1.Y + length * Math.Sin(angle);
pt2.Z = pt1.Z;
return pt2;
}
}
} |
|