开发者

Linking Excel Database to AutoCad for Typical Loop Drawing Generation

I have to know how can i link the excel database of Instrument loop Diagram in AutoCad format. I have AutoCad Template for a loop typical and Excel Database in which i h开发者_Go百科ave 100 Loops information for particular typical.I have AutoCad 2006,2007 and 2011 with me. please suggest idea for linking and generating he AutoCAD Drawings automatically.


The easiest way would be to learn a bit of AutoLisp, which is really worth learning if you're into generating drawings or automating your processes within AutoCAD.

Here's a great website for learning AutoLisp:

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

AutoDesk's Lisp forum is also a great source of help.

As for extracting the data from Excel, here is a library which really facilitates access from AutoLisp:

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


'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

Whatever way you choose now you can draw into the autocad drawing by using VBA.

There is another way for non programmers. AUTOCAD SCRIPT in fact you can create a excel table which creates this things and then you can export them to a text file. For simple task a solution but crap if you hase more complex things to do. And last but not least you can create dynamic blocks and use vba to insert them and set the values of their parameters according to your excel sheet. But this would explode this tiny post

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