Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Batch convert DGN to DWG

37 REPLIES 37
Reply
Message 1 of 38
arulanand12
40182 Views, 37 Replies

Batch convert DGN to DWG

Hi All,

 

My work needs to convert thousands of DGN files to DWG. We are using AutoCAD 2012. Is it possible to batch convert dgn files with a LISP and a mapping file? Anyone have a LISP for this?

 

Any help is appreciated.

 

Arul

37 REPLIES 37
Message 2 of 38
rick.hberg
in reply to: arulanand12

Is it safe to say you don't have any Microstation installs?  If you do, or if you can find one, use Utilities -> Batch Convert.

 

Otherwise, hopefully someone else can respond....

 

If I attach a dgn and then type  -xref, ?, *,  to list all xrefs, the dgn is not listed, so I don't know what it is inside the dwg.

Civil 3D 2014
Windows 7 x64
Message 3 of 38
alanjt_
in reply to: rick.hberg

Do you have the DGNIMPORT command in 2012?

Message 4 of 38
arulanand12
in reply to: alanjt_

First of all thank you for your replies.

 

Hi rick.hberg,

We do not have Microstation.

 

Hi alanjt_ ,

Yes. We have DGNIMPORT command in AutoCAD 2012.

Message 5 of 38
lgabriel
in reply to: arulanand12

Very easy to write a batch Autolisp routine. All you would need is to create an ASCII text file (flat file) of all of the *.dgn files you wish to import, including full path. Autolisp program would then open file, read the first line, import the *.dgn file into AutoCAD, save as a *.dwg file , close, read the next line and repeat until all *.dgn files have been imported.

 

I can write the program for you, however I need for you to send me a *.dgn file to complete the program. Not familiar with *.dgn files and need a sample file to see how the DGNIMPORT function works.

Message 6 of 38
arulanand12
in reply to: lgabriel

Hi Gabriel,

 

Hope your method will help for me. I have attached a .DGN file here.

 

Thanks,

Arul

Message 7 of 38

Any luck with this LISP?  I'm also looking to batch convert alot of DGN files to DWG.  I've just begun learning programming (LISP & C) so I'm not anywhere close to the level of knowledge I need to create such a LISP.  However we are working on a project which is dragging because of the number of dgn files we must import & view.  Very exhausting. 

Message 8 of 38
arulanand12
in reply to: arulanand12

Still digging for it. I will post here, once I get LISP code.

Message 9 of 38
huaer605
in reply to: arulanand12

Free download Professional batch DGN to DWG Converter in various version

Message 10 of 38
mmoolhuysen
in reply to: arulanand12

I've written the attached Lisp routine for converting multiple DGN files into DWG files. It expects a text file with the drawing names to convert as input. I've used it to convert large quantities of drawings.

 

The user has to make the necessary adjustments to the following variables:

tx1 = path and name of a file that holds a list with names for all the *.dgn's to be imported, names of *.dgn drawings may be written without extension, as well as with extension, in plain text format, no return after the last line.
tx2 = the path for the input folder, containing the actual *.dgn files to import.
tx3 = the path for the output folder, where the drawings converted into *.dwg will be saved, (routine assumes that the *.dwg files do not exist yet)
tx4 = name of the drawing model to import

Start the command by typing DGNI

 

The routine reads drawing names from the file given in tx1 line-for-line.
In each loop it performs a DGNIMPORT from the folder given as tx2 into the existing AutoCAD drawing,
does a Zoom Extends, saves the converted drawing result as *.dwg in the folder given as tx3,
and finally restores the drawing to its original state, ready to receive the next DGNIMPORT loop.

 

The DGNIMPORT command trips when the name of the *.dgn to be imported contains a comma, I advise to rename the drawings having this issue.

With friendly greetings, M. Moolhuysen.

Message 11 of 38
arulanand12
in reply to: arulanand12

Thanks for the LISP. I will post my feedback later after running it.

Message 12 of 38
mmoolhuysen
in reply to: arulanand12

I didn't implemented any mapping setup in my lisp file. If you need this, you should insert it as the 4th parameter of the DGNIMPORT command, in other words, replace the last pair of double quotes with the name of the mapping setup prepared in the defauld startup drawing.

Message 13 of 38
arulanand12
in reply to: mmoolhuysen

DGN files have external links for title blocks. I have put all these external linked files in the same folder where input DGN files are. But the LISP loop is breaking when it looks for the external link. Is it possible to locate it from within LISP? I would appreciate your help.

