Matt Simpson
Since AutoCAD drawing files aren't one file formats Excel lists in its
[File] Open dialog, I'd bet there's no support for such files in Excel
itself. What you _may_ be able to do is use Automation from an Excel macro
to launch AutoCAD drawing files in AutoCAD, and use AutoCAD's object model
to pull data out of its files.
If AutoCAD doesn't support Automation, you could find the specs to it's file
format (if they're publicly available - maybe not) and write some very low
level file I/O routines in VBA to extract the data. Other than that, you're
stuck with manual entry.
Actually, if you like Rube Goldberg contraption-like approaches to
automation, you could use a mouse/keyboard macro recorder program to record
the actions needed to extract the desired information from
_already_selected_ objects in an AutoCAD drawing (note: you'd need AutoCAD,
Excel and this macro recorder all up & running simultaneously), copying bits
of AutoCAD data, switching to Excel, pasting the data, switching back to
AutoCAD.
Connecting to AutoCAD (only AutoCAD 14, 2000, 2001i not LT)
Dim ACADApp as object
DIM ACADDoc as object
Dim ACADDocMS as object
'--- Connecting AutoCAD with
Excel ----------------------------------------------------
On Error Resume Next
Set ACADApp = GetObject(, "AutoCAD.Application")
If Err <> 0 Then
Err.Clear
Call MsgBox("No connection, AutoCAD must be active", vbOKOnly +
vbExclamation)
GoTo Finish
End If
On Error GoTo 0
'--- Connecting a drawing with
Excel -------------------------------------------------
On Error Resume Next
Set ACADDoc = ACADApp.ActiveDocument
If Err <> 0 Then
Err.Clear
Call MsgBox("No drawings active in AutoCADD" & vbCrLf &
Err.Description, vbOKOnly + vbExclamation)
GoTo Finish
End If
On Error GoTo 0
'--- Connecting the modelspace to
Excel ---------------------------------------------
Set ACADDocMS = ACADDoc.modelspace
'==== Reading form AutoCAD
===========================================================
'--- First make a selection in AutoCAD, started from
Excel -------------------------
Dim ACADSSet As Object ' ACADSet holds the selection
On Error Resume Next
Set ACADSSet = ACADDoc.selectionsets.Add("ASelectionSet") ' Set a
selection set to a variable
If Err <> 0 Then
' The selectionset exists, so delete first
Err.Clear
Set ACADSSet = ACADDoc.selectionsets.Item("ASelectionSet")
ACADSSet.Delete
Set ACADSSet = ACADDoc.selectionsets.Add("ASelectionSet")
If Err <> 0 Then
' Something wrong, just stopping
Call MsgBox(Err.Description, vbOKOnly + vbExclamation,
"Waarschuwing")
GOTO Finish
End If
End If
On Error GoTo 0
'--- Make the selection
happen ----------------------------------------------------
AppActivate ACADApp.Caption ' Activate AutoCAD, so that the user
can select object(s)
ACADSSet.SelectOnScreen ' The selectionset lets do a
selection from the screen
AppActivate Application.Caption ' And when the selection in AutoCAD
is finished back to excel
'--- The actual reading from the selected elements from AutoCAD
Dim ACADElem As Object
Dim ACADDataArray As Variant
Dim ACADDataPoint As Variant
Dim ACADDataLayer As String
For Each ACADElem In ACADSSet
With ACADElem
'==== Reading a Block ======
If StrComp(.entityname, "AcDbBlockReference", vbTextCompare) = 0
then
ACADDataPoint = .insertionPoint
' -- Put somehow the data in a Excel sheet
' X = ACADDataPoint(0), Y = ACADDataPoint(1) and Z =
ACADDataPoint(2)
ACADDataLayer = .layer
' .Name = the blockname
If .HasAttributes then
ACADDataArray = .GetAttributes
For i = LBound(ACADDataArray) To UBound(ACADDataArray)
' ACADDataArray(i).TagString = the TAG of the
attribute
' ACADDataArray(i).TextString = the Value of the
attribute
Next i
End If
End If ' End Reading a Block
'=== Reading a Text
If StrComp(.entityname, "AcDbText", vbTextCompare) = 0 Then
ACADDataPoint = .insertionpoint
ACADDataLayer = .layer
' The Text is .TextString
End If
End With
Next
'=== Writing to AutoCAD
Dim ACADDataPoint(2) As Double
ACADDataPoint(0) = 10# ' The X coordinate
ACADDataPoint(1) = 20# ' The Y coordinate
ACADDAtaPoint(2) = 30# ' The Z coordinate
'--- Block 'ABLOCK' must exists in AutoCAD
Set ACADElem = ACADDocMS.InsertBlock(ACADDataPoint, "ABLOCK", 1#, 1#,
1#, 0#)
ACADElem.Layer = ACADDoc.ActiveLayer ' Placing on the Active Layer
'--- Filling the Attributes
If ACADElem.hasattributes then
ACADDataArray = ACADElem.GetAttributes
For i = LBound(ACADDataArray) To UBound(ACADDataArray)
'-- Looking for the right TAG
If ACADDataArray(i).TagString = "aAttribute" Then
' ACADDataArray(i).TextString = "aValue"
End If
Next
End If
'--- A Text in AutoCAD
aTextHeight = 1# ' Text Height of 1 meter
Set ACADElem = ACADDocMS.AddText("Hallo from Excel", ACADDataPoint,
aTextHeight)
You can find all of the methodes, properties in the help of AutoCAD and just
by try and error (the watch function of the VBA editor is wonderfull)
Good luck
Pieter
"Matt" <ms...@voyager.co.nz.NOSPAM> schreef in bericht
news:9odn3q$met$1...@lust.ihug.co.nz...