AutoCAD Open/Close Automated Process

AutoCAD Open/Close Automated Process

btillman
Advocate Advocate
1,745 Views
2 Replies
Message 1 of 3

AutoCAD Open/Close Automated Process

btillman
Advocate
Advocate

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

 

0 Likes
1,746 Views
2 Replies
Replies (2)
Message 2 of 3

StephenPreston
Alumni
Alumni

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/.

 

HTH.

 

>>>

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

<<<

Cheers,

Stephen Preston
Autodesk Developer Network
0 Likes
Message 3 of 3

absStructural
Enthusiast
Enthusiast

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/... 

0 Likes