RepCad Posted June 25, 2020 Posted June 25, 2020 Hi everyone, I'm trying to plot a rectangle via autolisp, so I wrote some codes to get current device and make a plot by window item and left , right corner points, (setq cplot (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object) ) ) ) (setq dev (vla-get-ConfigName cplot)) (vla-put-PlotType cplot acWindow) ;;Set window option to plot area (setq pt1 (getpoint "Enter a point: ")) ;;Get upper-right point of rectabgle (setq pt2 (getpoint "Enter a point: ")) ;;Get lower-left point of rectabgle (vlax-invoke-method cplot 'setwindowtoplot pt1 pt2) (command "_.-PLOT" "No" "Model" "" dev "No" ;;plot without save file "No" "Yes" ) But it gives this error : Enter a point: ; error: lisp value has no coercion to VARIANT with this type. Quote
hanhphuc Posted June 25, 2020 Posted June 25, 2020 1 hour ago, amir0914 said: Hi everyone, I'm trying to plot a rectangle via autolisp, so I wrote some codes to get current device and make a plot by window item and left , right corner points, But it gives this error : Enter a point: ; error: lisp value has no coercion to VARIANT with this type. (vlax-3d-point pt1) as well as pt2 WCS Quote
RepCad Posted June 25, 2020 Author Posted June 25, 2020 30 minutes ago, hanhphuc said: vlax-3d-point pt1) error: Automation Error. Incorrect number of elements in SafeArray (setq cplot (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object) ) ) ) (setq dev (vla-get-ConfigName cplot)) (vla-put-PlotType cplot acWindow) (setq pt1 (getpoint "Enter a point: ")) (setq pt2 (getpoint "Enter a point: ")) (vlax-invoke-method cplot 'setwindowtoplot (vlax-3d-point pt1) (vlax-3d-point pt2) ) (command "_.-PLOT" "No" "Model" "" dev "No" "No" "Yes") Quote
hanhphuc Posted June 25, 2020 Posted June 25, 2020 (edited) 4 hours ago, amir0914 said: error: Automation Error. Incorrect number of elements in SafeArray sorry i assume variant was 3d point.. so try to debug yourself , according to developer documentation it requires 2d doubles, ie: x,y not x,y,z read the article Quote object.SetWindowToPlot(LowerLeft, UpperRight) Object Layout, PlotConfiguration The object or objects this method applies to. LowerLeft Variant (two-element array of doubles); input-only The X and Y values for the lower-left window. UpperRight Variant (two-element array of doubles); input-only The X and Y values for the upper-right window. Remarks The window coordinates are taken from the origin. The units for these values are specified by the PaperUnits property. The PlotType property must be set to acWindow for these coordinates to be used for the plot. vlax-2d-point is built-in function BCAD (defun vlax-2d-point (pt) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) (list (car pt) (cadr pt)) ) ) ) eg. call (vlax-2d-point p1) ;#<variant 8197 ...> (mapcar 'vlax-2d-point (list p1 p2)) ;( #<variant 8197 ...> #<variant 8197 ...> ) hint trans & acWindow Edited June 25, 2020 by hanhphuc vlax-2d-point 1 Quote
RepCad Posted June 25, 2020 Author Posted June 25, 2020 (edited) Thanks, it's working without any error, but the exported PDF or print is only blank page. I think convert the coordinates is wrong. (defun c:plt () (setq cplot (vla-get-ActiveLayout (vla-get-activedocument (vlax-get-acad-object) ) ) ) (setq dev (vla-get-ConfigName cplot)) (vla-put-PlotType cplot acWindow) (setq pt1 (getpoint "Enter a point: ")) (setq pt2 (getpoint "Enter a point: ")) (vlax-invoke-method cplot 'setwindowtoplot (vlax-2d-point pt1) (vlax-2d-point pt2) ) (vla-put-CenterPlot cplot "1") (command "_.-PLOT" "No" "Model" "" dev (strcat (getvar "DWGPREFIX") "1.pdf") "No" "Yes" ) ) (defun vlax-2d-point (pt) (vlax-make-variant (vlax-safearray-fill (vlax-make-safearray vlax-vbDouble '(0 . 1)) (list (car pt) (cadr pt)) ) ) ) Edited June 25, 2020 by amir0914 Quote
ronjonp Posted June 25, 2020 Posted June 25, 2020 (edited) Quick glance and you are passing a variant to vlax-invoke which does not work ( not tested ) ;; Use this (vla-setwindowtoplot cplot (vlax-2d-point pt1) (vlax-2d-point pt2)) ;; Or this (vlax-invoke cplot 'setwindowtoplot (list (car pt1) (cadr pt1)) (list (car pt2) (cadr pt2)) ) Other issues too but have to run... (vla-put-centerplot cplot "1") ?? Edited June 25, 2020 by ronjonp 1 Quote
hanhphuc Posted June 26, 2020 Posted June 26, 2020 4 hours ago, amir0914 said: Thanks, it's working without any error, but the exported PDF or print is only blank page. I think convert the coordinates is wrong. 11 hours ago, hanhphuc said: hint trans & acWindow missed a hint? untested (trans p 0 2) (trans p 1 2) (trans p 2 3) (trans p 3 2) etc.. (apply 'vla-SetWindowToPlot (cons cplot (mapcar '(lambda (p) (vlax-2d-point (trans p 1 2))) (list p1 p2))) ) is debugging fun? 3 hours ago, ronjonp said: Quick glance and you are passing a variant to vlax-invoke which does not work ( not tested ) (list (car pt1) (cadr pt1)) (list (car pt2) (cadr pt2)) 1 Quote
BIGAL Posted June 26, 2020 Posted June 26, 2020 (edited) Here is a example of plot pdf using a window it has hard coded window points but change them to your pt1 pt2 etc as per second example scale can be FIT. Removes need for VL etc. (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" "Acad.ctb" "Y" "n" "n" "n" pdfName "N" "y" ) (COMMAND "-PLOT" "Y" "" "DWG To PDF" "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE" "N" "W" pt1 pt2 "1=2" "C" "y" "Acad.ctb" "Y" "n" "n" "n" pdfName "N" "y" ) If as you say have a rectangle a pline then can use the vertices of the pline so just pick pline one pick, corners are vertice 1 and 3 This can be automated to plot all rectangles on a model layout say by layer. Read as multiple title blocks in model space.Yeah have code. Edited June 26, 2020 by BIGAL 1 Quote
RepCad Posted June 29, 2020 Author Posted June 29, 2020 (edited) On 6/26/2020 at 4:47 AM, hanhphuc said: missed a hint? untested (trans p 0 2) (trans p 1 2) (trans p 2 3) (trans p 3 2) etc.. (apply 'vla-SetWindowToPlot (cons cplot (mapcar '(lambda (p) (vlax-2d-point (trans p 1 2))) (list p1 p2))) ) Thank you so much, that was great. Edited June 29, 2020 by amir0914 Quote
RepCad Posted June 29, 2020 Author Posted June 29, 2020 On 6/26/2020 at 5:02 AM, BIGAL said: Here is a example of plot pdf using a window it has hard coded window points but change them to your pt1 pt2 etc as per second example scale can be FIT. Removes need for VL etc. (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" "Acad.ctb" "Y" "n" "n" "n" pdfName "N" "y" ) (COMMAND "-PLOT" "Y" "" "DWG To PDF" "Iso full bleed A3 (420.00 x 297.00 MM)" "m" "LANDSCAPE" "N" "W" pt1 pt2 "1=2" "C" "y" "Acad.ctb" "Y" "n" "n" "n" pdfName "N" "y" ) If as you say have a rectangle a pline then can use the vertices of the pline so just pick pline one pick, corners are vertice 1 and 3 This can be automated to plot all rectangles on a model layout say by layer. Read as multiple title blocks in model space.Yeah have code. Thanks BIGAL, but if I change any option of plot setting, I have to change it from codes, for example size paper, or scale, and I want to connect program to current plotter, no change manual in codes. Quote
BIGAL Posted June 30, 2020 Posted June 30, 2020 Have a look at plotting by Maratovich he has an extensive plot routine. For me always using layouts and title blocks at true scale removed all problems, the user would choose which option to run A1, A3, PDF etc we basically only had 3 options. AS A3 is a 1/2 size A1 our title block was true A1. Quote
Steven P Posted June 30, 2020 Posted June 30, 2020 Building on what BigAl had, in my PDF plotting routine I define all the plot variables earlier in the routine, and then bring them together in the (command "plot" … ) line. I control all of this with a DCL box for user inputs but you could use the LISP routine to work it all out too. So I have: ;;Plot model space (IF (= (getvar "TILEMODE") 1) (progn (if (= plotarea "window") (command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea pause pause plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights shadeplotsetting writeplottofile saveplotsettings proceedwithplot) ) ;;end if (if (/= plotarea "window") (command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights shadeplotsetting writeplottofile saveplotsettings proceedwithplot) ) ;; end if ) ;;end progn ) ;; end if ;;;;Plot paper space (IF (= (getvar "TILEMODE") 0) (progn (if (= plotarea "window") (progn (command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea pause pause plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights scalelineweights plotpaperspacefirst hidepaperspaceobjects writeplottofile saveplotsettings proceedwithplot) ) ) (if (/= plotarea "window") (progn (command "zoom" "all" "zoom" ".95x") (command "-plot" detailedplotconfiguration layoutname plottername papersize paperunits orientation plotupsidedown plotarea plotscale plotoffset plotwithplotstyles plotstyletablename plotwithlineweights scalelineweights plotpaperspacefirst hidepaperspaceobjects writeplottofile saveplotsettings proceedwithplot) ) ) ) ) Noting that plotarea is set to window if the user clicks on the 'plot window' check box in the DCL. I found that I needed slightly different command line depends if the user was in paper or model space. All the other variables are either defined or worked out earlier in the routine. It all depends how much automation you want on the plotting how many of these are via user inputs or worked out in the LISP. Might give you another idea of what you can do Quote
BIGAL Posted July 1, 2020 Posted July 1, 2020 Like Steven P pick 2 points then pop a dcl and just pick the correct settings, here is multi radio button.lsp example code. (setq ansp (ah:butts but "V" '("Choose printer " " A3 laser" " A1 Plotter" " A3 PDF" " A1 PDF" ))) (setq ansc (ah:butts but "V" '("Choose scale" " 1:100" " 1:200" " 1:50" " 1:10" ))) (setq anss (ah:butts but "V" '("Choose printer " " A4" " A3 " " A2" " A1" ))) Multi radio buttons.lsp 1 Quote
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.