Jump to content

Plot to PDF - Help to update the code


mhy3sx

Recommended Posts

Hi. I use this code to plot to pdf.

 

(defun C:laytopdf ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 (foreach Layout (layoutlist)

   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach
 (vla-put-StyleSheet(vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "Monochrome.ctb" )
 (setvar 'cmdecho cmd)
 (princ)
); defun C:test

 

 

This code works only with "monochrome.stb". I Have another plot style  ""monochrome2.stb""

I try to update the code to give a choise for the text style but something is going wrong.

 

 

(defun C:laytopdf ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 (foreach Layout (layoutlist)

   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach

  (setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 

  (if (= strdc "1")
   (progn
   (vla-put-StyleSheet(vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "Monochrome.ctb" )
    )
 )
  (if (= strdc "2")
  (vla-put-StyleSheet(vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "Monochrome2.ctb" )
  )
 (setvar 'cmdecho cmd)
 (princ)
); defun C:test

 

Can any one help me to fix the code ?

 

Thanks

Link to comment
Share on other sites

If you do plot detailed yes allows for setting the ctb.

(COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m"    "LANDSCAPE"  "N"   "W"  "-6,-6"    "807,560" "1=2"  "C"
	       "y"	  "Designlasercolour.ctb" "Y"	"n"    "n"    "y"   dwgName "N" "y"      )
    )

Maybe

(if (= strdc "1")
(setq ctb "Monochrome.ctb")
(setq ctb "Monochrome2.ctb")
)
(COMMAND "-PLOT"  "Y"  "" "dwg to Pdf"
	       "Iso full bleed A3 (420.00 x 297.00 MM)" "m"    "LANDSCAPE"  "N"   "W"  "-6,-6"    "807,560" "1=2"  "C"
	       "y"	ctb "Y"	"n"    "n"    "y"   dwgName "N" "y"      )
)

 

Link to comment
Share on other sites

I try this but not gives me the option to change the plot style

 

(defun C:foo ( / cmd )
  (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
(if (= strdc "1")
(setq ctb "Monochrome.ctb")
(setq ctb "Monochrome2.ctb")
)
(foreach Layout (layoutlist)
    (command "_.-PLOT" 
      "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
      Layout                                      ; Enter a layout name or [?] <Layout1>:
      ""                                          ; Enter a page setup name
      "DWG to PDF.pc3"                            ; Enter an output device name or [?] <DWG to PDF.pc3>:
      (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
      "No"                                        ; save changes to page setup?
      ctb
      "Yes"                                       ;Use Plot Style?
      "YES"                                       ; proceed with plot?
    ); command
  ); foreach


  (setvar 'cmdecho cmd)
  (princ)
); defun

 

Any ideas?

Thanks

Link to comment
Share on other sites

 

Your routine ctb changes depending on strdc, but does not ask for the strdc value.

 http://docs.autodesk.com/ACD/2011/ENU/filesALR/WS1a9193826455f5ff1a32d8d10ebc6b7ccc-69ff.htm

To use getkword, you must use initget first. like this

(defun c:test ( / strdc )
  (initget "1 2")
  (setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
  (cond
    ((= strdc "1") (setq strdc "Monochrome.ctb"))
    ((= strdc "2") (setq strdc "Monochrome2.ctb"))
    (t (setq strdc "Monochrome.ctb"))
  )
  (princ strdc)
  (princ)
)

 

 

 

And if you want to remember the previous value as a global variable, you can do it like this.

(defun c:test ( / strdc answer )
  (initget "1 2")
  (if (= oldanswer nil) (setq oldanswer "1"))
  (setq answer (getkword (strcat "\n [1.Monochrome/2.Monochrome2]:<" oldanswer ">")))
  (if (= answer nil) (setq answer oldanswer))
  (cond
    ((= answer "1") (setq strdc "Monochrome.ctb"))
    ((= answer "2") (setq strdc "Monochrome2.ctb"))
  )
  (setq oldanswer answer)
  (princ strdc)
  (princ)
)

 

 

And ctb and stb are different.

Edited by exceed
Link to comment
Share on other sites

Hi exceed. I try again but is not working

 

(defun C:test ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 (foreach Layout (layoutlist)
  (initget "1 2")
  (setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
  (cond
    ((= strdc "1") (setq strdc "Monochrome.ctb"))
    ((= strdc "2") (setq strdc "Monochrome2.ctb"))
    (t (setq strdc "Monochrome.ctb"))
  )

   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach

  (princ strdc)
 (setvar 'cmdecho cmd)
 (princ)
); defun C:test

 

Any ideas?

 

Thanks

Link to comment
Share on other sites

Now you have saved the Plotstyle within strdc. Now you need to apply that within the plot command, you can do that with the detailed Plot option.
Look at the reply from BIGAL, where he sets the ctb you can just use strdc now.

Link to comment
Share on other sites

Hi EnM4st3r. BIGAL  post confiused me because change the dimension of the paper. The code I post is more simple but support one plot  style.

 

(defun C:laytopdf ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 (foreach Layout (layoutlist)

   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach
 (vla-put-StyleSheet(vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "Monochrome.ctb" )
 (setvar 'cmdecho cmd)
 (princ)
); defun C:test

 

 

I try this but not working

 

(defun C:foo ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 (foreach Layout (layoutlist)
   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach

 (initget "1 2")
  (setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
  (cond
  (if (= strdc "1")
   (vla-put-StyleSheet(vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "Monochrome.ctb" )
   
   )
  (if (= strdc "2")
  (vla-put-StyleSheet(vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object))) "Monochrome2.ctb" )
  )
 )
 (setvar 'cmdecho cmd)
 (princ)
); defun C:foo

  

 

 

Any options?

 

Thanks

Link to comment
Share on other sites

If you have that moved up it looks like a good start.

But you are using vla-get-activelayout as the layout to change the stylesheet but you are never changing your active layout. That wont work since it will ofc only change the plotstyle of the active layout.

 

So you could either within your foreach function use (setvar "ctab" layout) and then change the plotystyle like you did.

Or what I would prefer is using (vlax-for layout (vla-get-layouts..

 

That would look somewhat like this

(initget "1 2")
(setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
(cond
  (if (= strdc "1")
    (setq plotstyle "Monochrome.ctb" )
  )
  (if (= strdc "2")
    (setq plotstyle "Monochrome2.ctb" )
  )
)
(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-stylesheet layout plotstyle)
)

(you need to do that before your foreach function)

 

 

Edited by EnM4st3r
Link to comment
Share on other sites

  • 2 weeks later...

Hi EnM4st3r, I did the change but gives me this error

 

Error: Automation error - "StyleSheet"

 

 

(defun C:foo ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 
 (initget "1 2")
 
(setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
(cond
  (if (= strdc "1")
    (setq plotstyle "Monochrome.ctb" )
  )
  (if (= strdc "2")
    (setq plotstyle "Monochrome2.ctb" )
  )
)

(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-stylesheet layout plotstyle)
)
 
 
 (foreach Layout (layoutlist)
   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach


 
 (setvar 'cmdecho cmd)
 (princ)
); defun C:foo

  

 

 

Thanks

 

Link to comment
Share on other sites

I update the code to this is not working. I can not change the plot style and I don't know why 🥺

 

Any suggestions ?

 

(defun C:foo ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 
 (initget "1 2")
 
(setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
(cond
  (if (= strdc "1")
    (setq plotstyle "Monochrome.ctb" )
  )
  (if (= strdc "2")
    (setq plotstyle "Monochrome2.ctb" )
  )
)


 
 (foreach Layout (layoutlist)
   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach

(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-stylesheet layout plotstyle)
)
 
 
 (setvar 'cmdecho cmd)
 (princ)
); defun C:foo

  

 

 

Thanks

Link to comment
Share on other sites

You will get an error using (vla-get-layouts (vla-get-activedocument..... as this includes "Model" but as you have shown your using (layoutlist) a better way.

 

Just go back to my code where it has "W" that is for window so you replace with "Layout" and remove the window corners.

 

Just type "-plot" and follow the prompts very carefully. That is your lisp code."

Edited by BIGAL
Link to comment
Share on other sites

Did you do -plot ?

 

: -PLOT
Detailed plot configuration? [Yes/No] <No>:y
Enter a layout name or ? <D01>:
Enter an output device name or ? <Print As PDF.pc3>:
Enter paper size or ? <ISO A3 (297.00 x 420.00 MM)>:
Enter paper units [Inches/Millimeters] <Millimeters>:
Enter drawing orientation [Portrait/Landscape] <Landscape>:
Plot upside down? [Yes/No] <No>:
Enter plot area [Display/Extents/Layout/View/Window] <Layout>:
Enter plot scale (Plotted millimeters = Drawing Units) or [Fit] <1:2000>:f
Enter plot offset (x,y) or [Center] <2.5,1.2>:c
<c> is not valid offset
Enter plot offset (x,y) or [Center] <2.5,1.2>:
Plot with plot styles? [Yes/No] <Yes>:
Enter plot style table name or ? (enter . for none) <default.ctb>:
Plot with lineweights? [Yes/No] <Yes>:
Scale lineweights with plot scale? [Yes/No] <No>:
Plot paper space last? [Yes/No] <Yes>:
Remove hidden lines in paper space? [Yes/No] <No>:

 

Link to comment
Share on other sites

Hi  BIGAL, I try this ,... is not working

 

 

((defun C:foo ( / cmd )
 (setq cmd (getvar 'cmdecho)) (setvar 'cmdecho 0)
 
 (initget "1 2")
 
(setq strdc (getkword "\n [1.Monochrome/2.Monochrome2]:<1>")) 
(if (= strdc "1")
(setq ctb "Monochrome.ctb")
(setq ctb "Monochrome2.ctb")
)


 
 (foreach Layout (layoutlist)
   (command "_.-PLOT" 
     "No"                                        ; Detailed plot configuration? [Yes/No] <No>: No
     Layout                                      ; Enter a layout name or [?] <Layout1>:
     ""                                          ; Enter a page setup name
     "DWG To PDF.pc3"                            ; Enter an output device name or [?] <DWG To PDF.pc3>:
     (strcat (getvar "DWGPREFIX") Layout ".pdf") ; Directory to save
     "No"                                        ; save changes to page setup?
     "YES"                                       ; proceed with plot?
   ); command
 ); foreach

(vlax-for layout (vla-get-layouts (vla-get-activedocument (vlax-get-acad-object)))
  (vla-put-stylesheet layout ctb)
)
 
 
 (setvar 'cmdecho cmd)
 (princ)
); defun C:foo  

 

Link to comment
Share on other sites

Re check the -plot if you do "No detailed" and your in a layout, then use "" rather than layout as this is being seen as a variable containing a layout name which you do not have.

Edited by BIGAL
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...