pyou Posted 32 minutes ago Posted 32 minutes ago (edited) Hi all Could someone help me with this lisp code, please. What I would like : 1) PUBLISH first as pdf ( with existing settings used) and Pause until PUBLISH finished. 2) Delete all Paper spaces and create Default Layout1 3) Purge drawing twice 3) Save as DXF Binary 2007 file. So far I am getting results i need to delete all paper spaces and create default layout1, Purge and saving as dxf Binary 2007 file automatically. Ideally I just want user friendly lisp code to publish pdf on desktop and save smallest file possible as dxf on desktop. (defun c:CleanAndSaveDXF ( / doc lays desktop dwgname fullpath Layout1Obj oldCmdecho ) ;; Save and turn off command echoing (setq oldCmdecho (getvar "CMDECHO")) (setvar "CMDECHO" 0) ;; 1) Keep/create exactly one "Layout1", delete everything else (setq doc (vla-get-ActiveDocument (vlax-get-acad-object)) lays (vla-get-Layouts doc) Layout1Obj nil) (vlax-for lay lays (cond ( (= (vla-get-Name lay) "Model") ) ( (= (strcase (vla-get-Name lay)) "LAYOUT1") (setq Layout1Obj lay) ) ( t (vl-catch-all-apply 'vla-Delete (list lay)) ) ) ) (or Layout1Obj (vla-Add lays "Layout1")) (vla-put-ActiveLayout doc (vla-Item lays "Model")) ;; 2) Ultra-purge (repeat 6 (command "-PURGE" "All" "*" "N")) (command "-PURGE" "Regapps" "*" "N") (command "-PURGE" "Z" "*" "N") (command "-PURGE" "E" "*" "N") ;; 3) Build exact filename (same base name, pure .dxf) (setq desktop (strcat (getenv "USERPROFILE") "\\Desktop\\")) (setq dwgname (vl-filename-base (getvar "DWGNAME"))) (if (or (null dwgname) (= dwgname "")) (setq dwgname "Drawing")) (setq fullpath (strcat desktop dwgname ".dxf")) ;; 4) Remove any existing file (including .dxf.dwg garbage) (foreach ext (list fullpath (strcat fullpath ".dwg")) (if (findfile ext) (vl-file-delete ext)) ) ;; 5) Export as BINARY 2007 DXF (command "._EXPORT" fullpath "2007" "B") ;; 6) One final purge (repeat 2 (command "-PURGE" "All" "*" "N")) ;; === NEW: Run the whole thing ONE MORE TIME automatically === (if (= (getvar "USERI1") 0) ; first run → marker = 0 (progn (setvar "USERI1" 1) ; mark that we are now on the second run (princ "\n--- Running second (final) pass for maximum cleanliness ---\n") (c:CleanAndSaveDXF) ; ← recursive call – runs again immediately (setvar "USERI1" 0) ; reset marker for next time you use the command ) ) ;; Restore original CMDECHO (only on the very last exit) (setvar "CMDECHO" oldCmdecho) (princ (strcat "\nClean BINARY DXF (2007) created → " fullpath "\n")) (princ) ) Edited 30 minutes ago by pyou 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.