Message 14 of 38
mmoolhuysen
in reply to: arulanand12

The setting to include references can't be changed with command line version of DGNIMPORT. However, it can be set by  in the dialogue box of the the regular DGNIMPORT command. I suspect that the stetting is saved in the registry, because it persist from drawing session to drawing session, and that last property is good news for us.

 

So, as a workaround to change things towards a behavior as desired by you, try this:

Import one random DGN-file using the regular DGNIMPORT command. In the dialogue box, look for a framed section named External DGN references, in there, select the radio button in front of option Translate references to blocks or xrefs. Allow the import to proceed by clicking on the OK button.

 

After this, I've opened a new drawing and run the LISP routine I've posted before, and now it did include the references.

 

With friendly greetings, Manfred.

Message 15 of 38
ddotten
in reply to: arulanand12

Thank you for the lisp file.  However, I have not been able to perform a DGNIMPORT with 2012.  I have been able to run the command in 2011.  Could you advise me as to how to modify the lisp routine to be compatible with 2011?  

Message 16 of 38
mmoolhuysen
in reply to: ddotten

We haven't installed version 2011, so you will have to do some testing yourself:

  1. Type -DGNIMPORT (dash in front of command name) at the command line prompt, to see what options this command expects without the use of a dialogue box.
  2. I believe system variable DGNIMPORTMODE does not exist yet in version 2011, so you have to drop the line (setvar "DGNIMPORTMODE" 1). I do not know if standard behavior of DGNIMPORT in version 2011 is to import into the existing drawing or always create a new drawing (this is controlled by the setting of system variable DGNIMPORTMODE in version 2012)
Message 17 of 38
ddotten
in reply to: arulanand12

I did remove the line (setvar "DGNIMPORTMODE" 1) as 2011 does not have that variable.  And 2011 does open a new drawing.  

 

In an attempt to run down the problem I changed the variables from LOCAL to GLOBAL.  I then loaded the LISP and executed the DGNI command.  I received error: bad argument type: FILE nil.  I then queried variables tx1-tx4 and they were correct.  However tx5 returns "nil" as does the variable fil.  

Message 18 of 38
mmoolhuysen
in reply to: ddotten

Variable fil staying nil suggests that line  (setq fil (open tx1 "r") was not successfully executed.

  1. Please check if variable tx1 holds the correct filename inclusive path for the txt file containing the names of the drawings you want to convert.
  2. You're not able to re-open the file because a previous run of the routine did come to the point it supposed to close the file at line (close fil) or was not able to close it properly.
Message 19 of 38
ddotten
in reply to: mmoolhuysen

I have solved the "fil variable problem" of the LISP.  (I had included the file path in my DGNConvertList)

I begin in Drawing1.  I load the LISP and type the DGNI command.  AutoCAD opens the 1st dgn "TopoA" in Drawing2.  The program stops with the dgn displayed.  If I toggle back to Drawing1 then the LISP continues and the Drawing1 is saved as a TopoA.dwg.  It then proceeds to open the 2nd dgn "TopoB" in Drawing3 and once again the program stops.  If I once again toggle back to the original drawing whose name is now TopoA, the process resumes.  This continues until the last dgn has been opened.  It has saved the dgns as dwgs in the target folder, but I have to manually switch each time a dgn is imported.

 

Message 20 of 38
ddotten
in reply to: ddotten

I have solved the "fil variable problem" of the LISP.  (I had included the file path in my DGNConvertList)

The problem now is that in AutoCAD 2011 the DGNIMPORT command opens a new drawing each time.  

 

I begin in Drawing1.  I load the LISP and type the DGNI command.  AutoCAD opens the 1st dgn "TopoA" in Drawing2.  The program stops with the dgn displayed.  If I toggle back to Drawing1 (or close Drawing2) then the LISP continues and the Drawing1 is saved as a TopoA.dwg.  It then proceeds to open the 2nd dgn "TopoB" in Drawing3 and once again the program stops.  If I once again toggle back to the original drawing whose name is now TopoA (or close Drawing3), the process resumes.  This continues until the last dgn has been opened.  It has saved the dgns as dwgs in the target folder, but I have to manually switch each time a dgn is imported.

 

Is there a routine or command that I can insert into the LISP to return AutoCAD to the original drawing to allow the process to continue?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost