Author Topic: Scripting a method to close a DXF without Save As DWG dialog box  (Read 629 times)

0 Members and 1 Guest are viewing this topic.

CJ

  • Mosquito
  • Posts: 9
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

  • Bull Frog
  • Posts: 207
Re: Scripting a method to close a DXF without Save As DWG dialog box
« Reply #1 on: March 12, 2024, 04:06:20 PM »
You can add this to your .scr file for closing the drawing:
Code - Auto/Visual Lisp: [Select]
  1. (command "_.close" "_Y")

57gmc

  • Bull Frog
  • Posts: 366
Re: Scripting a method to close a DXF without Save As DWG dialog box
« Reply #2 on: March 12, 2024, 06:53:38 PM »
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: [Select]
  1. (command "close" "n")

CJ

  • Mosquito
  • Posts: 9
Re: Scripting a method to close a DXF without Save As DWG dialog box
« Reply #3 on: March 14, 2024, 04:52:24 PM »
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: [Select]
  1. (foreach n batchfileslist
  2.  
  3.     (progn
  4.       (write-line
  5.         (strcat "_.OPEN \"" (nth acount batchfileslist) "\"")
  6.         f
  7.       )
  8.  
  9.       (write-line "(setvar 'SDI 1)" f)
  10.  
  11.       (write-line "filedia" f)
  12.  
  13.       (write-line "0" f)
  14.  
  15.       (write-line
  16.         (strcat "(load " (chr 34) "cza.lsp" (chr 34) ")")
  17.         f
  18.       )                                 ; TESTING ONLY
  19.  
  20.       (write-line "(c:za)" f)           ; TESTING ONLY
  21.  
  22.       (write-line
  23.         (strcat "_.SAVEAS"        " "      "DXF"    " "      "Version"
  24.                 " "      "LT2010" " "      "16"     " "      " "
  25.                 "Yes"
  26.                )
  27.         f
  28.       )
  29.  
  30.       (write-line "filedia" f)
  31.  
  32.       (write-line "1" f)
  33.  
  34.       (write-line "_.CLOSE" f)
  35.  
  36.       (write-line "No" f)
  37.  
  38.       (write-line "No" f)
  39.  
  40.       (write-line "(setvar 'SDI 0)" f)
  41.     )
  42.  
  43.     (setq acount (+ 1 acount))
  44.  
  45.   )

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
« Last Edit: March 14, 2024, 07:09:14 PM by kdub_nz »

57gmc

  • Bull Frog
  • Posts: 366
Re: Scripting a method to close a DXF without Save As DWG dialog box
« Reply #4 on: March 14, 2024, 04:59:16 PM »
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: [Select]
  1. (foreach n batchfileslist
  2.  
  3.     (progn
  4.       (write-line
  5.    (strcat "_.OPEN \"" (nth acount batchfileslist) "\"")
  6.    f
  7.       )
« Last Edit: March 14, 2024, 05:05:45 PM by 57gmc »

CJ

  • Mosquito
  • Posts: 9
Re: Scripting a method to close a DXF without Save As DWG dialog box
« Reply #5 on: March 14, 2024, 07:06:20 PM »
acount is established before the the FOREACH section.

This is the whole code:

Code - Auto/Visual Lisp: [Select]
  1.  
  2. (defun c:t4 (/ batchdirectory batchfileslist l)
  3.  
  4.  
  5.   ;;get files list from folder
  6.  
  7.   (listfiles)
  8.  
  9.   (setq batchfileslist dxfList)
  10.  
  11. ;;;                         TESTING ONLY                                   ;;;
  12.   (setq flag 4)
  13.  
  14.   (vla-GetCustomByIndex
  15.     (setq customInfo
  16.            (vla-get-SummaryInfo
  17.            )
  18.     )
  19.     8
  20.     'Province
  21.     'Prov
  22.   )
  23.  
  24.   (GetFolderLocation)
  25.  
  26.   (setq FullnameFolderFile fullname)
  27.  
  28.   (cond ((= PROV "SK")
  29.          (setq FullnameFolderFile
  30.                 (strcat FullnameFolderFile " (FACILITIES)" ".dxf")
  31.          )
  32.         )
  33.         ((= PROV "MB")
  34.          (setq FullnameFolderFile
  35.                 (strcat FullnameFolderFile " (FACILITIES)" ".dxf")
  36.          )
  37.         )
  38.         (T nil)
  39.   )
  40.  
  41. ;;;                         TESTING ONLY                                   ;;;
  42.  
  43.  
  44.  
  45.   (setq acount 0)
  46.  
  47.   (setq tempscript (strcat (getvar "TEMPPREFIX") "tempbatchscrpt.scr")) ; Create and open script file
  48.  
  49.   (setq f (open tempscript "w")) ; open file
  50.  
  51.   (foreach n batchfileslist
  52.  
  53.     (progn
  54.       (write-line
  55.         (strcat "_.OPEN \"" (nth acount batchfileslist) "\"")
  56.         f
  57.       )
  58.  
  59.       (write-line "(setvar 'SDI 1)" f)
  60.  
  61.       (write-line "filedia" f)
  62.  
  63.       (write-line "0" f)
  64.  
  65.       (write-line
  66.         (strcat "(load " (chr 34) "cza.lsp" (chr 34) ")")
  67.         f
  68.       )                                 ; TESTING ONLY
  69.  
  70.       (write-line "(c:za)" f)           ; TESTING ONLY
  71.  
  72.       (write-line
  73.         (strcat "_.SAVEAS"        " "      "DXF"    " "      "Version"
  74.                 " "      "LT2010" " "      "16"     " "      " "
  75.                 "Yes"
  76.                )
  77.         f
  78.       )
  79.  
  80.       (write-line "filedia" f)
  81.  
  82.       (write-line "1" f)
  83.  
  84.       (write-line "_.CLOSE" f)
  85.  
  86.       (write-line "No" f)
  87.  
  88.       (write-line "No" f)
  89.  
  90.       (write-line "(setvar 'SDI 0)" f)
  91.     )
  92.  
  93.     (setq acount (+ 1 acount))
  94.  
  95.   )
  96.  
  97.   (close f)
  98.  
  99.   (command "_.SCRIPT" tempscript) ; run script
  100. )

57gmc

  • Bull Frog
  • Posts: 366
Re: Scripting a method to close a DXF without Save As DWG dialog box
« Reply #6 on: March 14, 2024, 07:23:54 PM »
I would just use "n" instead of "(nth acount batchfileslist)", as it is already evaluated and available. Calling it "n" might mislead you to think its a number, but its just an element in the list, the same as returned by "(nth n list)". I assume that n should be a valid filepath.