Jump to content

NEED Batch DGN to DWG LISP ASAP!


tmelancon

Recommended Posts

We are bidding on a job with roughly 4500 drawings and its something that is going to put some work on my desk for a little while. The problem is that they have .DGN files and nobody has microstation. I need to quickly batch convert these to DWGs so I can see what we are working with to give an accurate quote.

 

If someone can chime in I would greatly appreciate it tremendously. God bless.

Link to comment
Share on other sites

Why not just create a script with the "-DGNIMPORT" command already in AutoCAD? You could use one of the myriad free batch script programs out there.

 

 

Also look into the DGNMAPPING command for setting up the mapping into AutoCAD.

Link to comment
Share on other sites

I am familiar with the -DGNIMPORT command, just not sure how to write the scipt so it imports the dgn, then saves the .dwg with the same name as the autocad file. There are a few steps to the DGNIMPORT command. Any help is appreciated.

Link to comment
Share on other sites

Thanks pkenewell, I did notice this LISP earlier and gave it a shot and from some reason when I run it I am getting this... I have everything exactly where it needs to be. I even ran DGNIMPORT on the few test files I have set up to test this lisp and it works fine, but when I run the LISP I get the error. FYI I only have 4 .DGN test files and for some reason and getting all these Invalid errors.

 

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Invalid or unsupported DGN file.

Link to comment
Share on other sites

Thanks for your quick response ReMark,

 

Here is what I have currently:

 

;* DGN_batch_modified.LSP - Converts a list of Microstation *.dgn drawings into AutoCAD *.dwg drawings
;                  Start command by typing DGNI
;
;                  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
;
;
;                  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 DELAY command for 1000 milliseconds (1 second) is needed to provide sufficient separation
;                  between the DGNIMPORT and SAVEAS processes (otherwise it starts to mix up drawings).
;
;                  The DGNIMPORT command trips when the name of the *.dgn to be imported contains a comma,
;                  I advise to rename drawings having this issue.
;
;                  Written by M. Moolhuysen. Modified by C. Matthews
;
;                  This software may not be sold as commercial product or included as part of a commercial product.


(defun C:DGNI (/ fil tx1 tx2 tx3 tx4 tx5)
 (setq tx1 "C:\\Users\\tmelancon\\Desktop\\DGN\\DGN-LIST.txt"            ;; example variable: file holding a list of *.dgn's names to be imported.
       tx2 "C:\\Users\\tmelancon\\Desktop\\DGN"                          ;; example variable: input folder.
       tx3 "C:\\Users\\tmelancon\\Desktop\\DGN\\DGN-CAD"                 ;; example variable: output folder.
       tx4 "Default"                                                     ;; example variable: drawing model name
 )
 (setvar "DGNIMPORTMODE" 1)
 (setq fil (open tx1 "r")
       tx5 (read-line fil))         ; repeats program until all lines from the list with *.dgn drawing names are read.
 (while tx5                         ; strips an extension with length of 3 characters from the drawing name, if present.
   (if (wcmatch tx5 "*`.???")
     (setq tx5 (substr tx5 1 (- (strlen tx5) 4)))
   )
   (command "_UNDO" "_MARK"
            "_-DGNIMPORT" (strcat tx2 tx5) tx4 "" ""
            "_ZOOM" "_E"
            "._DELAY" 500
            "_SAVEAS" "2000(LT2000)" (strcat tx3 tx5)
   )
   (command "_ERASE" "ALL" "")                ;erases everything on the page after the save
   (command "_.purge" "_all" "" "_no")        ;purges everything so you don't carry it over to the next drawing
   (command "_.purge" "_regapp" "" "_no")
   (command "_QNEW")                          ;opens a new drawing
   (setq tx5 (read-line fil))
 )
  (close fil)
 (command "_QUIT" "_Y")
 (princ)
)

 

With that said, I have a folder called "DGN" on my desktop. In that folder is a .txt file containing the list of 4 test file names (will move all when I am ready). I also have a folder called "DGN-CAD" for the output of the saved down .DWG files. I double checked everything and still something isnt right.

Link to comment
Share on other sites

Thanks pkenewell, I did notice this LISP earlier and gave it a shot and from some reason when I run it I am getting this... I have everything exactly where it needs to be. I even ran DGNIMPORT on the few test files I have set up to test this lisp and it works fine, but when I run the LISP I get the error. FYI I only have 4 .DGN test files and for some reason and getting all these Invalid errors.

 

 

As ReMark Said: did you adjust the paths in the file?

 

 

Below is a tweak that I did to it using the +SAVEAS command. Works fine for me in AutoCAD 2016:

 

 

;* DGNIMPORT.LSP - Converts a list of Microstation *.dgn drawings into AutoCAD *.dwg drawings
;                  Start command by typing DGNI
;
;                  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
;
;
;                  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 DELAY command for 1000 milliseconds (1 second) is needed to provide sufficient separation
;                  between the DGNIMPORT and SAVEAS processes (otherwise it starts to mix up drawings).
;
;                  The DGNIMPORT command trips when the name of the *.dgn to be imported contains a comma,
;                  I advise to rename drawings having this issue.
;
;                  Written by M. Moolhuysen.
;
;                  This software may not be sold as commercial product or included as part of a commercial product.

