【问题标题】:How to insert or create line in Autocad *.dxf drawing with VB.NET?如何使用 VB.NET 在 Autocad *.dxf 绘图中插入或创建线?
【发布时间】:2013-07-29 15:27:51
【问题描述】:

我正在为 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

非常感谢您的帮助

【问题讨论】:

    标签: vb.net insert line autocad


    【解决方案1】:

    这里是一个很好的起点

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

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

    这会给你一个好的开始。

    【讨论】:

      【解决方案2】:

      可以通过引用新的 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 Developer Guide

      【讨论】:

        猜你喜欢
        • 2012-10-09
        • 1970-01-01
        • 2016-01-21
        • 1970-01-01
        • 2023-02-20
        • 2017-05-07
        • 2017-05-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多