【问题标题】:Linking Excel Database to AutoCad for Typical Loop Drawing Generation将 Excel 数据库链接到 AutoCAD 以生成典型的循环图
【发布时间】:2011-03-13 12:43:29
【问题描述】:

我必须知道如何以 AutoCad 格式链接仪器回路图的 excel 数据库。我有用于典型循环的 AutoCad 模板和 Excel 数据库,其中我有 100 个特定典型循环的信息。我有 AutoCad 2006、2007 和 2011。请提出自动链接和生成他的AutoCAD图纸的想法。

【问题讨论】:

    标签: excel loops drawing autocad


    【解决方案1】:

    最简单的方法是学习一点 AutoLisp,如果您想在 AutoCAD 中生成绘图或自动化您的流程,这真的值得学习。

    这是一个学习 AutoLisp 的好网站:

    http://www.afralisp.net/index.php

    AutoDesk 的 Lisp 论坛也是一个很好的帮助来源。

    至于从 Excel 中提取数据,这里有一个库,它真正便于从 AutoLisp 访问:

    http://download.cnet.com/KozMos-VLXLS/3000-2077_4-94214.html

    【讨论】:

    【解决方案2】:
    'General rule: excel and acad have to be same like both 64bit or both 32 bit !!!
    ' You will need to add a reference to the AutoCAD
    ' Type Library to run this example book. Use the "Tools -
    ' References" menu. If you prefere you can switch to late
    ' binding by changeing the AutoCAD types to generic objects
    
    
    Public Sub Excel_drives_acadPolyline_import_POINTs()
    Dim objApp As AcadApplication
    Dim objDoc As AcadDocument
    Dim objEnt As AcadEntity
    Dim varPnt As Variant
    Dim strPrmpt As String
    Dim intVCnt As Integer
    Dim varCords As Variant
    Dim varVert As Variant
    Dim varCord As Variant
    Dim varNext As Variant
    Dim intCrdCnt As Integer
    On Error GoTo Err_Control
    Set objApp = AINTERFACE.Iapp
    Set objDoc = objApp.activedocument
    AppActivate objApp.CAPTION
    objDoc.Utility.GetEntity objEnt, varPnt
    If TypeOf objEnt Is AcadLWPolyline Then
        AppActivate ThisDrawing.applicaTION.CAPTION
        varCords = objEnt.COORDINATES
        For Each varVert In varCords
            intVCnt = intVCnt + 1
        Next
        For intCrdCnt = 0 To intVCnt / 2 - 1
            varCord = objEnt.COORDINATE(intCrdCnt) 
            Excel.applicaTION.Cells(intCrdCnt + 1, 1).value = varCord(0)
            Excel.applicaTION.Cells(intCrdCnt + 1, 2).value = varCord(1)
        Next intCrdCnt
    Else
        MsgBox "Selected entity was not a LWPolyline"
    End If
    Exit_Here:
    If Not objApp Is Nothing Then
        Set objApp = Nothing
        Set objDoc = Nothing
    End If
    Exit Sub
    Err_Control:
    'debug.print  err.DESCRIPTION
    Resume Exit_Here
    End Sub
     '----------------------------------------------------------------
     ' You will need to add a reference to the Excel
      ' Type Library to run this.In case of excel excel.exe is the library !
    
    Sub acad-drives_excel()
    Dim xAP As Excel.applicaTION
    Dim xWB As Excel.Workbook
    Dim xWS As Excel.WorkSheet
    Set xAP = Excel.applicaTION
    Set xWB = xAP.Workbooks.Open(SLOPEDIR.PROJECT & "\A2K2_VBA\IUnknown.xls")
    Set xWS = xWB.Worksheets("Sheet1")
    MsgBox "Excel says: """ & Cells(1, 1) & """"
    
    Dim A2K As AcadApplication
    Dim A2Kdwg As AcadDocument
    Set A2K = AINTERFACE.Iapp
    Set A2Kdwg = A2K.applicaTION.documents.Add
    MsgBox A2K.NAME & " version " & A2K.version & _
        " is running."
    
    Dim HEIGHT As Double
    Dim p(0 To 2) As Double
    Dim TxtObj As ACADTEXT
    Dim TxtStr As String
    HEIGHT = 1
    p(0) = 1: p(1) = 1: p(2) = 0
    TxtStr = Cells(1, 1)
    Set TxtObj = A2Kdwg.modelspace.AddText(TxtStr, _
        p, HEIGHT)
    
    A2Kdwg.SaveAs SLOPEDIR.PROJECT & "\A2K2_VBA\IUnknown.dwg"
    A2K.documents.Close
    A2K.Quit
    Set A2K = Nothing
    
    xAP.Workbooks.Close
    xAP.Quit
    Set xAP = Nothing
    End Sub
    

    无论您现在选择哪种方式,都可以使用 VBA 绘制到 AutoCAD 绘图中。

    对于非程序员还有另一种方法。 AUTOCAD SCRIPT 事实上,你可以创建一个创建这些东西的 excel 表,然后你可以将它们导出到一个文本文件。对于简单的任务,一个解决方案,但如果你有更复杂的事情要做,那就是废话。 最后但并非最不重要的一点是,您可以创建动态块并使用 vba 插入它们并根据您的 Excel 表设置它们的参数值。但这会爆炸这个小帖子

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多