DWG to PDF

DWG to PDF

gobluejd
Advocate Advocate
5,267 Views
47 Replies
Message 1 of 48

DWG to PDF

gobluejd
Advocate
Advocate

This is what I need to do:

 

Replace the Qsave command with a custom command that every time I save a DWG I want it to create a PDF in the background, save it like the exportpdf command does (names it the same filename - no layout info and save over an existing file if there is one).  It will always be saved to the same directory. 

 

Right now I can use autopublish, but it adds the name of the layout tab.  I need it to be just the acutal file name, for example - test.dwg = test.pdf.

 

Can anyone help me?  

 

0 Likes
Accepted solutions (2)
5,268 Views
47 Replies
Replies (47)
Message 2 of 48

wispoxy
Advisor
Advisor
Qsave command too important. Look for a decent LISP routine and set the command to something small like qsave.
0 Likes
Message 3 of 48

gobluejd
Advocate
Advocate
I've looked and do not see anything like what I am asking. I can certainly edit a LISP if it similar to what I need. At this point I do not see your response as a solution. I am needing help writing/finding one similar.
0 Likes
Message 4 of 48

wispoxy
Advisor
Advisor
Well then, I'll just have to help you find one 😄
Message 5 of 48

wispoxy
Advisor
Advisor
0 Likes
Message 6 of 48

gobluejd
Advocate
Advocate

Thanks!  I saw that as well, but not sure how it is working.  I contacted the guy who created.  I will post if he comes up with a solution.

0 Likes
Message 7 of 48

wispoxy
Advisor
Advisor
Ok, ya... I was going to tell you to private message that high rank.
0 Likes
Message 8 of 48

hmsilva
Mentor
Mentor

Hi Jeff,

quick and dirty, but should do the trick, add the code in acaddoc.lsp

 

