0

我正在为 Autocad 使用 VBA 编程,但直到今天我还没有找到如何在 VB.NET 上创建或插入行。

我看到 VB.NET 有两种使用 acad 文件的概念。

  1. 使用:AcApplication.DocumentManager.MdiActiveDocument;

  2. 使用这样的一些,作为多个文件的事务,所有文件夹文件都被声明为数据库,块表和修改作为事务,也许我对这些概念有点迷茫,但我是 VB.NET 的新手

我需要一个示例,说明如何在 VB.NET 上创建线或圆并使用概念 2 作为数据库在 DXF 绘图上插入,因为我需要修改很多绘图。

For Each Filedxf As IO.FileInfo In Modfiles 
Try 
    Change = False 
    Dim MyDB As New Database(False, True) 
    MyDB.DxfIn(Filedxf.FullName.ToString, IO.Path.Combine(PathToChange, "dxf.log")) 
    Using MyTrans As Transaction = MyDB.TransactionManager.StartTransaction 
        Dim MyBT As BlockTable = MyDB.BlockTableId.GetObject(OpenMode.ForRead) 
        For Each MyBTRId As ObjectId In MyBT 
            Dim MyBTR As BlockTableRecord = MyBTRId.GetObject(OpenMode.ForRead) 
            For Each cadID As ObjectId In MyBTR 
                Select Case cadID.ObjectClass.DxfName.ToUpper 
                    Case "TEXT" 
                        Dim MyText As DBText = cadID.GetObject(OpenMode.ForWrite) 
                        Select Case MyText.Layer.ToUpper

非常感谢你的帮助

4

2 回答 2

0

一个很好的起点就在这里

http://exchange.autodesk.com/autocad/enu/online-help/browse

谷歌在模型空间中插入一行。更改图层属性和 transaction.GetObject()

这会给你一个好的开始。

于 2013-07-29T23:41:35.133 回答
0

可以通过引用新的 ObjectARX dll 来访问 AutoCAD 互操作。用于绘制线条、添加块或任何其他 AutoCAD 功能的代码在过去几年中基本保持不变。

您可以从 VB 中执行的一些操作:

Imports Autodesk.AutoCAD.Interop
Imports AutoCAD

'drawing lines
'Set start point x:y:z coordinates
Dim sPoint(2) As Double 'Declare start point
sPoint(0) = X1 : sPoint(1) = Y1 : sPoint(2) = Z1
'Set end point x:y:z coordinate
ePoint(0) = X2 : ePoint(1) = Y2 : ePoint(2) = Z2


'Drawing lines
temp = ThisDrawing.ModelSpace.AddLine(sPoint, ePoint)
'changing layer for new object
temp.Layer = "LONGDASH"

'setting layer
ThisDrawing.ActiveLayer = ThisDrawing.Layers.Item(11)

' Adding blocks
Dim dblRotate As Double

Dim temp As AcadBlockReference
'Call Block_Detector(blockName)
'convert rotation to radians
dblRotate = ThisDrawing.Utility.AngleToReal(CStr(dblRotation), AcAngleUnits.acDegrees) '* 3.141592 / 180#

sPoint(0) = X 'Set start point x coordinate
sPoint(1) = Y 'Set start point y coordinate
sPoint(2) = Z 'Set start point z coordinate

'Set temp = ThisDrawing.Blocks.Add(sPoint, blockName)
temp = ThisDrawing.ModelSpace.InsertBlock(sPoint, blockName, 1, 1, 1, dblRotate)

更多信息可在AutoCAD 开发人员指南中找到

于 2014-09-10T14:57:34.543 回答