Need help creating a LISP

Need help creating a LISP

Markeckert
Enthusiast Enthusiast
2,107 Views
45 Replies
Message 1 of 46

Need help creating a LISP

Markeckert
Enthusiast
Enthusiast
I need to write a lisp that will perform the following. I'm somewhat of a newbie to LISPs so any help would be greatly appreciated. Here is what the LISP needs to perform.
  1. Starting from an open DWG file in AutoCAD2024 the LISP should open the rest of the dwg files that are in the same folder.
  2. Apply predefined Plot Offset properties (Which I will add to the code) to each of the dwg files open. It should also save the properties in the dwg files.
  3. Run the AutoCAD publishing process utilizing Adobe Acrobat Pro to create a single pdf containing all the dwg files as pages in the PDF.    Thanks for the help.
0 Likes
2,108 Views
45 Replies
Replies (45)
Message 2 of 46

Moshe-A
Mentor
Mentor

@Markeckert  hi,

 

You need to give us a little more info

1. a preview of the final state. depending on the quantity of files how they will be laid? 

    array of 2x2 / 3x3 / 4x4?

2. zip this sample folder contains some drawings and post it

2. plot scale?

 

Moshe

 

0 Likes
Message 3 of 46

Markeckert
Enthusiast
Enthusiast

Moshe, I've attached a screen shot of the PDF that should be created by the LISP. It would have page for each of the dwg files that are input to the Lisp. I've also attached two sample DWG files. I've also attached an image of the Plot Scale. 

Markeckert_0-1765816248257.png

 

0 Likes
Message 4 of 46

Moshe-A
Mentor
Mentor

@Markeckert ,

 

After exploring this i think you better move this to VBA forum (or .net) cause they have better tools to run publish.

 

Moshe

 

0 Likes
Message 5 of 46

Markeckert
Enthusiast
Enthusiast

Moshe, Would you be able to create a Lisp that would perform the first 2 steps? That might be enough for my user to utilize. 

0 Likes
Message 6 of 46

Sea-Haven
Mentor
Mentor

1st comment no need to open dwg's if using publish. Yes can make a list of all dwgs in current directory. You can write a DSD file that is used by publish. Example code and method can be found here. That should do what you want.

 

I don't use publish rather use plot lisps, not sure if Aecoreconsole supports plot. So could plot the pdf's without opening dwg, then I use ghostscript via lisp to join back into a single pdf file. I would do a script and call the plot lisp.

 

Have a go at making the DSD.

0 Likes
Message 7 of 46

Moshe-A
Mentor
Mentor

@Markeckert ,

 

While you wait here for solution explore SheetSet Manager, it is a comprehensive tool to manage sheets and publish to pdf/dwfx

 

Moshe

 

0 Likes
Message 8 of 46

Markeckert
Enthusiast
Enthusiast

Sea-Haven, I appreciate your suggestions but I'm unfamiliar with DSD, Ghostscript and  Aecoreconsole. I was hoping to get some of the script written for me. I can probably modify the script once I have the basic process coded. 

0 Likes
Message 9 of 46

Moshe-A
Mentor
Mentor

@Markeckert  hi,

 

check this IDwgFldr command.

 

it insert each dwg page\sheet organizing them in an array with a little offset you can specify at run time.

