Author Topic: Script File for Operations in Multiple DXF Files  (Read 529 times)

0 Members and 1 Guest are viewing this topic.

CEHill

  • Newt
  • Posts: 25
Script File for Operations in Multiple DXF Files
« on: July 22, 2024, 12:04:33 PM »
While there are beaucoup amounts of DWG-based scripts, my current task is to process several DXFs - purging 3 times in each file and saving.
I also use Lee Mac's Script Writer application to simplify coding the script as his application uses a generic *file* function(?) so coding specific files names is unnecessary.

Excluding the Script Writer function, below (and in the attached file as well ) is the simple task that I am trying to perform:
 
Code - Auto/Visual Lisp: [Select]
  1. _.open *file*
  2. _-Purge All * No
  3. _-Purge All * No
  4. _-Purge All * No
  5. _.save
  6. _.close *file*

I humbly ask for a bit of guidance to launch this otherwise 'lead balloon'.

Yours,

Clint
« Last Edit: July 22, 2024, 12:11:01 PM by CEHill »

Lonnie

  • Newt
  • Posts: 200
Re: Script File for Operations in Multiple DXF Files
« Reply #1 on: July 22, 2024, 03:38:11 PM »
Not tried it but

Perhaps try something like this.

Script.

_.open *file* (c:foo)  _.close

and this as your lisp.

Code: [Select]
;; AutoLISP Routine: Save Drawing as DXF
;; Author: [Your Name]
;; Description: This routine purges the current drawing and saves it as a DXF file.
;;
;; Acknowledgments:
;; Thanks to The Swamp community for their help and guidance.
;; Reference: https://www.theswamp.org/index.php?topic=59688.msg621602#msg621602
;;
;; Usage: Type FOO at the command line to execute the routine.

