Author Topic: Plot to PDF lisp for 2007  (Read 9706 times)

0 Members and 1 Guest are viewing this topic.

hyposmurf

  • Guest
Plot to PDF lisp for 2007
« on: September 20, 2006, 04:25:12 PM »
In what time I have spare I've been fiddling with some very basic lisps cut and carving them to get some very basic processes made easier for my everyday work.I've managed to get create a lisp that will do thew above but is no way perfect and I have one fundemental flaw.
I get iit to create the PDF,all great but it gets the drawing name together with .dwg file extension .so my file is drawingno.dwg.pdf .How do I get it to ignore the .dwg when it gets the drawing name?
Also we normally add all our PDF files to one folder,where as our dwg files are dotted about in different folders,my routine will only create a PDF within the folder the drawing is located.Is there a utility that will grab all my PDF files afterwards and do a cut and paste to the desired folder?Id rather do it this way than have to specifiy the folder to place the PDF every time.Here's my humble code :-)

Code: [Select]
;;PLOT TO PDF
(DEFUN C:PDF ()
(command
"-plot" "n" "" "" "DWG To PDF.pc3" (getvar "dwgname") "N" "Y")(princ))

Suiggestions welcome as to what I should have done with my code.Like I shouldve had the bottom line broken up more into further lines.

Oh I forgot to say to big hello to you all not been around much busy with my flat,girlfriend and work.

« Last Edit: September 20, 2006, 04:29:34 PM by hyposmurf »

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Plot to PDF lisp for 2007
« Reply #1 on: September 20, 2006, 04:30:18 PM »
try using:

