#!fsharp
#light
module FsTest.DrawLine
#I @"D:\\AutoCAD 2008"
#r "acdbmgd.dll"
#r "acmgd.dll"
open Autodesk.AutoCAD.Runtime
open Autodesk.AutoCAD.ApplicationServices
open Autodesk.AutoCAD.DatabaseServices
open Autodesk.AutoCAD.Geometry
[<commandmethod (?DRAWLINE?)>]
let DrawLine () =
let line = new Line(new Point3d(0.0, 0.0, 0.0), new Point3d(3333.0, 3333.0, 0.0))
let db = Application.DocumentManager.MdiActiveDocument.Database
use trans = db.TransactionManager.StartTransaction()
let bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead):?> BlockTable
let btr = trans.GetObject(bt.[BlockTableRecord.ModelSpace], OpenMode.ForWrite):?> BlockTableRecord
btr.AppendEntity(line) |> ignore
trans.AddNewlyCreatedDBObject(line, true)
trans.Commit()
#!csharp
Line line = new Line(new Point3d(0.0, 0.0, 0.0), new Point3d(3333.0, 3333.0, 0.0));
Database db = Application.DocumentManager.MdiActiveDocument.Database;
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);
btr.AppendEntity(line);
trans.AddNewlyCreatedDBObject(line, true);
trans.Commit();
}