mhy3sx Posted November 6 Share Posted November 6 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 6 Share Posted November 6 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" ) ) Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 6 Author Share Posted November 6 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 Quote Link to comment Share on other sites More sharing options...
exceed Posted November 7 Share Posted November 7 (edited) 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 November 7 by exceed Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 7 Author Share Posted November 7 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 Quote Link to comment Share on other sites More sharing options...
EnM4st3r Posted November 7 Share Posted November 7 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. Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 7 Author Share Posted November 7 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 7 Share Posted November 7 One obvious is your setting the ctb after you have plotted. Move that step to start of code. 1 Quote Link to comment Share on other sites More sharing options...
EnM4st3r Posted November 9 Share Posted November 9 (edited) 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 November 9 by EnM4st3r Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 17 Author Share Posted November 17 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 Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 18 Author Share Posted November 18 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 19 Share Posted November 19 (edited) 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 November 19 by BIGAL Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 20 Author Share Posted November 20 Hi BIGAL. Your code confuses me because using A3 paper. I don't want to change the paper size !!!! Thanks Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 21 Share Posted November 21 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>: Quote Link to comment Share on other sites More sharing options...
mhy3sx Posted November 21 Author Share Posted November 21 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 Quote Link to comment Share on other sites More sharing options...
BIGAL Posted November 21 Share Posted November 21 (edited) 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 November 21 by BIGAL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.