bbreal Posted December 18, 2023 Posted December 18, 2023 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. Quote
BIGAL Posted December 19, 2023 Posted December 19, 2023 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 ? Quote
fuccaro Posted December 19, 2023 Posted December 19, 2023 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. Quote
bbreal Posted December 20, 2023 Author Posted December 20, 2023 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. Quote
SLW210 Posted December 21, 2023 Posted December 21, 2023 Try these resources..... Dxf2Dwg | AutoCAD | Autodesk App Store Batch convert DXF files to DWG files (augi.com) Quote
Steven P Posted January 5, 2024 Posted January 5, 2024 It looks like dxfin is dialog box entry only and so "-DXFIN" won't work - or it didn't for me in testing Quote
SLW210 Posted January 5, 2024 Posted January 5, 2024 You need to set FILEDIA=0 then DXFIN works without a dialog box. 1 Quote
SLW210 Posted January 5, 2024 Posted January 5, 2024 Perhaps the LISP in this thread could be adapted, I'll look when I get back to work next week. Quote
BIGAL Posted January 6, 2024 Posted January 6, 2024 (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 January 6, 2024 by BIGAL Quote
SLW210 Posted January 10, 2024 Posted January 10, 2024 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) ) 1 Quote
YuriC Posted August 27, 2024 Posted August 27, 2024 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. Quote
SLW210 Posted August 27, 2024 Posted August 27, 2024 _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. 2 Quote
Clint Posted Friday at 09:35 PM Posted Friday at 09:35 PM A cursory inspection of the attached program is appreciated. I have a deadline today. The modified program shown above: DOES create the DWG files DOES NOT show the entities as shown in the source DXF files There is the possibility that I may have introduced in the code when editing it. I will thoroughly review and use the BricsCAD BLADE editor to debug it tomorrow BRICSCAD I use BricsCAD V25 that includes the DXFIN command just as AutoCAD. I took the liberty of changing the header but maintaining this link and the editor in the comments. ;;; DXF2DWG.lsp - Batch converts *.dxf drawings into *.dwg drawings ;;; Author: Written by M. Moolhuysen. Edited by C. Matthews. Edited by CEH ;;; Created on: 2024-01-10 ;;; Last edited: 2026-01-02 ;;; Description: ;;; Converts a list of BricsCAD *.dxf drawings into BricsCAD *.dwg drawings ;;; ;;;* DXFIN.LSP - Converts a list of BricsCAD *.dxf drawings into BricsCAD *.dwg drawings ;;; Start command by typing DXF2DWG ;;; ;;; Make the necessary adjustments to the following variables: ;;; --------------------------------------------------------- ;;; tx1 = path and name of a file that holds a list with names for all the *.dxf's to be imported, ;;; names of *.dxf 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 *.dxf 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 DXFIN 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 DXFIN loop. ;;; ;;; The DELAY command for 1000 milliseconds (1 second) is needed to provide sufficient separation ;;; between the DXFIN and SAVEAS processes (otherwise it starts to mix up drawings). ;;; ;;; The DXFIN command trips when the name of the *.dxf to be imported contains a comma, ;;; I advise to rename drawings having this issue. ;;; ;;; This software may not be sold as commercial product or included as part of a commercial product. ;;; ;;; 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 * ;;; ;;; ------------------------- Program Start ------------------------- ;;; (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) ) DXF2DWG.lsp Quote
Steven P Posted 23 hours ago Posted 23 hours ago .... so it isn't importing the DXF file? Still holidays till Monday so CAD is still off but what happens if you do the 'dxfin' line manually: (command "DXFIN" (strcat "-FolderName"- "\\" "-fileName-" ) "Default" "" "") 1 Quote
rlx Posted 22 hours ago Posted 22 hours ago new to Bricad but this seems to work : (defun c:DxfToDwg ( / actDoc dxf-folder dxf-list ) (setq actDoc (vla-get-activedocument (vlax-get-acad-object))) (vl-load-com) (cond ((not (setq dxf-folder (_getfolder "Select folder with dxf files"))) (princ "\nNo folder selected")) ((not (vl-consp (setq dxf-list (_getfiles dxf-folder "*.dxf")))) (princ (strcat "\nNo dxf files in folder " dxf-folder))) (t (command ".undo" "mark")(setvar "expert" 2) (foreach dxf dxf-list (command ".erase" "all" "") (vla-purgeall actDoc) (vl-cmdf "_.dxfin" dxf) (vla-ZoomExtents (vlax-get-acad-object)) (command ".save" (strcat (vl-filename-directory dxf) "\\" (vl-filename-base dxf))) ) (command ".undo" "back") ) ) (princ) ) ; generic getfolder routine with possibility to create a new subfolder (_getfolder "select path") (defun _getfolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application")) (setq f (vlax-invoke s 'browseforfolder 0 m 65536 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path)) (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s)) (if f (vl-string-translate "\\" "/" f))) (defun void (x) (or (eq x nil) (and (listp x)(not (vl-consp x))) (and (eq 'STR (type x)) (eq "" (vl-string-trim " \t\r\n" x))))) (defun _getfiles ( fol ext / lst) (cond ((or (void fol) (not (vl-file-directory-p fol))) (princ (strcat "\nInvalid folder :" (vl-princ-to-string fol)))) (t (if (vl-consp (setq lst (vl-directory-files fol ext 1))) (setq lst (mapcar '(lambda (x)(strcat fol "/" x)) lst)))) ) lst ) 1 Quote
SLW210 Posted 22 hours ago Posted 22 hours ago Do you have an example file? Most likely a difference in AutoCAD and BricsCAD, I'll try to look at it next week, but a full workload so no guarantees. IIRC, I have not used that on AutoCAD 2026. Quote
Clint Posted 21 hours ago Posted 21 hours ago (edited) 1 hour ago, rlx said: new to Bricad but this seems to work : (defun c:DxfToDwg ( / actDoc dxf-folder dxf-list ) (setq actDoc (vla-get-activedocument (vlax-get-acad-object))) (vl-load-com) (cond ((not (setq dxf-folder (_getfolder "Select folder with dxf files"))) (princ "\nNo folder selected")) ((not (vl-consp (setq dxf-list (_getfiles dxf-folder "*.dxf")))) (princ (strcat "\nNo dxf files in folder " dxf-folder))) (t (command ".undo" "mark")(setvar "expert" 2) (foreach dxf dxf-list (command ".erase" "all" "") (vla-purgeall actDoc) (vl-cmdf "_.dxfin" dxf) (vla-ZoomExtents (vlax-get-acad-object)) (command ".save" (strcat (vl-filename-directory dxf) "\\" (vl-filename-base dxf))) ) (command ".undo" "back") ) ) (princ) ) ; generic getfolder routine with possibility to create a new subfolder (_getfolder "select path") (defun _getfolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application")) (setq f (vlax-invoke s 'browseforfolder 0 m 65536 "")))(setq f (vlax-get-property (vlax-get-property f 'self) 'path)) (setq f nil))(vl-catch-all-apply 'vlax-release-object (list s)) (if f (vl-string-translate "\\" "/" f))) (defun void (x) (or (eq x nil) (and (listp x)(not (vl-consp x))) (and (eq 'STR (type x)) (eq "" (vl-string-trim " \t\r\n" x))))) (defun _getfiles ( fol ext / lst) (cond ((or (void fol) (not (vl-file-directory-p fol))) (princ (strcat "\nInvalid folder :" (vl-princ-to-string fol)))) (t (if (vl-consp (setq lst (vl-directory-files fol ext 1))) (setq lst (mapcar '(lambda (x)(strcat fol "/" x)) lst)))) ) lst ) 1 hour ago, SLW210 said: Do you have an example file? Most likely a difference in AutoCAD and BricsCAD, I'll try to look at it next week, but a full workload so no guarantees. IIRC, I have not used that on AutoCAD 2026. SLW210, Your concern is very much appreciated. As I now understand it, below is the key difference that is breaking the original program coded for AutoCAD when used in BricsCAD Researching per Grok AI: "The DXFIN command does not work exactly the same in AutoCAD and BricsCAD, though both support it and it relates to handling DXF files. Key Differences Core behavior — AutoCAD's DXFIN opens the DXF as a standalone drawing; BricsCAD's imports into the current one. Use cases — This reflects design philosophy: BricsCAD (and some other AutoCAD-compatible platforms like progeCAD) adds convenience for merging DXF data directly, a feature AutoCAD users often request but handle via workarounds. In AutoCAD The DXFIN command loads a DXF file in a way similar to the OPEN command. It typically opens the selected DXF file as a new or current drawing (often in a new tab if multiple drawings are allowed). This behavior aligns with historical use for converting DXF into an editable AutoCAD drawing, especially in older versions or for recovery purposes (e.g., exporting to DXF via DXFOUT and reloading via DXFIN to clean issues). AutoCAD lacks a built-in command to directly merge or import the full contents of a DXF file into an already open drawing. Users often work around this by opening the DXF separately and copying/pasting elements. In BricsCAD The DXFIN command explicitly opens a file dialog to select a DXF file and imports its contents into the current open drawing (merging the geometry, layers, etc., into the existing workspace). This makes it more like an "import/merge" tool. BricsCAD also has separate commands like OPEN (for opening DXF/DWG as new tabs) and IMPORT (for other formats or specific cases). Contextual nuances — Some BricsCAD forum discussions suggest slight variations (e.g., in scripts vs. interactive use), but official documentation confirms the import-into-current behavior." ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I queried Grok about the Visual LISP code submitted. Here is the result: No, this LISP code will not work reliably in BricsCAD as written, though parts of it are compatible and could function with modifications. BricsCAD offers excellent AutoLISP and Visual LISP compatibility—most functions like vla-get-activedocument, vla-purgeall, vla-ZoomExtents, vlax-get-acad-object, vl-directory-files, and vl-file-directory-p work identically or very similarly to AutoCAD. The helper functions (_getfolder, _getfiles, void) are standard and platform-agnostic (assuming Windows for the Shell COM object in _getfolder). DXFIN Behavior and Erase Step BricsCAD's DXFIN command imports the DXF file's contents into the current drawing (merging geometry, layers, etc., with existing content), rather than replacing it outright. The code explicitly erases everything first with (command ".erase" "all" ""), which clears the drawing before importing. This effectively achieves a "replace" behavior, making this part intentional and effective for BricsCAD's merge-style import. However, the line (vl-cmdf "_.dxfin" dxf) supplies the filename directly. Official BricsCAD documentation states that DXFIN opens a file dialog. In scripted/LISP mode, this might: Open the dialog (requiring user interaction, breaking batch processing) Or accept the filename argument directly (common in some CAD platforms for scripting) Without suppressing dialogs (e.g., via (setvar "FILEDIA" 0)), it risks pausing for input. Save Command Issue This is the primary breaking point. The code uses (command ".save" (strcat ... )) to save each processed DXF as a DWG (using the original base name, no extension—BricsCAD would add .dwg). In BricsCAD, the SAVE command typically performs a quick save (QSAVE) to the current drawing's name or opens the Save As dialog if unnamed. It does not reliably accept a filename argument directly in command/LISP mode for a scripted Save As operation. As a result: The provided path/filename would likely be ignored. It would either quick-save to the current drawing's existing name (overwriting the first saved file repeatedly) or prompt a dialog. For multiple files, all conversions would end up saving to the same file (the one named after the first DXF), defeating the batch purpose. BricsCAD (like AutoCAD) uses SAVEAS for specifying a new filename in scripts, often requiring (setvar "FILEDIA" 0) to avoid dialogs, e.g.: lisp (setvar "FILEDIA" 0) (command "._saveas" "" (strcat path (vl-filename-base dxf) ".dwg")) (setvar "FILEDIA" 1) Or better, use ActiveX: (vla-SaveAs actDoc newFullPath acNative) for reliable, dialog-free saving. Other Minor Notes Undo marking/back: Works, but saves commit changes, so undoing at the end won't revert saved files. Expert set to 2: Suppresses warnings—fine. Path handling: Mix of / and \\ is usually tolerated on Windows. Purge after erase: Redundant but harmless. ZoomExtents: Fine via VLA. Suggested Fixes for BricsCAD To make this batch DXF-to-DWG converter work unattended: Suppress dialogs: Add (setvar "FILEDIA" 0) at start, restore at end. For DXFIN: Test if direct filename works; if not, use a workaround (e.g., OPEN the DXF in a new drawing, then copy/paste or save). Replace the save line with a proper SaveAs, preferably via vla-SaveAs. Optionally start with a new blank drawing. Have you tested this code in BricsCAD already? What specific error or behavior did you observe (e.g., dialogs appearing, wrong saves)? Knowing that would help pinpoint if DXFIN accepts direct files in your version. Alternatively, are you open to a modified version of the code that uses more reliable methods like vla-SaveAs? ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- I will proceed with testing a modified version of the code as supplied from the above suggestions that follows: START (defun c:DxfToDwg ( / actDoc dxf-folder dxf-list oldFileDia oldCmdEcho oldExpert) (setq actDoc (vla-get-activedocument (vlax-get-acad-object))) (vl-load-com) (cond ((not (setq dxf-folder (_getfolder "Select folder with dxf files"))) (princ "\nNo folder selected")) ((not (vl-consp (setq dxf-list (_getfiles dxf-folder "*.dxf")))) (princ (strcat "\nNo dxf files in folder " dxf-folder))) (t ;; Save and suppress dialogs/echo for scripted operation (setq oldFileDia (getvar "FILEDIA")) (setq oldCmdEcho (getvar "CMDECHO")) (setq oldExpert (getvar "EXPERT")) (setvar "FILEDIA" 0) (setvar "CMDECHO" 0) (setvar "EXPERT" 2) (command ".undo" "mark") (foreach dxf dxf-list (command ".erase" "all" "") (vla-purgeall actDoc) (vl-cmdf "_.dxfin" dxf) ;; Imports into current (cleared) drawing (vla-ZoomExtents (vlax-get-acad-object)) ;; Save as DWG with explicit .dwg extension using ActiveX (reliable in BricsCAD) (setq dwgPath (strcat (vl-filename-directory dxf) "\\" (vl-filename-base dxf) ".dwg")) (vla-SaveAs actDoc dwgPath) ;; Saves in current DWG format; overwrites if exists ) (command ".undo" "back") ;; Restore system variables (setvar "FILEDIA" oldFileDia) (setvar "CMDECHO" oldCmdEcho) (setvar "EXPERT" oldExpert) ) ) (princ) ) ;; Helper functions (unchanged from original) (defun _getfolder ( m / f s) (if (and (setq s (vlax-create-object "Shell.Application")) (setq f (vlax-invoke s 'browseforfolder 0 m 65536 ""))) (setq f (vlax-get-property (vlax-get-property f 'self) 'path)) ) (vl-catch-all-apply 'vlax-release-object (list s)) (if f (vl-string-translate "\\" "/" f)) ) (defun void (x) (or (eq x nil) (and (listp x) (not (vl-consp x))) (and (eq 'STR (type x)) (eq "" (vl-string-trim " \t\r\n" x)))) ) (defun _getfiles ( fol ext / lst) (cond ((or (void fol) (not (vl-file-directory-p fol))) (princ (strcat "\nInvalid folder :" (vl-princ-to-string fol)))) (t (if (vl-consp (setq lst (vl-directory-files fol ext 1))) (setq lst (mapcar '(lambda (x) (strcat fol "/" x)) lst)) ) ) ) lst ) THANKS! I want to thank the original submitter of this post and to all the concerned experts here that take time to assist. NOTE I realize that AI can only take you so far. It does not replace learning and advancing my LISP programming skills nor does it replace the important nuances and logic that us as humans can detect and serves to perfect the code. I will test the above code and provide an update. Thanks, Clint Edited 21 hours ago by Clint Add closing comments and salutation Quote
troggarf Posted 13 hours ago Posted 13 hours ago There's an app for that: https://apps.autodesk.com/ACD/en/Detail/Index?id=3434696327413675915&appLang=en&os=Win32_64 1 Quote
Recommended Posts
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.