(command "_.undefine" "qsave")
(defun c:qsave (/ *error* echo file mutt)

   (defun *error* (msg)
      (if mutt
         (setvar 'nomutt mutt)
      )
      (if echo
         (setvar 'cmdecho echo)
      )
      (cond ((not msg))
            ((member msg '("Function cancelled" "quit / exit abort")))
            ((princ (strcat "\n** Error: " msg " ** ")))
      )
      (princ)
   )

   (setq mutt (getvar 'nomutt)
         echo (getvar 'cmdecho))
   (setvar 'cmdecho 0)
   (setvar 'nomutt 1)
   (setq file (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".pdf"))
   (if (= (getvar 'ctab) "Model")
      (command "_.-export" "_P" "_D" "_N" file)
      (command "_.-export" "_P" "_C" "_N" file)
   )
   (command "_.qsave")
   (*error* nil)
   (princ)
)

 

If a user enter .qsave (with a period), will call the native 'qsave' command.

 

Hope this helps,
Henrique

EESignature

0 Likes
Message 9 of 48

gobluejd
Advocate
Advocate

Thanks!  I will try this when I get into office!!!

0 Likes
Message 10 of 48

gobluejd
Advocate
Advocate
My PC needed a doctor 😞 I will confirm if this works after holidays!!!
0 Likes
Message 11 of 48

gobluejd
Advocate
Advocate
I have added this and do not see anything happen after the qsave. I am not sure where I see in the code it is saving to. I have searched for *.pdf via c: and do not see a PDF has been created. Can you advise? Also I just got back from vacation which is why I am not just looking at this.
0 Likes
Message 12 of 48

gobluejd
Advocate
Advocate

Also I notice when I save (to test) and then do a regular "_exporteplotformat" it says the attached and Adobe is not open.

 

Thoughts?

 

 

0 Likes
Message 13 of 48

hmsilva
Mentor
Mentor

@gobluejd wrote:
I have added this and do not see anything happen after the qsave. I am not sure where I see in the code it is saving to. I have searched for *.pdf via c: and do not see a PDF has been created. Can you advise? Also I just got back from vacation which is why I am not just looking at this.

Hi Jeff,

the code will save the '.pdf' file in the same directory as the current '.dwg' file and with the same name.

I did test the code (in an old AutoCAD) without issues...

 

Open a test .dwg and If you copy/paste this code lines in command line

 

(if (setq f (findfile "acaddoc.lsp"))
   (startapp "explorer" f)
   (prompt "\nFile not found!!!")
)

do you see the added code in acaddoc.lsp file?

 

 

Henrique

EESignature

0 Likes
Message 14 of 48

gobluejd
Advocate
Advocate

I created a test.dwg, pasted the code you added and it does not show up in the acaddoc.lsp (I attached).

 

It is not creating a PDF in same directory.  I can tell you that if I do a qsave, then try and use the exportPDF command, it locks the PDF file and says it is in use as previously mentioned.

0 Likes
Message 15 of 48

hmsilva
Mentor
Mentor

@gobluejd wrote:

I created a test.dwg, pasted the code you added and it does not show up in the acaddoc.lsp (I attached).

 

It is not creating a PDF in same directory.  I can tell you that if I do a qsave, then try and use the exportPDF command, it locks the PDF file and says it is in use as previously mentioned.


Jeff,

the code I have posted, will open the first acaddoc.lsp file that autocad finds.

It should open the acaddoc.lsp file with the

(command "_.undefine" "qsave")
(defun c:qsave (/ ...

 

(findfile "acaddoc.lsp")

the returned path is from the modified acaddoc.lsp?

 

If not, you'll have to edit the found acaddoc and add the

(command "_.undefine" "qsave")
(defun c:qsave (/ ...

 

'then try and use the exportPDF command, it locks the PDF file and says it is in use as previously mentioned.'

Jeff, I have no clue why it says the file is in use... in my tests, I can edit/delete the '.pdf' files created by the code...

Which AutoCAD version are you using?

 

Henrique

EESignature

0 Likes
Message 16 of 48

gobluejd
Advocate
Advocate

I think I may see the issue.  I have Autocad and Mechanical Autocad and I may have edited the wrong one. 

 

However when AutoCad is open, and I paste:

(findfile "acaddoc.lsp")

 It comes up nil.

 

The only copy I can see is in AcadM, which is for the Mechanical (which I never use). I have the ultimate subscription.

 

So, I wonder why I can not see it?

0 Likes
Message 17 of 48

gobluejd
Advocate
Advocate

Ok - Got it to work.  I did not have the file for AutoCad 2016.  I took the one in the Mechanical Directory, saveas as to my autocad 2016, deleted all in it and added your code and it works!!!!

 

Now is possible to have it publish to another drive or folder?

 

Like

C:\Users\Jeff.Dickerson\Documents\Drawings\PDF

 

0 Likes
Message 18 of 48

hmsilva
Mentor
Mentor
Accepted solution

@gobluejd wrote:

Ok - Got it to work.  I did not have the file for AutoCad 2016.  I took the one in the Mechanical Directory, saveas as to my autocad 2016, deleted all in it and added your code and it works!!!!

 

Now is possible to have it publish to another drive or folder?

 

Like

C:\Users\Jeff.Dickerson\Documents\Drawings\PDF

 


Yes,

change

(setq file (strcat (getvar 'dwgprefix) (vl-filename-base (getvar 'dwgname)) ".pdf"))

to

 

(setq file (strcat "C:\\Users\\Jeff.Dickerson\\Documents\\Drawings\\PDF\\" (vl-filename-base (getvar 'dwgname)) ".pdf"))

 

 

Henrique

EESignature

Message 19 of 48

gobluejd
Advocate
Advocate
Thanks so much!!! Is it using a certain PC3 file? It is not correctly printing it. It only PDF's a portion of it. I am assuming I just have to set the printing preferences for the correct PC3 file it is using?
0 Likes
Message 20 of 48

gobluejd
Advocate
Advocate

I got it, just had to pick correct one.  Thanks so much.

0 Likes