Visual Basic Customization

Visual Basic Customization

Reply
Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 1 of 6 (642 Views)
Accepted Solution

VBA - Convert 2010 Acad Drawings to 2004/LT2004

642 Views, 5 Replies
02-01-2013 05:49 AM

Hey all,

 

I have a simple and quick question:

Is is possitlbe using VBA (not .NET) to open an Acad 2010 Drawing, then re-save it as a Acad 2004/LT2004 Drawing?

 

I need to be able to import the drawing into some third party software, and for some reason, it is incompatible with the newer versions.

 

I would also like to know if it is possible to convert ANY version of a drawings (be it 2007, 2000, 2012, etc...).  Also if at all possible, is there an easy way to re-save a drawing that was created using other software (aka SolidWorks) to use AutoCAD's specific file formatting?  I know that when you try to open a drawing created in SolidWorks (opening in AutoCAD), that it will display a message saying the drawing was created by an external application.  I would like to be able to change the file so that AutoCAD created the drawing.

 

 

Thanks for all your help, it is greatly appreciated! :smileyhappy:

God Bless,

-Nick

If you just want to convert drawing format from Acad2010 to Acad2000/4/7, you can use Dwg TrueView to do batch job.

 

If you have to do it with VBA code, you can easily save them as older drawing format all the way back to R14 version (assume you use Acad2010-2012). You certainly do not need to mix your VBA code with LISP code (e.g. you do it either with LISP or VBA, both are simple enough.

 

You do like this (pseudo code, assuming you have a string array of dwg file names):

 

Dim fileNames As String()

Dim saveAsFielNames As strinig()

 

''Then fill the strinig arrays with dwg file names

 

Dim dwg As AcadDocument

Dim app As AcadApplication

Set app=ThisDrawing.Application

 

Dim i As Integer

For i=0 to Ubound(fileNames)

    Set dwg=app.Documents.Open(fileNames(i))

    ''Do something if needed

    dwg.SaveAs saveAsFileName(i), ac2000(4/7))_dwg

    dwg.Close

Next

 

 

If you open VBA IDE in autoCAd and open Object Browser, find AcSaveAsType in the left and highlight it, you can see all the enum values of it for your versio of AutoCAD.

 

Attached is the screen picture froom my acad2012.Untitled.png

 

 

Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 2 of 6 (614 Views)

Re: VBA - Convert 2010 Acad Drawings to 2004/LT2004

02-05-2013 07:39 AM in reply to: Millerni456

Okay so after doing some research I came across the following forums.  It looks like I might be able to accomplish this using LISP, but this would still need to be done using VBA (as I need to interface with Microsoft Office).

 

Here's the forum about running LISP using VBA:

http://forums.autodesk.com/t5/Visual-Basic-Customization/Run-lisp-command-in-autocad-from-VBA/td-p/2...

 

Here's the forum about saving as a specified file format.

http://forums.augi.com/showthread.php?50250-Use-Saveas-Command-from-a-Lisp-Routine

 

So, as I try to understand this even further;  if anyone can answer, I'd like to know if taking this route is possible.

 

Can I run a VBA program to open AutoCAD, and then execute a LISP file to save the drawing as a different format?

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 3 of 6 (601 Views)

Re: VBA - Convert 2010 Acad Drawings to 2004/LT2004

02-06-2013 06:52 AM in reply to: Millerni456

If you just want to convert drawing format from Acad2010 to Acad2000/4/7, you can use Dwg TrueView to do batch job.

 

If you have to do it with VBA code, you can easily save them as older drawing format all the way back to R14 version (assume you use Acad2010-2012). You certainly do not need to mix your VBA code with LISP code (e.g. you do it either with LISP or VBA, both are simple enough.

 

You do like this (pseudo code, assuming you have a string array of dwg file names):

 

Dim fileNames As String()

Dim saveAsFielNames As strinig()

 

''Then fill the strinig arrays with dwg file names

 

Dim dwg As AcadDocument

Dim app As AcadApplication

Set app=ThisDrawing.Application

 

Dim i As Integer

For i=0 to Ubound(fileNames)

    Set dwg=app.Documents.Open(fileNames(i))

    ''Do something if needed

    dwg.SaveAs saveAsFileName(i), ac2000(4/7))_dwg

    dwg.Close

Next

 

 

Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 4 of 6 (596 Views)

Re: VBA - Convert 2010 Acad Drawings to 2004/LT2004

02-06-2013 10:32 AM in reply to: norman.yuan

Thanks for the reply!

 

It looks like this will work!

However, is it possible you can enumerate all the different dwg file formats?

 

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 5 of 6 (590 Views)

Re: VBA - Convert 2010 Acad Drawings to 2004/LT2004

02-06-2013 12:19 PM in reply to: Millerni456

If you open VBA IDE in autoCAd and open Object Browser, find AcSaveAsType in the left and highlight it, you can see all the enum values of it for your versio of AutoCAD.

 

Attached is the screen picture froom my acad2012.Untitled.png

 

 

Valued Contributor
Millerni456
Posts: 55
Registered: ‎01-23-2013
Message 6 of 6 (584 Views)

Re: VBA - Convert 2010 Acad Drawings to 2004/LT2004

02-07-2013 07:25 AM in reply to: norman.yuan

Wow thanks, that will be very helpful!

 

Again, I appreciate all your efforts!

 

God Bless,

-Nick

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
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!