找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
查看: 4944|回复: 0

初试AutoCAD + F#

[复制链接]

32

主题

8

回帖

0

精华

铜牌会员

积分
110
发表于 2011-8-8 14:13:00 | 显示全部楼层 |阅读模式
很早前的F#处女作了。
申请核心会员 转载请注明出处

#!fsharp
// 使用 F# 缩略语法
#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
// 下面是才鸟老大在 DotNetARX 帮助文件中, 第一页 Geting Started 的第一段 C# 示例.
// 对比一下还是蛮像的嘛~_~
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();
}
您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

快速回复 返回顶部 返回列表