Question on making a batch job

Question on making a batch job

Anonymous
Not applicable
574 Views
7 Replies
Message 1 of 8

Question on making a batch job

Anonymous
Not applicable

Hello, I was wondering if it was possible to make a batch job program that would run from a visual basic program. You can do something similar to this with Inventor using AdnInventorLoader method, which allows the computer to automate the inventor load-up process, and then open files and do commands with the files in a given list.

 

My question is if I can do something similar to this automation in AutoCAD. I know how to send commands and do that as part of a external plug-in/program, but making it as a automated batch job from a list of files is tripping me up.

0 Likes
575 Views
7 Replies
Replies (7)
Message 2 of 8

jdiala
Advocate
Advocate
0 Likes
Message 3 of 8

Anonymous
Not applicable

That doesn't really do what I want...I already have the processes I want AutoCAD to do programed in VB 2012, not as a script. I was hoping I could open autoCAD through VB to make it one complete program, like I can with Inventor.

0 Likes
Message 4 of 8

Anonymous
Not applicable

I tried opening AutoCAD with a shell command, but with the references needed to interact with autoCAD installed on the program, it makes autoCAD crash on startup...I'm about at my wits end trying to find a way to make this work...

0 Likes
Message 5 of 8

norman.yuan
Mentor
Mentor

Automating AutoCAD from an external application (stand-alone EXE) can be easily done via COM automation. It is a well-known technology for more than 20 year and still used.

 

Since you mentioned using VB.NET to develop your app, you can (some pseudo code):

 

1. Set reference to AutiCAD type library in the "Add refernces" dialog, "COM" tab.

2. You write code like:

 

Dim cadApp As AcadApplication=New AcadApplication ''This will start AutoCAD session

cadApp.VIsible=True ''This will make AutoCAD application visible

For Each fileName as String in MyDwgFileList

    Dim dwg As AcadDocument=cadApp.Documents.Open(fileName, False)

    ''Do whatever you want to do with the drawing via COM API

    dwg.Close(True/False) ''Close the drawing with/without saving

Next

cadApp.Quit ''QUit AutoCAD

 

However, you may really want to think hard to decide if automating AutoCAD from external exe is really the good solution. You can easily do the batch jobs inside AutoCAD with VBA (or with AutoCAD .NET API). This topic is a dead horse beaten so many times. Discretion is advised.

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 6 of 8

Anonymous
Not applicable

Hello.

 

Thanks for the code, and sorry for being a complete idiot, but even after I added the COM references for the AutoCAD Type Library, I get this error. What in my stupidity did I do wrong?

 

"Unable to cast COM object of type 'System.__ComObject' to interface type 'Autodesk.AutoCAD.Interop.AcadApplication'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{9FD28580-7461-4A57-AF4F-695AF5FDDA35}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

0 Likes
Message 7 of 8

Anonymous
Not applicable
never mind figured it out. I was using 32-bit versions when I should have been using 64-bit. I'm an idiot through and through.
Message 8 of 8

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I'm an idiot through and through.

I fully disagree, because you found the source of the problem and even better (from the point of the forum-view) you documented your mistake here and so you are helping others!

 

Happy coding, - alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2026
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Likes