CAD Forums > CAD General
Scripting a method to close a DXF without Save As DWG dialog box
CJ:
Hello everyone,
I have created a LISP routine that exports a DXF but now I want to open that DXF and run another function. What I want is to strip all the Object Data/XData from the DXF before I send the files to client. I do not want to run this function in my working DWG.
Everything I have read says that scripting is my best choice to open other DWGs from a current DWG, do something, close and move onto the next DWG. I currently have a Test LISP file (zoom extents) that I can load via a script file and run successfully. I have gotten the save the DWF to work. My script is failing at the point where it closes.
It seems that whenever I try to CLOSE a DXF, AutoCAD demands that confirm I do not want to save my work as a DWG, twice! I have tried the Filedia 0 but it doesn't help. I cannot find a 'silent' or command-line version that by-passes this dialog box.
Any help with this scripting issues would be great.
dexus:
You can add this to your .scr file for closing the drawing:
--- Code - Auto/Visual Lisp: ---(command "_.close" "_Y")
57gmc:
As soon as you open the dxf, AutoCAD is going to convert it to a dwg. Don't re-open the dxf. Strip the object data from the dwg first, then export to dxf. This will leave the open dwg as a dxf. If you try to close now, you will be prompted to save as a dwg. Instead you can then close the dxf using
--- Code - Auto/Visual Lisp: ---(command "close" "n")
CJ:
Thanks dexus and 57gmc for your input. After many hours of banging my head and keyboard I got the script to run but now i am struggling with a new issue. It was opening the second drawing ( I had the first two DXFs open in AutoCAD) then I got the save function working and now for some reason it will not open the second drawing on the list.
Here is the code. The CZA.lsp is just a sample code for zoom extents. Batchfileslist is a list of DXFs files in a folder.
--- Code - Auto/Visual Lisp: ---(foreach n batchfileslist (progn (write-line (strcat "_.OPEN \"" (nth acount batchfileslist) "\"") f ) (write-line "(setvar 'SDI 1)" f) (write-line "filedia" f) (write-line "0" f) (write-line (strcat "(load " (chr 34) "cza.lsp" (chr 34) ")") f ) ; TESTING ONLY (write-line "(c:za)" f) ; TESTING ONLY (write-line (strcat "_.SAVEAS" " " "DXF" " " "Version" " " "LT2010" " " "16" " " " " "Yes" ) f ) (write-line "filedia" f) (write-line "1" f) (write-line "_.CLOSE" f) (write-line "No" f) (write-line "No" f) (write-line "(setvar 'SDI 0)" f) ) (setq acount (+ 1 acount)) )
Like I said before, the script can open the dxf file, do something to it and close it as a DXF. I probable have a small error somewhere that causing an error for opening the second.
edit Kerry: add code tags [code=cadlisp-7]
https://www.theswamp.org/index.php?topic=48309.0
57gmc:
You should post your code within code tags and use the lisp format.
In line 5 of the code below, shouldn't "account" be "n"?
--- Code - Auto/Visual Lisp: ---(foreach n batchfileslist (progn (write-line (strcat "_.OPEN \"" (nth acount batchfileslist) "\"") f )
Navigation
[0] Message Index
[#] Next page
Go to full version