马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
 - using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.EditorInput;
- namespace Linetype
- {
- public class Commands
- {
- [CommandMethod("CL")]
- public void CreateLinetype()
- {
- Document doc =
- Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- Transaction tr =
- db.TransactionManager.StartTransaction();
- using (tr)
- {
- // 获取线型表
- LinetypeTable lt =
- (LinetypeTable)tr.GetObject(
- db.LinetypeTableId,
- OpenMode.ForWrite
- );
- // 创建新的线型表记录...
- LinetypeTableRecord ltr =
- new LinetypeTableRecord();
- // ... 设置线型表记录的属性
- ltr.AsciiDescription = "T E S T -";
- ltr.PatternLength = 0.75;
- ltr.NumDashes = 2;
- ltr.SetDashLengthAt(0, 0.5);
- ltr.SetDashLengthAt(1,-0.25);
- ltr.Name = "TESTLINTEYPE";
- // 把新的线型添加到线型表
- ObjectId ltId = lt.Add(ltr);
- tr.AddNewlyCreatedDBObject(ltr,true);
- // 使用这个新线型创建一条测试直线
- BlockTable bt =
- (BlockTable)tr.GetObject(
- db.BlockTableId,
- OpenMode.ForRead
- );
- BlockTableRecord btr =
- (BlockTableRecord)tr.GetObject(
- bt[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite
- );
- Line ln =
- new Line(
- new Point3d(0, 0, 0),
- new Point3d(10, 10, 0)
- );
- ln.SetDatabaseDefaults(db);
- ln.LinetypeId = ltId;
- btr.AppendEntity(ln);
- tr.AddNewlyCreatedDBObject(ln, true);
- tr.Commit();
- }
- }
- }
- }
|