【AutoCAD】.NETで開発を行おう – パート2 – 10分 –

その他

概要

  • AutoCADで.NETを使用して、カスタマイズします。
  • 以下のような図を.NETで作成します。

パート1は、以下を参照。

VisualStudio 2019でプロジェクトを作成

パート1と同様に VisualStudio 2019のプロジェクトを作成します。

  • vbの空のクラスライブラリの新規プロジェクトを作成します。
  • 同様に”C:\Program Files\Autodesk\AutoCAD 2022”のacmgd.dll、acdbmgd.dll、accoremgd.dllの3つを参照に指定します。

コード作成

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry

Public Class Class1
    <CommandMethod("CreateLine")>
    Public Shared Sub CreateLine()
        Dim oDb As Database = HostApplicationServices.WorkingDatabase
        Dim oTr As Transaction = oDb.TransactionManager.StartTransaction
        Dim ptStart As Point3d = New Point3d(0.0, 0.0, 0.0)
        Dim ptEnd As Point3d = New Point3d(100.0, 100.0, 0.0)
        Dim oLine As Line = New Line(ptStart, ptEnd)
        Dim oBt As BlockTable = oTr.GetObject(oDb.BlockTableId, OpenMode.ForRead)
        Dim oBtr As BlockTableRecord =
        oTr.GetObject(oBt.Item("*MODEL_SPACE"), OpenMode.ForWrite)
        oBtr.AppendEntity(oLine)
        oTr.AddNewlyCreatedDBObject(oLine, True)
        oTr.Commit()
        oTr.Dispose()
    End Sub
End Class

コンパイル

パート1を参考にコンパイルします。

NETLOADコマンドでdllの読み込み

  • AutoCADを立ち上げて、コマンドでNETLOADコマンドを打ちます。
  • CREATELINE を打ち込みます。
  • 直線が描画されます。

スポンサーリンク
その他
Engineerをフォローする
レンサバ