the number of sheets in row is 5 (that's fills 44"). by setting a new value to ITEMS->ROW you can change it.

after the insert done, you will be asked for Plot. i use "DWG to PDF.pc3" , you can change it but be aware that

changing the device may require a change in (command "-plot" ...) arguments.

 

enjoy

Moshe

 

 

; IDwgFldr.lsp
; by Moshe-A
; DEC 16, 2025

; Import Drawing Folder

(defun c:IDwgFldr (/ initial chop_extension askreal askYesNo 					; local functions
		     savAttdia savAttreq DICTAPPNAME xdef ydef X-SHEET Y-SHEET ITEMS->ROW 	; local variables
		     path xofset yofset files^ base p0 i j name  Xmax Ymax plotLL plotUR)	; local variables

 (defun initial ()
  (setq DICTAPPNAME "IDwgFldrlsp-by-Moshe-A-DEC2025")
  (setq xdef (vlax-ldata-get DICTAPPNAME "Xofset" 0.5))
  (setq ydef (vlax-ldata-get DICTAPPNAME "Yofset" 0.5))
  
  ; some constat
  (setq X-SHEET  8.5)
  (SETQ Y-SHEET 11.0)
  (setq ITEMS->ROW 5) ; number item in a row
 ); initial
  
  
 (defun chop_extension (s / p)
  (if (setq p (vl-string-search "." s))
   (substr s 1 p)
  )
 ); chop_extension


 (defun askreal (msg def / ask)
  (initget (+ 2 4))
  (if (not (setq ask (getreal (strcat "\n" msg " <" (rtos def) ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); askreal


 (defun askYesNo (msg def / ask)
  (initget "Yes No")
  (if (not (setq ask (getkword (strcat "\n" msg " <" def ">: "))))
   (setq ask def)
   (setq def ask)
  )
 ); askYesNo 


 ; here start c:IDwgFldr
 (setvar "cmdecho" 0)
 (command "._undo" "_begin")

 (setq savAttdia (getvar "attdia"))
 (setvar "attdia" 0)

 (setq savAttreq (getvar "attreq"))
 (setvar "attreq" 0)

 (initial) ; set some constats
  
 (if (and
       (setq path  (acet-ui-pickdir "Pick a folder:" (getvar "dwgprefix") "Import Drawing Folder"))
       (setq xofset (askreal "X-Offset" xdef))
       (setq yofset (askreal "Y-Offset" ydef))
     )
  (progn
   (cond
    ((not (setq files^ (vl-directory-files path "*.dwg" 1)))
     (vlr-beep-reaction)
     (prompt "\nNo drawing files found in selected folder.")
    ); case
    ((not (setq base (getpoint "\nStart point: "))))
    ( t
     (setq files^ (mapcar (function (lambda (s) (chop_extension s))) files^))
     (setq plotLL (list (- (car base) xofset) (- (cadr base) yofset)))
     (setq plotUR '(0.0 0.0))
     
     (setq i 0 j 0)
     (while (nth (+ (* i ITEMS->ROW) j) files^)
      (while (and
	       (nth (+ (* i ITEMS->ROW) j) files^)
	       (< j ITEMS->ROW)
             )
       (setq name (nth (+ (* i ITEMS->ROW) j) files^))
       (setq p0 (list (+ (car base) (* j (+ X-SHEET xofset))) (+ (cadr base) (* i (+ Y-SHEET yofset)))))
       (command "._insert" (strcat path "\\" name) "_None" p0 1 1 0)
       (setq j (1+ j))
      ); while

      (setq Xmax (+ (car  p0) (* j (+ X-SHEET xofset))))
      (setq Ymax (+ (cadr p0) (* i (+ Y-SHEET yofset))))
       
      (setq j 0) 	; reset colums
      (setq i (1+ i))	; inc rows
     ); while

     (if (< (car plotUR) Xmax)
      (setq plotUR (list Xmax (cadr plotUR)))
     )

     (if (< (cadr plotUR) Ymax)
      (setq plotUR (list (car plotUR) Ymax))
     )
      
    ); case
   );cond

   (vlax-ldata-put DICTAPPNAME "Xofset" xofset)
   (vlax-ldata-put DICTAPPNAME "Yofset" yofset)

   (if (eq (askYesNo "Plot to PDF?" "Yes") "Yes")
    (progn
     (setvar "expert" 5)
     (command ".-plot" "_Yes" "" "DWG To PDF.pc3" "ANSI full bleed E (34.00 x 44.00 Inches)" "_Inches" "_Landscape"
	      "_No" "_Window" plotLL plotUR "1=1" "0,0" "_Yes" "acad.ctb" "_Yes" "" "" "_Yes" "_Yes")
     (setvar "expert" 0)
    ); progn
   ); if
   
  ); progn
 );if 

 (setvar "attreq" savAttreq)
 (setvar "attdia" savAttdia)
  
 (command "._undo" "_end")
 (setvar "cmdecho" 1)
  
 (princ)
); c:IDwgFldr

 

 

0 Likes
Message 10 of 46

Markeckert
Enthusiast
Enthusiast

Hi Moshe, Thanks for putting this together. I'm getting an error when I just hit enter for the Start Point but I don't get the error if I click in a spot on the AutoCAD canvas for the Start Point. Can you remove the prompt for the Start Point?  My user does not want to make that selection. I've pasted the error messaged below. 

X-Offset <.5>:
Y-Offset <.5>:
Start point:
Plot to PDF? <Yes>: yes
Unknown command "1=1". Press F1 for help.
Unknown command "0,0". Press F1 for help.
Unknown command "YES". Press F1 for help.
Unknown command "CTB". Press F1 for help.
Unknown command "YES". Press F1 for help.
Unknown command "IDWG". Press F1 for help.
Unknown command "IDWG". Press F1 for help.
Unknown command "YES". Press F1 for help.
Unknown command "YES". Press F1 for help.

0 Likes
Message 11 of 46

Sea-Haven
Mentor
Mentor

Nice idea @Moshe-A, would use a Xref be better then can edit the original dwg's and just update current dwg re plot and up to date.

0 Likes
Message 12 of 46

Moshe-A
Mentor
Mentor

@Markeckert  hi,

 

after the insert done, you will be asked for Plot. i use "DWG to PDF.pc3" , you can change it but be aware that

changing the device may require a change in (command "-plot" ...) arguments.

 

Have you read the above?

Do you have "DWG to PDF.pc3" device?

Did you change it to "Adobe Acrobat Pro.pc3"?

and if you did, did you update plot arguments appropriately - do you know how to do that?

 

Moshe

 

 

0 Likes
Message 13 of 46

Moshe-A
Mentor
Mentor

@Sea-Haven ,

 

thanks mate 😀

0 Likes
Message 14 of 46

Markeckert
Enthusiast
Enthusiast

I do have a DWG to PDF.pc3 device and I have left the lisp set to "DWG to PDF.pc3" but I'm getting the errors mentioned above.

0 Likes
Message 15 of 46

Moshe-A
Mentor
Mentor

@Markeckert ,

 

made some changes but not to the issue with plot to pdf, what is the autocad version you are using?

Start Point?  My user does not want to make that selection?

the sheets array must start somewhere

 

Moshe

0 Likes
Message 16 of 46

Markeckert
Enthusiast
Enthusiast

Hi Moshe, I'm getting this error when it gets to the plot.

Markeckert_0-1766084552884.png

 

0 Likes
Message 17 of 46

Moshe-A
Mentor
Mentor

@Markeckert ,

 

1. Are aware background plotting is enabled?

2. Modify the lisp, try again.

 

Moshe

 

0 Likes
Message 18 of 46

Markeckert
Enthusiast
Enthusiast

I forgot mention in my previous reply that I'm using AutoCAD 2024 version 19.1. I ran the new Lisp and I got this set of errors: I've also attached a screen print of the AutoCAD window.

X-Offset <.5>:
Y-Offset <.5>:
Start point:
Plot to PDF? <Yes>: yes
Unknown command "NONE". Press F1 for help.
Unknown command "1=1". Press F1 for help.
Unknown command "0,0". Press F1 for help.
Unknown command "YES". Press F1 for help.
Unknown command "CTB". Press F1 for help.
Unknown command "YES". Press F1 for help.
Unknown command "ID1". Press F1 for help.
Unknown command "ID1". Press F1 for help.
Unknown command "YES". Press F1 for help.
Unknown command "YES". Press F1 for help.

 

Markeckert_0-1766087853714.png

 

0 Likes
Message 19 of 46

Moshe-A
Mentor
Mentor

@Markeckert ,

 

sorry the previous fix made a bug - fix attached

i do not like your image, the sheets should be laid near each other, make sure the insertion point of all dwg(s) is at lower left corner.

0 Likes
Message 20 of 46

Markeckert
Enthusiast
Enthusiast

It went further this time. It opened Adobe and created a PDF. Unfortunately the PDF is blank except for the two red lines shown in the attached screen shot. I also included a screen shot of the publish page. 

Markeckert_0-1766091922036.png

Markeckert_1-1766092068968.png

 

 

0 Likes