Author Topic: PDF Plot - to same Directory as opened drawing  (Read 10524 times)

0 Members and 1 Guest are viewing this topic.

Timmy007

  • Guest
PDF Plot - to same Directory as opened drawing
« on: September 14, 2011, 10:54:23 AM »
Hi,

I'm new to this forum, and LISP in general, so I apologise if this has been asked before, however I couldn't find a definitive answer by searching on here.

I have used this LISP routine which was uploaded to the Autodesk Uni site back in 2009, I can get the routine to plot to PDF, however it seems to save the file to the last manually opened file's directory - i.e I opened a image file and then ran the routine on a previously opened dwg, and the PDF was save to the image file directory - not very useful if you're working in a large organisation!

It therefore only seems to do what I want it to if you open the dwg files directly and then run the routine there and then, it seems to revert back to the last manually opened directory to save the PDF file? I dragged and dropped lots of files and ran the routine, they ended up in My Documents - all very odd and confusing!

What I need to be able to do, is to run the routine, and the PDF will be saved in the directory in which the opened drawing is saved in. This also needs to work if you "drag and drop" the files into AutoCAD and run the routine, I'm sure its just a simple one liner but I haven't managed figure it out.

The LISP routine is below:

The LISP routine is below:

;A0-size Landscape Extents Fit Center Monochrome - using .pc3 file
(defun c:1PPPDF_A0LEFCM_DWG_PDF( / currtab dwgnameonly cdname)

(setq currtab (getvar "ctab"));Gets the current layout tab name
 
(setq dwgnameonly (getvar "dwgname"));Gets variable value for drawing name which includes the .dwg extenstion.
(setq cdname (substr dwgnameonly 1 (- (strlen dwgnameonly) 4)));Gets drawing name and strips file name extension.

 
(if (= (getvar "tilemode") 1);Determines if you are in Paperspace or Modelspace
 
(progn ;This part of program runs if you are in modelspace
(command "-plot" "y" "model" "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "Extents" "fit" "Center" "y" "_wyg_mono.ctb" "y" "As" "n" cdname "y" "y")
);end progn
 
(progn ;This part of program runs if you are in paperspace
(command "-plot" "y" currtab "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "extents" "fit" "center" "y" "_wyg_mono.ctb" "y" "n" "y" "n" cdname "y" "y")
);end progn
);end if
(princ)
);end defun
 

Thanks in advance

 

Tim


Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: PDF Plot - to same Directory as opened drawing
« Reply #1 on: September 14, 2011, 11:13:35 AM »
(setq dwgnameonly (getvar "dwgname"));Gets variable value for drawing name which includes the .dwg extenstion.
(setq cdname (substr dwgnameonly 1 (- (strlen dwgnameonly) 4)));Gets drawing name and strips file name extension.

 
(progn ;This part of program runs if you are in modelspace
(command "-plot" "y" "model" "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "Extents" "fit" "Center" "y" "_wyg_mono.ctb" "y" "As" "n" cdname "y" "y")
);end progn
 
(progn ;This part of program runs if you are in paperspace
(command "-plot" "y" currtab "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "extents" "fit" "center" "y" "_wyg_mono.ctb" "y" "n" "y" "n" cdname "y" "y")
);end progn
);end if
(princ)
);end defun
The code isn't defining a location for the file to be saved, just the name (cdname).  You need to get the drawing prefix AND the name and combine the two to create a full path where the file is to be saved.

Code: [Select]
(defun C:Test ( / cdname cdprefix dwgnameonly FullNameAndPath)
   (setq cdprefix (getvar "dwgprefix"))
   (setq dwgnameonly (getvar "dwgname"))
   (setq cdname (substr dwgnameonly 1 (- (strlen dwgnameonly) 4)))
   (setq FullNameAndPath (strcat cdprefix cdname))
   (alert FullNameAndPath)
   (princ)
)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: PDF Plot - to same Directory as opened drawing
« Reply #2 on: September 14, 2011, 11:14:19 AM »
Welcome to the forum Timmy007! I hope you like it here  8-)

Give this a try:

Code: [Select]
(defun c:test ( / cm )
    (setq cm (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (command "_.-plot" "_y"
        (if (= 1 (getvar 'TILEMODE)) "Model" (getvar 'CTAB))
        "DWG To PDF.pc3"
        "ISO expand A0 (841.00 x 1189.00 MM)"
        "_M" "_L" "_N" "_E" "_F" "_C" "_Y" "_wyg_mono.ctb" "_Y" "_A"
        (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME)))
        "_Y" "_Y"
    )
    (setvar 'CMDECHO cm)
    (princ)
)
(vl-load-com) (princ)

It could probably do with some more error trapping should the plotter / paper / style not exist.
« Last Edit: September 15, 2011, 02:50:04 PM by Lee Mac »

Timmy007

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #3 on: September 14, 2011, 12:17:35 PM »
Hi guys,

Thanks for the swift replies! - I'm looking forward to learning lots about LISP on the forum! it's something I've dabbled in for a few years, but never taken too seriously!

Matt, whilst what you're saying makes sense, I still get the same result when I used your code? I have placed mine below - maybe I'm doing something wrong??

Code: [Select]
;A0-size Landscape Extents Fit Center Monochrome - using .pc3 file
(defun c:1PPPDF_A0LEFCM_DWG_PDF( / cdname cdprefix dwgnameonly FullNameAndPath)
   (setq cdprefix (getvar "dwgprefix"))
   (setq dwgnameonly (getvar "dwgname"))
   (setq cdname (substr dwgnameonly 1 (- (strlen dwgnameonly) 4)))
   (setq FullNameAndPath (strcat cdprefix cdname))
   (alert FullNameAndPath)


(setq currtab (getvar "ctab"));Gets the current layout tab name
 
(setq dwgnameonly (getvar "dwgname"));Gets variable value for drawing name which includes the .dwg extenstion.
(setq cdname (substr dwgnameonly 1 (- (strlen dwgnameonly) 4)));Gets drawing name and strips file name extension.

 
(if (= (getvar "tilemode") 1);Determines if you are in Paperspace or Modelspace
 
(progn ;This part of program runs if you are in modelspace
(command "-plot" "y" "model" "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "Extents" "fit" "Center" "y" "_wyg_mono.ctb" "y" "As" "n" cdname cdprefix dwgnameonly FullNameAndPath "y" "y")
);end progn
 
(progn ;This part of program runs if you are in paperspace
(command "-plot" "y" currtab "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "extents" "fit" "center" "y" "_wyg_mono.ctb" "y" "n" "y" "n" cdname cdprefix dwgnameonly FullNameAndPath "y" "y")
);end progn
);end if
(princ)
);end defun


it also then asks me for the last 2 plot promts of "save changes to plot set up" & "proceed with plot"?

Lee, I will have to have a more detailed look at your code, as it errors and doesn't run, but I'll have a look to see if I can decifer the problem - and probably then ask you for help with it! lol  :lol:

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: PDF Plot - to same Directory as opened drawing
« Reply #4 on: September 14, 2011, 02:12:12 PM »
Lee, I will have to have a more detailed look at your code, as it errors and doesn't run, but I'll have a look to see if I can decifer the problem - and probably then ask you for help with it! lol  :lol:

What error do you get Timmy? I gave it a quick test before posting and all seemed to be fine  :?

Timmy007

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #5 on: September 15, 2011, 03:59:15 AM »
Hi Lee,

when I run the LISP it starts to run, but then crashes out I've pasted in the command line text for you to see where its crashing.

Code: [Select]
Command: test
Unknown command "Y".  Press F1 for help.
Unknown command "AS".  Press F1 for help.
Unknown command "Y".  Press F1 for help.
Unknown command "N:\PROJECTS\A059001 - A059500\A059473\ACAD\ELDON\SHEET
FILES\ELECTRICAL\A059473-1-28-E-2000_03".  Press F1 for help.
Unknown command "Y".  Press F1 for help.
Unknown command "Y".  Press F1 for help.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: PDF Plot - to same Directory as opened drawing
« Reply #6 on: September 15, 2011, 06:20:33 AM »
Looks like Lee may have this name incorrect, try this spelling  "_wyg_mono.ctb"

Although there is a Yes before the Drawing name that looks out of place too.   :-o
« Last Edit: September 15, 2011, 06:24:54 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Timmy007

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #7 on: September 15, 2011, 08:16:43 AM »
I've managed to get the paperspace printing to work now, and it creates the PDF to the dwg files origin directory which is great!! I've used a combination of the original routine, and Lee's and Matt's - so thanks for your help  :-)

What I can't seem to get is the model space to work... This seems to place the pdf in the last opned file driectory (as before) but now also calls the PDF file "n" or "y". I know this is to do with something within the routine, but i'm stumped after that!

Code: [Select]
;A0-size Landscape Extents Fit Center Monochrome - using .pc3 file
(defun c:1PPPDF_A0LEFCM_DWG_PDF( / cm cdname cdprefix dwgnameonly FullNameAndPath)
(setq cm (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)

(setq currtab (getvar "ctab"));Gets the current layout tab name
(setq cdprefix (getvar "dwgprefix")) 
(setq dwgnameonly (getvar "dwgname"));Gets variable value for drawing name which includes the .dwg extenstion.
(setq cdname (substr dwgnameonly 1 (- (strlen dwgnameonly) 4)));Gets drawing name and strips file name extension.
(setq FullNameAndPath (strcat cdprefix cdname))
(alert FullNameAndPath)
 
(if (= (getvar "tilemode") 1);Determines if you are in Paperspace or Modelspace
 
(progn ;This part of program runs if you are in modelspace
(command "-plot" "y" "model" "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "Extents" "fit" "Center" "y" "_wyg_mono.ctb" "y" "As" "n" (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME))) "y" "y")
);end progn
 
(progn ;This part of program runs if you are in paperspace
(command "-plot" "y" currtab "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)" "M" "L" "n" "extents" "fit" "center" "y" "_wyg_mono.ctb" "y" "n" "y" "n" (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME))) "y" "y")
);end progn
);end if
(princ)
);end defun

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: PDF Plot - to same Directory as opened drawing
« Reply #8 on: September 15, 2011, 02:50:58 PM »
Hi Lee,

when I run the LISP it starts to run, but then crashes out I've pasted in the command line text for you to see where its crashing.

Code: [Select]
Command: test
Unknown command "Y".  Press F1 for help.
Unknown command "AS".  Press F1 for help.
Unknown command "Y".  Press F1 for help.
Unknown command "N:\PROJECTS\A059001 - A059500\A059473\ACAD\ELDON\SHEET
FILES\ELECTRICAL\A059473-1-28-E-2000_03".  Press F1 for help.
Unknown command "Y".  Press F1 for help.
Unknown command "Y".  Press F1 for help.

I see I mispelled the ctb filename - please try my updated code above.  :-)

Timmy007

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #9 on: September 16, 2011, 06:58:15 AM »
Hi Lee

Thanks for amending the code, I tested it out this morning, and it wprks great in model space. How would I amend it to work in paperspace also?

My code above works flawlessly in paperspace - which should be fine for what we need it for, but itsn't as clean as your code - I'm still very new to LISP  :-D

Lee Mac

  • Seagull
  • Posts: 12906
  • London, England
Re: PDF Plot - to same Directory as opened drawing
« Reply #10 on: September 17, 2011, 09:02:22 AM »
My code above works flawlessly in paperspace - which should be fine for what we need it for, but itsn't as clean as your code - I'm still very new to LISP  :-D

Assuming the prompts are correct for your code, give this a try:

Code: [Select]
(defun c:test ( / cm )
    (setq cm (getvar 'CMDECHO))
    (setvar 'CMDECHO 0)
    (command "_.-plot" "_y"
        (if (= 1 (getvar 'TILEMODE)) "Model" (getvar 'CTAB))
        "DWG To PDF.pc3" "ISO expand A0 (841.00 x 1189.00 MM)"
        "_M" "_L" "_N" "_E" "_F" "_C" "_Y" "_wyg_mono.ctb" "_Y"
    )
    (if (= 1 (getvar 'TILEMODE))
        (command "_A")
        (command "_N" "_Y")
    )
    (command "_N" (strcat (getvar 'DWGPREFIX) (vl-filename-base (getvar 'DWGNAME))) "_Y" "_Y")
    (setvar 'CMDECHO cm)
    (princ)
)
(vl-load-com) (princ)

rhino

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #11 on: September 19, 2011, 02:11:55 PM »
might want to look at this code:
http://www.theswamp.org/index.php?topic=28078.0

the prompts and command sequence needs to be tweaked to work in paperspace though...

rhino

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #12 on: October 12, 2011, 11:04:56 PM »
Is there a way to pass the file name and location to cutepdf via vba?

The following link shows how the file name and path are provided for an ms. access document...
http://bytes.com/topic/access/answers/879916-create-pdf-report-using-cutepdf-means-vba

We have a batch plot routine and would like to use cutepdf for plotting as ACAD 2007 dwg to pdf.pc3 results in large pdf files
As cutepdf behaves like a printer it opens outside the ACAD shell - which is why we can't pass the file name or path via lisp...

Thanks for the help.

pBe

  • Bull Frog
  • Posts: 402
Re: PDF Plot - to same Directory as opened drawing
« Reply #13 on: October 13, 2011, 03:54:51 AM »
One thing i noticed when using "DWG to PDF.pc3" is somehow it wont print "RTEXT" entity.

We had a diesel expression at the bottom left corner of our standard Title Block and it just wont show on the resulting pdf
since we lost our cutepdf.pc3, we ended up using "ADOBE PDF.pc3"  which prompts for filename.

Its not like we cant change the titleblock but its more of  nagging issue with me.

Any thoughts on this?






cmwade77

  • Swamp Rat
  • Posts: 1443
Re: PDF Plot - to same Directory as opened drawing
« Reply #14 on: October 13, 2011, 12:07:50 PM »
What version of AutoCAD? In 2012 this seems to work fine.

pBe

  • Bull Frog
  • Posts: 402
Re: PDF Plot - to same Directory as opened drawing
« Reply #15 on: October 14, 2011, 04:47:20 AM »
Autcad 2009

Attached is a sample file

Thanks

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: PDF Plot - to same Directory as opened drawing
« Reply #16 on: October 14, 2011, 11:38:47 AM »
I didn't have your plot style, so I used one of our own, so it may be a bit bolder than you would normally have, but please see the attached PDF. I created it in 2012 with the DWG to PDF.PC3

I no longer have 2009 on my system, we are on subscription, so we just stick with the latest and save down when needed.

rhino

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #17 on: October 14, 2011, 11:44:33 AM »
that's precisely the reason why we need to use cutepdf to create pdf's - the driver provided with ACAD 2007 does not 'work very well'...they fixed this in the 2010 version which is the next major release of ACAD.

any ideas on my post and request?

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: PDF Plot - to same Directory as opened drawing
« Reply #18 on: October 14, 2011, 11:49:41 AM »
Well, there are a couple of options that I can see:

  • Upgrade to 2012, it really is worth it, there are a lot of new features that will make things a lot faster for you since 2009.
  • If you do not want to upgrade, you can also use PDF Creator (free at http://www.pdfforge.org/pdfcreator) and set it up to automatically name the files. Last time that I tried it, CutePDF doesn't allow this. Be sure to use the link, there are a lot of similarly title ones that are spyware ridden, you will still need to do a custom install and uncheck the install toolbar with this one if you don't want it though.
  • Use the DWF6 ePlot, then convert the DWFs to PDFs.

rhino

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #19 on: October 14, 2011, 12:04:55 PM »
does pdf creator use the same ghostscript engine?

our company has already installed cutepdf on all computers - getting them to install pdf creator would be...
can pdf creator be used without installing?

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: PDF Plot - to same Directory as opened drawing
« Reply #20 on: October 14, 2011, 12:07:02 PM »
If you have a print server, you can install it there and share it, then you simply have to add the printer to each computer. Still has to be done on each system, but you can set a logon script to do that.

rhino

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #21 on: October 14, 2011, 12:38:45 PM »
pdfcreator doesn't do what i need - i would be supplying the file name and the location... :ugly:

cmwade77

  • Swamp Rat
  • Posts: 1443
Re: PDF Plot - to same Directory as opened drawing
« Reply #22 on: October 14, 2011, 12:56:29 PM »
Actually, it can be setup to accomplish what you need. Please see my guide that I just made attached, it should help you out with that. I have been meaning to create this guide for my users for a while, so I thought I would actually take a moment to finally make it.

rhino

  • Guest
Re: PDF Plot - to same Directory as opened drawing
« Reply #23 on: October 14, 2011, 01:14:28 PM »
Thank you - will call it through the lisp I have set up n post back tomorrow - the lisp prints all drawings within the folder - this should work :)

pBe

  • Bull Frog
  • Posts: 402
Re: PDF Plot - to same Directory as opened drawing
« Reply #24 on: October 15, 2011, 02:01:27 AM »
  • Upgrade to 2012, it really is worth it, there are a lot of new features that will make things a lot faster for you since 2009.

Might as well :)