(defun c:foo ()
  ;; Function to purge the active document
  (defun lm:prg ()
    (if (= 1 (getvar 'dwgtitled))  ; Check if the drawing is titled
      (progn
        (setq doc (vla-get-activedocument (vlax-get-acad-object)))  ; Get the active document
        (repeat 3 (vla-purgeall doc))  ; Purge the document three times
      )
    )
  )

  ;; Function to save the drawing as a DXF file
  (defun lm:SaveAsDXF ()
    (setq original-filedia (getvar 'filedia))  ; Save the current FILEDIA setting
    (setvar 'filedia 0)  ; Set FILEDIA to 0 to suppress dialog boxes
    (setq current-filename (getvar 'dwgname))  ; Get the current drawing name
    (setq dxf-filename (strcat (vl-filename-base current-filename) ".dxf"))  ; Create the DXF filename
    (command "_.SAVE" "DXF" "16" dxf-filename)  ; Save the file as a DXF
    (setvar 'filedia original-filedia)  ; Restore the original FILEDIA setting
    (princ (strcat "File saved as DXF: " dxf-filename "\n"))  ; Print a message to the command line
  )

  (lm:prg)  ; Call the purge function
  (lm:SaveAsDXF)  ; Call the save as DXF function
  (princ)  ; Exit quietly
)



« Last Edit: July 22, 2024, 03:43:17 PM by Lonnie »

CEHill

  • Newt
  • Posts: 25
Re: Script File for Operations in Multiple DXF Files
« Reply #2 on: July 22, 2024, 03:52:58 PM »

Hi Lonnie,

The LISP program is very welcome.

I see this script code formatting is used in the excellent Script Writer application by the legendary Lee Mac that I have installed.

So, reading a thread by you about the removal of all LMAC_ prefixed config file types in the ROAMABLEROOTPREFIX location, I did just that.

Currently, I am a loss as to what to replace it with!
What is your recommendation on the contents and the file name for a replacement for the default config file(s) used by the Script Writer application?

Regards,

C.

Lonnie

  • Newt
  • Posts: 200
Re: Script File for Operations in Multiple DXF Files
« Reply #3 on: July 22, 2024, 03:54:14 PM »
On a side note.
"https://www.theswamp.org/index.php?topic=59553.msg620876#msg620876"
showed me where Lee puts his config files in case you really messup. I was able to go into the LMAC_WScript_V1.2.cfg file and type my pathing in to use UNC pathing. It was a real help to me.

CEHill

  • Newt
  • Posts: 25
Re: Script File for Operations in Multiple DXF Files
« Reply #4 on: July 22, 2024, 03:57:46 PM »
I see. I am going to install a fresh copy of Script Writer and adjust the specified support file you mention.

Thanks,
C.

Lonnie

  • Newt
  • Posts: 200
Re: Script File for Operations in Multiple DXF Files
« Reply #5 on: July 22, 2024, 04:06:49 PM »
You should be able to add

_.open *file* (c:foo)  _.close

through the dialog box and save the script that way. I only mentioned the ROAMABLEROOTPREFIX in case you needed to nuke your stuff.
LMAC_WScript_V1.2.cfg is where all that info is kept.

type
(getvar 'ROAMABLEROOTPREFIX)
and you'll see where it puts it. just remove the extra "\"s
« Last Edit: July 22, 2024, 04:22:10 PM by Lonnie »

CEHill

  • Newt
  • Posts: 25
Re: Script File for Operations in Multiple DXF Files
« Reply #6 on: July 22, 2024, 04:28:48 PM »
The UNC path to the folder where the files to be processed reside. Correct? I apologize for the lengthy discourse.

An earlier email reply from Lee Mac containing related questions included several questions from him that implied I simply specify the aforementioned folder. Also, the script will be a single-line code due to the data field.

I will test using the LISP you included.
It will be interesting.
 :whistling:

Thanks a million for your help today, sir!

CEHill

  • Newt
  • Posts: 25
Re: Script File for Operations in Multiple DXF Files
« Reply #7 on: July 22, 2024, 04:47:13 PM »
The ROAMABLEROOTPREFIX displays at the command line when Script Writer is invoked.
"C:\\Users\\CEH\\AppData\\Roaming\\Bricsys\\BricsCAD\\V24x64\\en_US\\"

UNC PATH: What path is needed by the program to actually process the DXF files?

My LMAC_WScript_V1.2.cfg file contains the following code: where the folder of DXF files reside.

Code - Auto/Visual Lisp: [Select]
  1. "_.open *file* (c:foo)  _.close"
  2. "C:\\Users\\CEH\\Desktop\\Publish Issues\\Test 1 Copy 24-11825_ Framing Shop (SE Detailed... HW-1 Only Print)"
  3. "0"
  4. nil

I am not sure what I am missing. IT HAS TO BE SIMPLE!

Lonnie

  • Newt
  • Posts: 200
Re: Script File for Operations in Multiple DXF Files
« Reply #8 on: July 22, 2024, 05:16:13 PM »
Sorry
Bringing up that other thread was probably a mistake.
It looks like your using drive letters so you can simply browse to your folder. No reason at all to edit the cfg file.

That script assumes you can run the lisp in each newly opened file.
Can you type foo in a newly opened file and have it run?

In addition, does the lisp run the way you expect?  Does it do the purge and the save to dxf like you expect? If so it should work.

If the lsp file is not loading in each new file try this.
copy this

Code: [Select]
(defun lm:prg ()
(if (= 1 (getvar 'dwgtitled))
    (progn
        (setq doc (vla-get-activedocument (vlax-get-acad-object)))
        (repeat 3 (vla-purgeall doc))
    )
)
)

(defun lm:SaveAsDXF ()
  (setq original-filedia (getvar 'filedia))  ; Save the current filedia setting
  (setvar 'filedia 0)                        ; Set filedia to 0 to suppress dialog boxes
  (setq current-filename (getvar 'dwgname))  ; Get the current drawing name
  (setq dxf-filename (strcat (vl-filename-base current-filename) ".dxf")) ; Create the DXF filename based on the current drawing name
  (command "_.SAVE" "DXF" "16" dxf-filename) ; Save the file as a DXF
  (setvar 'filedia original-filedia)         ; Restore the original filedia setting
  (princ (strcat "File saved as DXF: " dxf-filename "\n")) ; Print a message to the command line
)

(lm:prg)
(lm:SaveAsDXF)


lisp to
"C:\Users\CEH\Desktop\Publish Issues"

Name it to purgesave.lsp
Type
(load "C:\\Users\\CEH\\Desktop\\Publish Issues\\purgesave.lsp") at a command prompt.
tell autocad to always load this file.

Change the script to the following

_.open *file* (load "C:\\Users\\CEH\\Desktop\\Publish Issues\\purgesave.lsp") _.close


Once again nothing was really tested.

1. The new lisp will run on the load command so there is no need to add it to your autocad.
and
2. make sure the lsp does what you want. I really did not test it well.



« Last Edit: July 23, 2024, 04:03:46 PM by Lonnie »

CEHill

  • Newt
  • Posts: 25
Re: Script File for Operations in Multiple DXF Files
« Reply #9 on: July 23, 2024, 07:36:01 AM »
Your help is really overwhelmingly gracious and very welcome. Thanks a bunch!

I will follow your suggestions and test your code.
Yes, I am at the shallow end of the CAD customization pool and wearing floatie wings as well.

My aim is to update you with positive news!

P.S.: If I had known DWG and LISP would not die as predicted and I would be working in a DWG-based environment I would have focused on LISP-based programming mastery many years ago.

Thanks,
Clint

CEHill

  • Newt
  • Posts: 25
Re: Script File for Operations in Multiple DXF Files
« Reply #10 on: July 23, 2024, 11:20:36 AM »
Hello again Lonnie,

SUMMARY
An error occurred in the FOO program relating to the file version code syntax. See the attached screenshot.

BACKGROUND
I use BricsCAD and, more importantly, due to a critical dependency posed by our primary design software, MBS, the R11/12 ASCII DXF file format must be generated.

SPECIFIC ISSUE
The error is related to the file format code syntax peculiar to BricsCAD
In BricsCAD, there is a numeral that applies to each file format (SAVEFORMAT variable) with '1' being the 2018 DWG file.
The R11/12 ASCII DXF file format is represented by '26'.

With this correction, it appears the remainder of the FOO program works as designed!

Let me know if further explanation is required.
Thanks for all of your help so far. If you reached your limit, it is perfectly fine!

Clint