Jump to content

Recommended Posts

Posted

Hi, I'm trying the above for work so I'm on network, firewall etc. Can't really download much but lisp or script files I can use. Has someone done the above via a lisp or script. I've a few to do so don't want to open each one etc to make the change. Seems a relatively easy operation so I'm sure there's a fix. Thanks.

Posted

A simple script made with notepad.

 

Open dwg1.dxf
qsave dwg1
close
Open dwg2.dxf
qsave dwg2
close
Open dwg3.dxf
qsave dwg3
close
Open dwg3.dxf
qsave dwg3
close

The dwg1 would be like "C:\\mydxfiles\\project123\\dwg1"

 

There are various ways to make a list of dwg names, how many are we talking about ?

Posted

An other way:

Copy this code in Notepad and save it on your computer as "Batch.lsp"

(defun batch()
  (command "saveas" "2010" "")
  )
(batch)

Next open AutoCAD, type APPLOAD and in the opened window, drag the file "Batch.lsp" in the start-up suit.

In Windows Explorer select all the dxf files to be converted, right-click, open (I assume AutoCAD is the default app to open the dxf files)

 

Don't forget to remove the "Batch.lsp" from the start-up suit!

 

The "2010" in the code means that it will convert the dxf files in DWG 2010 format. Change to suit.

Posted

Hi, it's various, first batch I had about 200, I'm after getting another batch of 100 or so. Sorry but only looking at this now again.

I'm ok with basic AutoCAD but I never did anything with scripts or lisps etc. Any way to make it faster is a help.

  • 3 weeks later...
Posted

It looks like dxfin is dialog box entry only and so "-DXFIN" won't work - or it didn't for me in testing

Posted

You need to set FILEDIA=0 then DXFIN works without a dialog box.

  • Like 1
Posted (edited)

rsnea not sure it will work once you hit "Quit" the lisp should stop so only do 1 dwg processed that is why the suggestion by SLW210 to use current dwg only, did you test ? 

Edited by BIGAL
Posted

This seems to work okay on my machine.

 

;;;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;;;                                                                                                                       |
;;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Modified to Import DXF (.dxf) to AutoCAD (.dwg)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|
;;;                                                                                                                       |
;;;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;;;
;;;  Original versions I got from here 
;;;  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-convert-dgn-to-dwg/td-p/3237978
;;;
;;;* 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. Modified by C. Matthews
;;;
;;;                  This software may not be sold as commercial product or included as part of a commercial product.
;;;
;;;
;;;***********************************************************************************************************************
;;;***********************************************************************************************************************
;;;                    Converts a folder of DXF *.dxf drawings into AutoCAD® *.dwg drawings                              *
;;;                                        Start command by typing DXF2DWG                                               *
;;;                                                                                                                      *
;;;                   Modified by SLW210 A.K.A. Steve Wilson from DGN import to DXF import 01/10/2024                    *
;;;                                                                                                                      *
;;;                                                                                                                      *
;;;                                     In response to this thread at CADTutor                                           *
;;;                                                                                                                      *
;;;                 https://www.cadtutor.net/forum/topic/78909-batch-convert-dxf-to-dwg/#comment-626951                  *
;;;***********************************************************************************************************************
;;;***********************************************************************************************************************

(defun C:DXF2DWG (/ fil tx1 tx2 tx3 tx4 tx5)
  (princ "Please select input folder. \n")
  (setq tx1 (vl-directory-files (setq tx2 (acet-ui-pickdir)) "*.dxf")) ; Select the folder containing *.dxf files to be imported.
  
  (princ "Please select output folder. \n")
  (setq tx3 (acet-ui-pickdir)                                             ; Select folder for the *.dwg files to be exported into.
        tx4 "Default"                                                    
  )
  (setvar "FILEDIA" 0)
  
  (foreach tx5 tx1
    (if (wcmatch tx5 "*`.???")
      (setq tx5 (substr tx5 1 (- (strlen tx5) 4)))
    )
    (command "_UNDO" "_MARK"
             "DXFIN" (strcat tx2 "\\" tx5) tx4 "" ""
             "_ZOOM" "_E"
             "._DELAY" 500
             "_SAVEAS" "2018(LT2018)" (strcat tx3 "\\" tx5 ".dwg") "_N"     
    )
    (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

  (setvar "FILEDIA" 0)   
  )

  (princ)
)

 

  • Thanks 1
  • 7 months later...
Posted
On 1/10/2024 at 5:50 PM, SLW210 said:

This seems to work okay on my machine.

 

;;;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;;;                                                                                                                       |
;;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<Modified to Import DXF (.dxf) to AutoCAD (.dwg)>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>|
;;;                                                                                                                       |
;;;||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
;;;
;;;  Original versions I got from here 
;;;  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/batch-convert-dgn-to-dwg/td-p/3237978
;;;
;;;* 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. Modified by C. Matthews
;;;
;;;                  This software may not be sold as commercial product or included as part of a commercial product.
;;;
;;;
;;;***********************************************************************************************************************
;;;***********************************************************************************************************************
;;;                    Converts a folder of DXF *.dxf drawings into AutoCAD® *.dwg drawings                              *
;;;                                        Start command by typing DXF2DWG                                               *
;;;                                                                                                                      *
;;;                   Modified by SLW210 A.K.A. Steve Wilson from DGN import to DXF import 01/10/2024                    *
;;;                                                                                                                      *
;;;                                                                                                                      *
;;;                                     In response to this thread at CADTutor                                           *
;;;                                                                                                                      *
;;;                 https://www.cadtutor.net/forum/topic/78909-batch-convert-dxf-to-dwg/#comment-626951                  *
;;;***********************************************************************************************************************
;;;***********************************************************************************************************************

(defun C:DXF2DWG (/ fil tx1 tx2 tx3 tx4 tx5)
  (princ "Please select input folder. \n")
  (setq tx1 (vl-directory-files (setq tx2 (acet-ui-pickdir)) "*.dxf")) ; Select the folder containing *.dxf files to be imported.
  
  (princ "Please select output folder. \n")
  (setq tx3 (acet-ui-pickdir)                                             ; Select folder for the *.dwg files to be exported into.
        tx4 "Default"                                                    
  )
  (setvar "FILEDIA" 0)
  
  (foreach tx5 tx1
    (if (wcmatch tx5 "*`.???")
      (setq tx5 (substr tx5 1 (- (strlen tx5) 4)))
    )
    (command "_UNDO" "_MARK"
             "DXFIN" (strcat tx2 "\\" tx5) tx4 "" ""
             "_ZOOM" "_E"
             "._DELAY" 500
             "_SAVEAS" "2018(LT2018)" (strcat tx3 "\\" tx5 ".dwg") "_N"     
    )
    (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

  (setvar "FILEDIA" 0)   
  )

  (princ)
)

 

 

I've been using this code (and adapted it for one of my own routines) and it works great.
I do have some questions about it though, since I'm not entirely familiar with some commands and what their purpose are in this routine.
Specifically I don't quite understand what "_regapp" does or why it's used here (googling it didn't clear up much).
I'm also curious as to why "_QNEW" doesn't stop the lisp from running?

I was told that Autolisp couldn't go from one drawing to another, but it seems to do that just fine here.

Posted

_regapp is part of the Purge command it removes unneeded regapps (registered applications).

 

Terry Dotson gives a good explanation HERE...

 

Try QNEW manually, it opens a new drawing and changes focus to that drawing.

 

 

  • Like 2

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