Valued Contributor
Posts: 67
Registered: ‎07-25-2012
Message 1 of 3 (810 Views)

AutoCAD Open/Close Automated Process

810 Views, 2 Replies
10-01-2012 04:28 AM

I'm working on an automation process and have had some sucess with it. It's automated which means no user input is allowed. Basically the process does this:


1. Opens AutoCAD 2013

2. Loads a LISP program and executes it (a drawing is prepared and saved to the server)

3. Closes AutoCAD 2013 and waits fot the next drawing request


All works well with the exception of step #3. I haven't attempted this for the last few weeks but my testing back then to close AutoCAD caused it to close too soon. The LISP program did not complete it's execution before AutoCAD shutdown. I tried to do some delay in VB.NET but those attempts did not work as planned. The code I'm using is below:


 Sub Launch_AutoCAD()

        Dim vAcadApp As AutoCAD.AcadApplication
        Dim vAcadDoc As AutoCAD.AcadDocument
        vAcadApp = New AutoCAD.AcadApplication
        vAcadApp.Visible = True
        vAcadApp.WindowState = AcWindowState.acMax
        vAcadDoc = vAcadApp.Documents.Open("\\a_long_novell_server_path\My_Automated_Template.dwg", True)
        vAcadDoc.SendCommand("(load ""//another_long_novell_server_path/my_lisp.lsp"" ""The load failed"") " & my_start_command & Chr(13))

    End Sub


Board Manager
Posts: 418
Registered: ‎05-22-2006
Message 2 of 3 (775 Views)

Re: AutoCAD Open/Close Automated Process

10-01-2012 01:25 PM in reply to: btillman

Here's some very old (VB6) code demonstrating how to use AcadState.IsQuiescent. I've not tested that this still works. Also, for general batch processing, have you looked at the source code for the ADN Plugin of the Month DWF/PDF Batch Publish. You're welcome to reuse the code if it helps. You'll find it in the catalog here - http://labs.autodesk.com/utilities/ADN_plugins/catalog/.





Option Explicit
Dim state As AcadState
Dim app As AcadApplication

Private Sub Command1_Click()
   Dim pt1(0 To 2) As Double
   Dim pt2(0 To 2) As Double
   pt1(0) = 0: pt1(1) = 0: pt1(2) = 0
   pt2(0) = 100: pt2(1) = 100: pt2(2) = 0
   If (state.IsQuiescent) Then
    app.ActiveDocument.Database.ModelSpace.AddLine pt1, pt2
   End If
End Sub

Private Sub Form_Load()
   Set app = GetObject(, "AutoCAD.Application") ' Or CreateObject
   Set state = app.GetAcadState
End Sub



Stephen Preston
Autodesk Developer Network
Active Contributor
Posts: 36
Registered: ‎07-15-2010
Message 3 of 3 (700 Views)

Re: AutoCAD Open/Close Automated Process

10-15-2012 06:03 AM in reply to: btillman

I went through a similar problem.  The issue is that SendCommand is not synchronous (i.e. it returns before the command completes.  The most reasonable solution I could find was using the command Document.CommandEnded for steps that needed to wait until after the command finished.  Credit goes to DiningPhilosopher.


See http://forums.autodesk.com/t5/NET/acedCMD-Synchronous-Causes-Problems-with-selection-by-window/td-p/... 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!