如何使用VB.NET在Autocad*.dxf绘图中插入或创建线条



我在VBA for Autocad上编程,但直到今天我都找不到如何在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

非常感谢您的帮助

是一个很好的起点

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

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

这将给你一个良好的开端。

可以通过引用新的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开发人员指南》

相关内容

  • 没有找到相关文章

最新更新