(vl-filename-base (getvar 'dwgname))

I would also read up on the sheet set manager for acad I can't imagine printing without it.

http://www.autodesk.com.hk/adsk/servlet/item?siteID=1170102&id=6746935
« Last Edit: September 20, 2006, 04:36:30 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hyposmurf

  • Guest
Re: Plot to PDF lisp for 2007
« Reply #2 on: September 20, 2006, 04:36:12 PM »
Thanks Ronjop can you explain why that works.vl-filename-base defines that that it should just take the filename and the next part goes onto get the drawing name?Never used vl-filename-base.Waht else can be done with vl?

ronjonp

  • Needs a day job
  • Posts: 7531
Re: Plot to PDF lisp for 2007
« Reply #3 on: September 20, 2006, 04:47:35 PM »
From the help file:

Quote
Returns the name of a file, after stripping out the directory path and extension

(vl-filename-base filename)

Arguments

filename

A string containing a file name. The vl-filename-base function does not check to see if the file exists.

Return Values

A string containing filename in uppercase, with any directory and extension stripped from the name.

Examples

_$ (vl-filename-base "c:\\acadwin\\acad.exe")
"ACAD"
_$ (vl-filename-base "c:\\acadwin")
"ACADWIN"

If you look in the help file under Autolisp, Visual lisp, and DXF there is a list of most of the commands in there sorted out alphabetically.

Another way to do this is:

(vl-string-right-trim ".dwg" (getvar 'dwgname))



Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

hyposmurf

  • Guest
Re: Plot to PDF lisp for 2007
« Reply #4 on: September 20, 2006, 04:54:23 PM »
Thanks alot  8-)

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Plot to PDF lisp for 2007
« Reply #5 on: September 20, 2006, 05:00:28 PM »
Hyposmurf,

I have created a similar routine for creating PDFs and it will place it in a specified folder.   it does a bunch of housekeeping things before and during the creation of the pdf.  The only thing that will not work for you is that the PDF name is the Dwg number in the title block. 

The people here at the swamp, (CAB and T Willey to name a few) help me evolve the routine to where it is today and i feel that they shared and i have no problem in sharing for you to use or cannibalized from.  I am heading home for supper and will return to do some plotting.  I will post the routine then if you would like.




I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

hyposmurf

  • Guest
Re: Plot to PDF lisp for 2007
« Reply #6 on: September 21, 2006, 07:43:11 AM »
Sure I'd like to see that routine and Im sure others would.

hudster

  • Gator
  • Posts: 2848
Re: Plot to PDF lisp for 2007
« Reply #7 on: September 21, 2006, 07:49:06 AM »
Here's one I've written, with a lot of help from this site.

This one saves the PDF in the working folder, but checks for a drawing sheet and plots it to so suit the sheet, A1, A0 etc.

Code: [Select]
;;;
;;; TITLE:@file.lsp
;;;
;;; Copyright (C) 2006 by Andy Hudson
;;;
;;; Permission to use, copy, modify, and distribute this
;;; software and its documentation for any purpose and without
;;; fee is hereby granted
;;;
;;; THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR
;;; IMPLIED WARRANTY. ALL IMPLIED WARRANTIES OF FITNESS FOR ANY
;;; PARTICULAR PURPOSE AND OF MERCHANTABILITY ARE HEREBY
;;; DISCLAIMED.
;;;
;;; Andy Hudson
;;; May 2006
;;;
;;;-------------------------------------------------------------
;;; Description:
;;;
;;; Plot routine to set up and plot to PDF
;;;
;;;-------------------------------------------------------------
;;; COMMAND - Various
;;;-------------------------------------------------------------
(defun c:@PDF (/ @cmd @fname @fname1 @fname2 @fname3 @paper @plotter @ss @ss2 @tmode)
  (setq @tmode (getvar "tilemode"))
  (setq @cmd (getvar "cmdecho"))
  (setvar "cmdecho" 0)
  ;;filename
  (setq @fname (strcat (getvar "dwgprefix") (vl-filename-base (getvar "dwgname"))))
  ;;GET TITLE BLOCK NAME
  (setq @ss (entget (ssname (ssget "x" (list (cons 0 "insert") (cons 2 "*sheet"))) 0)))
  (setq @ss2 (cdr (assoc 2 @ss)))
  ;; IF A1 TITLE SHEET FOUND
  (cond
    ((= (strcase @ss2) "A1_SHEET")
     (setq @paper   "ISO expand A1 (841.00 x 594.00 MM)"
           @plotter "DWG To PDF.pc3"))
    ;; IF A0 TITLE SHEET FOUND
    ((= (strcase @ss2) "A0_SHEET")
     (setq @paper   "ISO expand A0 (841.00 x 1189.00 MM)"
           @plotter "DWG To PDF.pc3"))
    ;; IF STH LAN TITLE SHEET FOUND
    ((= (strcase @ss2) "TSHEET")
     (setq @paper   "ISO expand A1 (841.00 x 594.00 MM)"
           @plotter "DWG To PDF.pc3"))
    ;; IF renfrewshire TITLE SHEET FOUND
    ((= (strcase @ss2) "A1_DWG_SHEET")
     (setq @paper   "ISO expand A1 (841.00 x 594.00 MM)"
           @plotter "DWG To PDF.pc3"))
  )
  ;; PAGESETUP PART
  (if @paper
    (progn
      (setvar "TILEMODE" 0)
      (command "-plot" "Y" "" @plotter @paper "m" "LANDSCAPE" "NO" "EXTENTS" "FIT" "CENTER" "YES"
               "Rybka Battle - Full Colour.ctb" "YES" "NO" "NO" "NO" @fname "NO" "YES"
              )
    )
    (alert "No Title Sheet Found")
  )
  ;;reset variables
  (setvar "cmdecho" @cmd)
  (princ)
)
Revit BDS 2017, 2016, 2015, 2014, AutoCAD 2017, 2016, Navisworks 2017, 2016, BIM360 Glue

GDF

  • Water Moccasin
  • Posts: 2081
Re: Plot to PDF lisp for 2007
« Reply #8 on: September 21, 2006, 10:10:58 AM »
This is not a standalone utility (incorp into my larger program), but you can get some good nuggets from it.
The batch Plot is by our good friend Tim Willey.

Gary
Why is there never enough time to do it right, but always enough time to do it over?
BricsCAD 2020x64 Windows 10x64

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Plot to PDF lisp for 2007
« Reply #9 on: September 21, 2006, 01:21:04 PM »
Attached is my Plot to a PDF lisp.  Feel free to use it or part-it-out.

The routine is large and clunky partly due to what I want done and partly to my "See Dick run." way of programing.

Note to others
Please feel free to comment on ways to improve how ever I don't want to hijack Hyposmurf's thread.  :-)
« Last Edit: September 21, 2006, 01:22:44 PM by Krushert »
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

Andrea

  • Water Moccasin
  • Posts: 2372
Re: Plot to PDF lisp for 2007
« Reply #10 on: September 25, 2006, 01:16:34 PM »
Just for Information....

I have made many test with PDF file from DWG...

But we have BIG BIG drawings here..
so the PDF files are BIG also and slow to make it...

solution ?

Yes,
Create a DWF file format...this will reduce 60% or more your drawing file..
and still vector format.

after the DWF was created.....you can now print to PDF (we use cutePDF)
these steps was quick ,clean and fast. !

You will save time creating PDF and was sure to create-it !  ;-)

If you have any other suggestion....don't be shy !

 :kewl:
Keep smile...

hyposmurf

  • Guest
Re: Plot to PDF lisp for 2007
« Reply #11 on: October 03, 2006, 03:58:22 PM »
Thanks for all your feedback.I am still pondering what Im doing wrong.Alll I want is for my PDF to be created in the folder the drawing is,I can then move it manually after.Bit cumbersome but it will suffice for now.Heres what I have come up with so far:

Code: [Select]
;;PLOT PDF
(DEFUN C:PDF ()
(command "_saveas""2000")(GETVAR "DWGPREFIX")(getvar 'dwgname)
(command "-plot" "N" "" "" "DWG To PDF.pc3" (vl-filename-base (getvar 'dwgname)) "N" "Y")(princ))

Heres what I get after:

Command: pdf
_saveas
Current file format: AutoCAD 2000(LT2000) Drawing
Enter file format
[R14(LT98&LT97)/2000(LT2000)/2004(LT2004)/2007(LT2007)/Standards/DXF/Template]
<2007>: 2000 Save drawing as <C:\Documents and Settings\d.ryan\Desktop\Southall
Eventide Home.dwg>: -plot A drawing with this name already exists.
Do you want to replace it? <N> N
Command: PDF Unknown command "PDF".  Press F1 for help.
 
Command: PDF Unknown command "PDF".  Press F1 for help.
 
Command: DWG To PDF.pc3 Unknown command "DWG TO PDF.PC3".  Press F1 for help.
 
Command: Southall Eventide Home Unknown command "SOUTHALL EVENTIDE HOME".
Press F1 for help.
 
Command: N Unknown command "N".  Press F1 for help.
 
Command: Y Unknown command "Y".  Press F1 for help.

I realise that I need to add a YES to overwrite the existing drawing when the save portion of the lisp exicutes,not sure how though.

Another could have the PDF files always save to the same location,but have the same file names?

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Plot to PDF lisp for 2007
« Reply #12 on: October 03, 2006, 04:13:29 PM »
I realise that I need to add a YES to overwrite the existing drawing when the save portion of the lisp exicutes,not sure how though. 

First you have to clear the save-as crash to find out where the next crash is going to happen.  I typical set the "expert" variable to "4" to ignore the overwrite prompt.  Then I set it back to 1 in the end.  The gurus might have a better way for this.

Another could have the PDF files always save to the same location, but have the same file names?
  this is where prefixing the file name with a date & time will treat it as a separate file everytime.  If that is what you want.  If you want the PDF file to be overwritten everytime then leave the expert variable as 4 for this operation as well.

Gurus: Please correct me if I am wrong or there is a much more efficient way of doing this.
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans

hyposmurf

  • Guest
Re: Plot to PDF lisp for 2007
« Reply #13 on: October 04, 2006, 08:14:51 AM »
Ideally I'd like to manually create a PDF folder, then run my lisp on each drawing I want to PDF, only having to specify the PDF location once at the start of the operation.All my PDF's would then fall into the one folder.

Krushert

  • Seagull
  • Posts: 13679
  • FREE BEER Tomorrow!!
Re: Plot to PDF lisp for 2007
« Reply #14 on: October 04, 2006, 12:30:47 PM »
Take a look at my lisp that I attached earlier.  My lisp just does that (similar).   See code snips below.  My current lisp creates a sub-folder in the project folder.  The drawing folder also resides in the Project folder.

Code: [Select]
;;; Main Application ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
;;; PLOTS THE DRAWING TO A PDF FILE WITH THE CURRENT LAYOUT..
  (DWG-NUMB)
  (today)
  (StrPath)

[b]  (vl-mkdir NewPath)[/b]

  (setq plotter (strcat "CWSs DWG To PDF.pc3"))
  (vl-cmdf "-PLOT" "NO" "" "PDF_ARCH-D" plotter NewFile "n" "y")

Code: [Select]
  ;;Start of StrPath defun~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ;;Replaces "Drawings" folder with a "Transfer-OutGoing" folder
  (defun StrPath (/ OldName OldPath)
    ;;define the function and declare all variabled local

    (setq OldName (getvar "dwgname")) ;Extracts the Drawing File Name
    (setq OldPath (getvar "dwgprefix")) ;Extracts the Drawing Location
    (setq NewPath (vl-string-subst ; Swaps folders from teh existing path
    "\\Transfer-Outgoing\\"
    "\\Drawings\\"
    OldPath
  )
    )

That is if I understand you correctly.  If you are wanting to place the pdfs in a different folder everytime you run the lisp; then someone smarter than me will have to help you with that.  (psst.  they helped me with my lisp in setting this folder feature up)  You might be going down a route of a batch script plotting process.
« Last Edit: October 04, 2006, 12:34:12 PM by Krushert »
I + XI = X is true ...  ... if you change your perspective.

I no longer CAD or Model, I just hang out here picking up the empties beer cans