Jump to content

VBA to shut down AutoCAD


Olhado_

Recommended Posts

I have this vba code, which I call from vb program with the following batch file. It works fine, except that once the vba program is complete it needs the user to close AutoCAD to continue. Is there any way I can have a vba program close AutoCAD?

 

I tried using SendCommand "Exit" and it seems to just confuse AutoCAD.

 

 

Batch File:

 

call "C:\[...]\Acad.exe" /b "C:\plot\plot.scr" 
exit

VBA Code:

 

Public Sub Main() 
        
   Dim strPlotSize As String 
   Dim strPrinterType As String 
   Dim docCurrentDrawing As AcadDocument 
   Dim strFileName As String 
   Dim acState As AcadState 
   Dim objWin As Object 
    
      
   ' Reserved for Debugging 
   'UserForm1.Show 
    
   ' Read printer preferances 
   Read_File ("C:\plot\plot_config.txt") 
   strPrinterType = cDL(1) 
   cDL.Remove (1) 
   strPlotSize = cDL(1) 
   cDL.Remove (1) 
   
   ' Read list of files 
   Read_File ("C:\plot\batch_plot.txt") 
   
   ' Open in read-only mode and run LISP file        
   For intList = 1 To intCount 
       Set docCurrentDrawing = Application.Documents.Open(cDL.Item(intList), vbReadOnly) 
       strFileName = Replace(docCurrentDrawing.Name, ".dwg", ".pdf") 
       docCurrentDrawing.SendCommand ("CADLock" & vbCr) 
       GoTo Wait 
    
Continue:
       ' Print Page and close document 
       ReleasePrint strPrinterType, strPlotSize 
       docCurrentDrawing.Close (False) 
       For lngVbaHold = 1 To 50000 
           DoEvents 
       Next
      ' Close printed PDF document 
       CloseApp strFileName, "" 
       Next 
   
       For intList = 1 To intCount 
       CloseApp Replace(cDL.Item(intList), ".dwg", ".pdf"), "" 
       Next 
    
   On Error Resume Next 
   Application.ActiveDocument.SetVariable "FILEDIA", 1 
      
   End ' End of Program 
    
Wait: 
   Set acState = Application.GetAcadState 
   If acState.IsQuiescent Then 
        
       GoTo Continue 
        
   Else 
       DoEvents 
       GoTo Wait 
   End If 
    
End Sub 

Link to comment
Share on other sites

There's a way to shut down processes from the Windows command prompt using taskkill, but it's only available on certain versions of Windows. You can find it elsewhere and download it, just do a google search for "taskkill.exe". You could then make it into a one-line batch file and you're done.

 

Hope that helps a bit. ^.^

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...