Civil3D is its own beast of a program, highly dependant on sets of pre-existing conditions to function properly. Trying to drive it from the outside sounds like a diagnostic nightmare waiting to happen. I would instead investigate making the program work inside Civil3D (it has its own API) and consuming Excel files as a data source. Unless you are only planning to use Excel as a program/macro "host", in which case it makes even more sense to put it *all* into Civil3D.
Hi,
>> Can you send commands to the command line of Autocad from an Excel VBA?
At least yes, you can use the function "SendCommand" of the document-object and start commands in AutoCAD.
Minimalistic Code (no cleanup, no excessive error handling):
Public Sub startCommandInAcad()
Dim tAcadApp As AcadApplication
Set tAcadApp = getAcadApp
If (tAcadApp Is Nothing) Then
Call MsgBox("No AcadApplication found")
Else
If (tAcadApp.ActiveDocument Is Nothing) Then
Call MsgBox("No current Drawing found in AutoCAD-Application")
Else
On Error Resume Next
tAcadApp.ActiveDocument.SendCommand ("_-LANDXMLOUT" & vbCr & "C:\TEMP\ExpFile.XML" & vbCr)
If Err.Number <> 0 Then
Call MsgBox("Error occured during 'SendCommand'" & vbNewLine & Err.Description)
End If
On Error Goto 0
End If
End If
End Sub
Private Function getAcadApp() As AcadApplication
Dim tRetVal As AcadApplication
On Error Resume Next
Set tRetVal = GetObject(, "AutoCAD.Application")
On Error GoTo 0
Set getAcadApp = tRetVal
End Function
BUT: as, also mentioned by dgorsman, a tool running within Civil3D let's you access more functions resulting in better control, especially if something fails.
The SendCommand is something quite critical as you don't get any feedback. E.g. if Civil3D blocks the command you sent (e.g. for command LANDXMLOUT it might interrupt because there is no data in the file to export ... or a file with that used to export already exists ...) you don't get a feedback like an exception or a return value like you get from functions. After that Civil3D might wait for the next command or it might be unrepsonsive to COM as it has a "overwrite yes/no"-dialog open.
If you need Excel to start Civil3D and start functions in it create an app that can be loaded into Civil3D, make it COM-compatible so you can access the functions/properties within your Civil3D-internal app from your VBA-Code in Excel.
BTW: there is a special forum for Civil3D-customization >>>here<<<.
- alfred -