(defun C:DGNI (/ fil tx1 tx2 tx3 tx4 tx5)
 (setq tx1 "C:\\Users\\philk\\Desktop\\Sample\\Dgn-names.txt"  ;; example variable: file holding a list of *.dgn's names to be imported.
       tx2 "C:\\Users\\philk\\Desktop\\Sample\\"      ;; example variable: input folder.
       tx3 "C:\\Users\\philk\\Desktop\\Sample\\"      ;; example variable: output folder.
       tx4 "Default"                                  ;; example variable: drawing model name
 )
 (setvar "DGNIMPORTMODE" 1)
 (setq fil (open tx1 "r")
       tx5 (read-line fil))
 ; repeats program until all lines from the list with *.dgn drawing names are read.
 (while tx5
   ; strips an extension with length of 3 characters from the drawing name, if present.
   (if (wcmatch tx5 "*`.???")
     (setq tx5 (substr tx5 1 (- (strlen tx5) 4)))
   )
   (command "_UNDO" "_MARK"
            "_-DGNIMPORT" (strcat tx2 tx5) tx4 "" ""
            "_ZOOM" "_E"
            "._DELAY" 1000
            "._+SAVEAS" "dwG" "2013dwg" "" (strcat tx3 tx5)
            "_UNDO" "_BACK"
   )
   (setq tx5 (read-line fil))
 )
 (close fil)
 (command "_QUIT" "_Y")
 (princ)
)

Link to comment
Share on other sites

Thanks for your quick response ReMark

 

Here is what I have currently:,...

 

 

 

AH - I see the problem: You need to end all the paths in the variables with "\\"! (except "tx1" wich already has the filename).

 

 

It does not see the "DGN" folder because when it combines the path and the filename - there is nothing separating them. Instead it sees "DGN.dgn" rather than "DGN\\.dgn".

 

   tx2 "C:\\Users\\tmelancon\\Desktop\\DGN\\"   ;;SEE double-backslash on end!
   tx3 "C:\\Users\\tmelancon\\Desktop\\DGN\\DGN-CAD\\" 

Link to comment
Share on other sites

Oh my goodness... Can we say SLAP IN THE FOREHEADD:facepalm::facepalm:!! WOW! Can I blame it on Monday??! If so then ITS MONDAY!!! Thank you thank you thank you REMARK and PKENEWELL!!! BEASSTTSSSSSSSSS!! :notworthy::notworthy:

Link to comment
Share on other sites

Sounds like a classic case of failure to read the fine print.:lol:

 

Caulk it up to the fact that it is Monday. Enough said.

Link to comment
Share on other sites

Why not just a script there is another post here around 200+ dgn ins automatically, if I have to make a list then run program I could have had the script done.

 

If all in one directory you can simply make 90% of your script using old fashioned CMD option. Dir *.dgn > dirlst /b then edit dirlist in Word to add the commands check out Replace and ^p

 

_.DGNIMPORT "P:\2014 Projects\2014073\Design\basin 1\2014073-1" SAVESAS 2014073-1 CLOSE

Link to comment
Share on other sites

  • 1 month later...

I've been trying to get this same script from Mr. Moolhuysen to work for quite some time but keep running into the same error. When it gets to the _-DGNIMPORT command I get the following error:

 

FATAL ERROR: Unhandled Access Violation Reading 0xffffffff Exception at c9932045h

For the life of me I cannot figure out what the problem is. According to all of the resources I've found online, there isn't a problem with the code itself (though I could be wrong. It's happened before). Maybe I need an update for my CAD? I'm using AutoCAD MEP 2017, and below is the current lisp file that I edited, just in case I'm wrong about it.

 

(defun C:DGNI (/ fil tx1 tx2 tx3 tx4 tx5)
 (setq tx1 "C:\\Users\\mgreathouse\\Downloads\\list.txt"  ;; example variable: file holding a list of *.dgn's names to be imported.
       tx2 "C:\\Users\\mgreathouse\\Downloads\\"          ;; example variable: input folder.
       tx3 "C:\\Users\\mgreathouse\\Desktop\\dwgs\\"      ;; example variable: output folder.
       tx4 "Default"                                      ;; example variable: drawing model name
 )
 (setvar "DGNIMPORTMODE" 1)
 (setq fil (open tx1 "r")
       tx5 (read-line fil))

 ; repeats program until all lines from the list with *.dgn drawing names are read.
 (while tx5

   (command "_UNDO" "_MARK"
            "_-DGNIMPORT" (strcat tx2 tx5) tx4 "" ""
            "_ZOOM" "_E"
            "._DELAY" 1000
            "_SAVEAS" "2013(LT2013)" (strcat tx3 tx5)
            "_UNDO" "_BACK"
   )
   (setq tx5 (read-line fil))
 )
 (close fil)
 (command "_QUIT" "_Y")
 (princ)
)

Any of you peeps experienced this problem before? If anyone has any knowledge to share, I'd really appreciate it!

 

EDIT: The problem seems to be related to specific DGNs. Some DGNs work fine through this script, but some don't. I suppose they could be corrupted? The problem is they import just fine through the graphical interface within CAD, they just don't work through the _-DGNIMPORT way. All of them have Default model and Standard mapping, so that isn't the issue. As of right now this problem isn't an AutoLISP problem, so it's not applicable to this thread anymore, but if anyone knows off the top of their head an easy way to fix it, let me know!

Edited by mgreathouse
Link to comment
Share on other sites

  • 4 years later...

I've tried this LISP file and seems to work except for the first drawing.

Tried 2 drawings and 10 drawings, all are converted except for the first.

Tried a different batch in case of DGN corruption ... same again, all are converted except for the first.

 

The code is unchanged except for user input for "tx1", "tx2" and "tx3".

 

Does anyone else have this issue?

 

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...