Danielm103 Posted Sunday at 11:16 AM Posted Sunday at 11:16 AM (edited) 31 minutes ago, SLW210 said: What was wrong with rlx's? According to the ARX docs using dxfIn Quote This function should be used only on a newly created AcDbDatabase that was created with its constructor's buildDefaultDrawing argument set to Adesk::kFalse. If this method is used on an AcDbDatabase created with buildDefaultDrawing set to Adesk::kTrue or an AcDbDatabase that already has information in it (for any reason including a previous call to this method), then memory leaks or possibly fatal errors will result. While rlx’s version attempts to clean the drawing via vla-purgeall, I suppose there could be some items that are not purged? It’s not clear what happens in case of an existing dictionary or style. AI “AutoCAD typically handles conflicts by prioritizing the current drawing's definitions” I'm guessing that rlx’s version is safe enough though Edited Sunday at 11:19 AM by Danielm103 1 Quote
rlx Posted Sunday at 11:55 AM Posted Sunday at 11:55 AM The reason I clean the drawing is I once wrote a program to generate instrument loop diagrams from an excel file. I found the most stable and easy way was not to use a script but stay in the current drawing and from there save(as) each loop. I also made use from templates and also had the option to update the drawing in stead of generating the entire drawing. But at some time some templates had been given an update to a block definition and to be certain the latest version was used I had to make sure the old block was purged. Overkill , some times yes , but in my case it worked as it should. In this case , dxfin , probably overkill , but it doesn't hurt either. I tested it on Bricad 22 and the dwg extension was no problem, it worked as it should. The recommendation from the annoying paperclip oh , sorry , AI its called these days , to pimp the filename and use vla-saveas is not wrong though. Just didn't need it on my computer. Had it gave me an error I would have fixed it but it worked right from the start for me. 2 1 Quote
Clint Posted Sunday at 01:23 PM Posted Sunday at 01:23 PM 16 hours ago, troggarf said: There's an app for that: https://apps.autodesk.com/ACD/en/Detail/Index?id=3434696327413675915&appLang=en&os=Win32_64 Hi troggarf, We use BricsCAD. I thank you, sir! Clint Quote
Clint Posted Sunday at 01:28 PM Posted Sunday at 01:28 PM On 1/3/2026 at 6:47 AM, Clint said: 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 The promised update The version above works but with one exception: It only places the converted (DWG) files in the source (DXF) file folder according to the code, of course. It works for me. Thanks, Clint Quote
Clint Posted Sunday at 01:31 PM Posted Sunday at 01:31 PM On 12/18/2023 at 6:31 PM, BIGAL said: 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 ? Hi BIGAL, Of course, an elegantly simple and effective solution is presented here. This nugget is being stored and will come in handy for related batch scripting. Thanks, Clint Quote
Clint Posted Sunday at 02:06 PM Posted Sunday at 02:06 PM 1 hour ago, rlx said: The reason I clean the drawing is I once wrote a program to generate instrument loop diagrams from an excel file. I found the most stable and easy way was not to use a script but stay in the current drawing and from there save(as) each loop. I also made use from templates and also had the option to update the drawing in stead of generating the entire drawing. But at some time some templates had been given an update to a block definition and to be certain the latest version was used I had to make sure the old block was purged. Overkill , some times yes , but in my case it worked as it should. In this case , dxfin , probably overkill , but it doesn't hurt either. I tested it on Bricad 22 and the dwg extension was no problem, it worked as it should. The recommendation from the annoying paperclip oh , sorry , AI its called these days , to pimp the filename and use vla-saveas is not wrong though. Just didn't need it on my computer. Had it gave me an error I would have fixed it but it worked right from the start for me. Hi rlx, The Excel-based automated gem you coded would have certainly minimized the extremely mundane diagram-based tasks and would have been handy in what is one half (15 years) of my overall drafting design career sentence within the chemical processing industry * using mainly AutoCAD, other Autodesk-based products, plus a few of the last years there in BricsCAD. I appreciate your explanation on the program's purpose and your particular career experience. I find it very interesting how functionality changed in BricsCAD between your V22 used and the BricsCAD V25 used that caused the lack of an expected file conversion outcome. I am slowly weaning myself off the AI crutch that can never replace real personal experience and direct application from learning programming languages. Thanks, Clint Footnote (*) My interests now lie in CAD programming that I wish I had started years ago as I am now working in the pre-engineered metal building design/manufacturing position that is much more in line with my formal education, personal interest, and work in mechanical and structural design departments that make up half of my 30+ years of design drafting experience. Quote
Clint Posted Sunday at 02:10 PM Posted Sunday at 02:10 PM 3 hours ago, Danielm103 said: if you can use Python import traceback from pyrx import Ap, Db, Ed, Ge @Ap.Command() def dxftodwg(): try: for dxf in Ap.Application.listFilesInPath("E:\\FloorPlans", ".dxf"): dwg = dxf.replace(".dxf", ".dwg") db = Db.Database(False, True) db.dxfIn(dxf) db.saveAs(dwg) print(dxf, dwg) except Exception as err: traceback.print_exception(err) Hi Danielm 103, Yes, Python is a distinct possibility. Has Python-based programs replaced LISP-based programming in your current experience. Why or why not? Thanks, Clint Quote
Steven P Posted Sunday at 08:00 PM Posted Sunday at 08:00 PM 6 hours ago, Clint said: The promised update The version above works but with one exception: It only places the converted (DWG) files in the source (DXF) file folder according to the code, of course. It works for me. Thanks, Clint For most things I do this is my default option, rarely need to do much other than that and if I do, drag and drop. 1 1 Quote
Danielm103 Posted Sunday at 09:05 PM Posted Sunday at 09:05 PM 6 hours ago, Clint said: Hi Danielm 103, Yes, Python is a distinct possibility. Has Python-based programs replaced LISP-based programming in your current experience. Why or why not? Thanks, Clint It’s more of, ‘pick the right tool for the right job’. In this case, ObjectARX, and by extension, Python, can provide a clean new drawing to import your DXFs into every time, whereas lisp may not. I don’t remember what all is stored in DXF, i.e. if there are things that are non-purgeable. An example is an existing text, dimension, or table style, that are named “Standard”. Nested references, Associated Styles (the text style for a dimension style). There may be user variables stored per drawing CLAYER, LTSCALE: So, using lisp DXFIN -> purge -> save on repeat may have subtle side effects. This may or may not be an issue for you 1 Quote
BIGAL Posted Sunday at 09:30 PM Posted Sunday at 09:30 PM What programming language to use ? There are so many, Lisp, Pascal, VBA, C##, now .NET, Python and of course the push product by Autodesk Dynamo but only on certain platforms. Yeah the macro record almost useless. As I have said before years ago macro record in a CAD program wrote VBA code. There is lisp2C from years ago that converted lisp code to C## code, hey Daniel what about convert lisp to Python ? The main advantage in lisp is the non compile, just run, I use code that is 30+ years old still works. Any compiled code every few years has to be recompiled to work as versions change. Dont forget how many years ago now Autodesk said VBA support would be removed, it's still there. 1 Quote
rlx Posted Sunday at 11:10 PM Posted Sunday at 11:10 PM Even if I wanted to use a different language I wouldn't be able because at my work I'm unable to install any software that's not supplied in our software center , also certain extensions like *.bat are a big freaking no no so my dragon claws are tied in that respect. But I can get vl-some satisfaction however whenever I can create something that at first glance seems impossible to do and then come up with something that actually works. 1 Quote
Danielm103 Posted Monday at 12:26 AM Posted Monday at 12:26 AM 1 hour ago, rlx said: Even if I wanted to use a different language I wouldn't be able because at my work I'm unable to install any software that's not supplied in our software center , also certain extensions like *.bat are a big freaking no no so my dragon claws are tied in that respect. But I can get vl-some satisfaction however whenever I can create something that at first glance seems impossible to do and then come up with something that actually works. Yikes! Working with your arms tied.. No way I could work effectively without my tools, I would at least need autohotkey. Last company I worked for, I automated their whole system, mostly because I was lazy and I wanted to eat donuts all day. AutoCAD ships with .NET, nothing to install, I would be rolling some goodies for sure. “We At ACME corporation stifle innovation by making everyone think inside the box” 2 Quote
rlx Posted Monday at 12:46 AM Posted Monday at 12:46 AM Their IT department even has a slogan (and I'm not kidding here) : You name it , we block it 3 1 Quote
Clint Posted Monday at 12:48 PM Posted Monday at 12:48 PM I'll this topic a "wrap" Thanks to all here! rlx: I also have worked at my last company of fifteen years within a very locked down IT environment. Here and now, I am free! One caveat here is that there are limitations in acquiring additional Microsoft tools i.e., Power Platform tools, etc. due to the complexity introduced from being a client of an widely known commercial web hosting service. Happy, happy, happy! Clint 3 Quote
SLW210 Posted 16 hours ago Posted 16 hours ago On 1/4/2026 at 7:26 PM, Danielm103 said: Yikes! Working with your arms tied.. No way I could work effectively without my tools, I would at least need autohotkey. Last company I worked for, I automated their whole system, mostly because I was lazy and I wanted to eat donuts all day. AutoCAD ships with .NET, nothing to install, I would be rolling some goodies for sure. “We At ACME corporation stifle innovation by making everyone think inside the box” You would still need Visual Studio or similar and packages installed. Even for Visual Studio Code and LISP, I get PowerShell errors due to IT blocking it as well as the need to download the extension. Main issue is just lazy IT departments not wanting to due proper security, every issue I have had a work shows "improper server configuration" and/or "improper firewall configuration" when searching the issue. Anyone using Autodesk products (maybe other programs as well) has to manually override the proxy server on each restart of their computer or we have licensing issues. I had to to do all of the leg work on getting that issue resolved. Unfortunately that's just how many IT "professionals" are trained, "when in doubt, block it out". I normally don't have issues getting programs installed, just usually they are in no hurry to get it done. Autodesk is partly to blame, should be a better way to get apps, add-ons, etc. than needing an IT install. Even Microsoft, why do I need to update Windows and MS Office tools separately and need IT to allow use of PowerShell? To be honest though, I am just the AutoCAD guy, so they don't understand how programming with other tools is relevant. 1 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.