[CommandMethod("DrawLineTest")]
public void DrawLineTest()
{
double angle = Math.PI / 4;//与X轴夹角
Point3d startPoint = new Point3d(0,0,0);//起点
double lineLength = 50;//线的长度
Vector3d vector = new Vector3d(1, 0, 0);//x轴方向向量
Point3d endPoint = startPoint + (vector.GetNormal().RotateBy(angle,Vector3d.ZAxis)) * lineLength;
//把x轴向量转到指定角度就可以了
Line line = new Line(startPoint, endPoint);
AddEntity(line);
}
public void AddEntity(Entity entity)
{
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
using (Transaction trans = db.TransactionManager.StartTransaction()) {
BlockTable bt = (trans.GetObject(db.BlockTableId, OpenMode.ForWrite)) as BlockTable;
BlockTableRecord btr = (trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)) as BlockTableRecord;
ObjectId objectId = btr.AppendEntity(entity);
trans.AddNewlyCreatedDBObject(entity, true);
trans.Commit();
trans.Dispose();
}
}
希望会对你有用。