.NET

Reply
Active Contributor
btillman
Posts: 48
Registered: ‎07-25-2012
Message 1 of 3 (757 Views)

AutoCAD Open/Close Automated Process

757 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
StephenPreston
Posts: 368
Registered: ‎05-22-2006
Message 2 of 3 (722 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/.

 

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
Active Contributor
absStructural
Posts: 34
Registered: ‎07-15-2010
Message 3 of 3 (647 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/... 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community