Nikon Posted February 27 Author Posted February 27 (edited) On 2/27/2025 at 4:50 PM, GLAVCVS said: An important issue is the paper size of the target layout. Because, regardless of the size of the rectangle in model space, it can be adapted to the layout in paper space (with the relevant scaling considerations, of course). Forcing the code to select one paper size or another based on the size of the rectangle in model space will make the job a bit more complicated. (cond ; Format selection depending on the viewport area ((and (> Square 59251) (< Square 65488)) (vla-put-ConfigName Layout "DWG To PDF.pc3") (vla-put-CanonicalMediaName Layout "ISO_full_bleed_A4_(297.00_x_210.00_MM)")) ((and (> Square 118503) (< Square 130977)) (vla-put-ConfigName Layout "DWG To PDF.pc3") (vla-put-CanonicalMediaName Layout "ISO_full_bleed_A3_(420.00_x_297.00_MM)")) Edited March 1 by Nikon Quote
GLAVCVS Posted February 27 Posted February 27 What I mean is that any rectangle, whatever its size, can be fitted into an A4 Layout without any problem, even if it does not keep the proportions of the standard formats. Simply adjust the A4 Layout Viewport to the proportions of the rectangle taken as a reference in the model space. A zoom in the model space of this viewport will achieve the final effect. But if you have to consider the size of the rectangle selected to use one Layout or another, everything is a little more complicated. I hope I have explained myself better now. 1 Quote
Nikon Posted February 27 Author Posted February 27 (edited) 17 minutes ago, GLAVCVS said: What I mean is that any rectangle, whatever its size, can be fitted into an A4 Layout without any problem, even if it does not keep the proportions of the standard formats. I need to save scale and proportions. I want to try to do this for at least one A2 frame, for example... Edited February 27 by Nikon Quote
BIGAL Posted February 27 Posted February 27 Ok PM me I will talk via email. Yes you select scale and title block size, the title block is read from say a dwg containing all your layouts pre set up. Or can be made to match each title block that is inside the current dwg. As per code I posted all the size details are hard coded. You make say one or more rectang then just run step 2 and make the layouts. If you want different size then just run step one again. I need to see your title blocks in a dwg to work out settings. The other thing I did was a plottopdf.lsp that auto reads the title block name in a layout so matches correct plot settings again hard coded. 1 Quote
Nikon Posted February 28 Author Posted February 28 8 hours ago, BIGAL said: I need to see your title blocks in a dwg to work out settings. The other thing I did was a plottopdf.lsp that auto reads the title block name in a layout so matches correct plot settings again hard coded. Thanks, I don't need a very complicated program. I just have polyline frames A2 in the model space (there are no title blocks). I want to try to do this for at least one A2 frame, for example... Quote
Saxlle Posted February 28 Posted February 28 (edited) Hey @Nikon, If I can give you some advice. I had the same situation about 2-3 years ago, and I've been thinking about how to do automatization in creating layouts. And, I figure it out the best way (for my purpose) is to make differents "dwg" with appropriate size of viewports with accompanying "dwt" files (where are you going to have a "block" section with the name of company, number of project, name of the project, etc.). The first one is to make a different sizes of desired viewports. This one from picture 1 is for the 297x420 cm paper size. The second one is to make a "dwt" files where are you going to put your viewport inside the layout. The picture 2 show how it looks layout for the paper size 297x420 cm. The third one is coding (this is the first time when I created something using autolisp, the first program). It will look like this (this is the part from the code): (while (< i len) (setq base nil) (setq xy nil) (setq obj (ssname ss i)) (setq data1 (entget (ssname ss i))) (setq blockname (cdr (assoc 2 data1))) (cond ((= blockname L1) (setq data2 (entget (entnext (cdr (assoc -1 data1))))) (setq data3 (entget (entnext (cdr (assoc -1 data2))))) (setq data4 (entget (entnext(cdr (assoc -1 data3))))) (setq base (cdr (assoc 11 data3))) (setq xy (cdr (assoc 1 data3))) (setq no (1+ i)) (setq data4 (subst (cons 1 (itoa no)) (assoc 1 data4) data4)) (entmod data4) (setq nno (strcat v1 "." v2 "." (itoa no))) (setq path (findfile ".\\Situacioni plan saobracajne signalizacije_297x420.dwt")) (command "layout" "t" path "1") (command "layout" "s" "1") (command "layout" "r" "" nno) (command "mspace" "ucs" "ob" obj "plan" "c" "zoom" "w" base xy "pspace") ) ................... I hope I gave you some idea, it is simillar as @BIGAL proposal. Best regards. Edited February 28 by Saxlle 1 1 Quote
GLAVCVS Posted February 28 Posted February 28 (edited) 16 hours ago, Nikon said: I need to save scale and proportions. I want to try to do this for at least one A2 frame, for example... What measurements will the rectangles have in the model space and/or what should the scale be? Edited February 28 by GLAVCVS Quote
Nikon Posted February 28 Author Posted February 28 1 hour ago, GLAVCVS said: What measurements will the rectangles have in the model space and/or what should the scale be? The dimensions of the frame in the model space are 594x420mm, scale 1:1. Only one selected frame should be included in the viewport, not the entire drawing. Quote
BIGAL Posted February 28 Posted February 28 (edited) Me personally your going down the wrong path you have your title block in a layout at true size a A1 841x594 a A2 594x420, then you make your mview inside that title block, then set correct scale. The rectangs in model space are a scaled representative of the viewport size. Think about it. So again I need the size of your viewports in Each title block with the title block at true size. A A2 will be like 584x397 Did you look at the movie ? Edited February 28 by BIGAL 1 Quote
Nikon Posted March 1 Author Posted March 1 (edited) 9 hours ago, BIGAL said: Me personally your going down the wrong path you have your title block in a layout at true size a A1 841x594 a A2 594x420, then you make your mview inside that title block, then set correct scale. There are no problems with my drawings, but sometimes I have to work with old objects, where formats are created using lines (at best polylines). I wanted to get something like that. A layout named "A2-Layout" is being created, but with A4 sheet parameters, and there is "no" in the print stylesheet. The viewport is not being created. The code returns an error: invalid argument type: VLA-OBJECT nil. (defun c:CreaA2Layout ( / acadObj doc layouts newLayout pspace vp) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq layouts (vla-get-Layouts doc)) (setq newLayout (vla-Add layouts "A2-Layout")) (vla-put-ConfigName newLayout "DWG To PDF.pc3") (vla-put-StyleSheet Layout "monochrome.ctb") (vla-put-PlotType Layout 5) (vla-put-CanonicalMediaName newLayout "ISO_full_bleed_A2_594.00_x_420.00") (vla-put-PaperUnits newLayout acMillimeters) (vla-put-PlotType newLayout acExtents) (vla-put-CenterPlot newLayout :vlax-true) (vla-put-PlotRotation newLayout ac0degrees) (vla-Activate newLayout) (setq pspace (vla-get-Block newLayout)) ;; Viewport (setq vp (vla-AddObject pspace "AcDbViewport" (vlax-3D-point '(0 0 0)) ) ) (vla-put-Width vp 594) (vla-put-Height vp 420) (vla-put-DisplayLocked vp :vlax-false) (vla-put-customscale vp 1) (vla-put-DisplayLocked vp :vlax-true) (princ) ) Edited March 1 by Nikon Quote
GLAVCVS Posted March 1 Posted March 1 I've changed a few things in your code to make it work. But you'll have to adjust the viewport dimensions because you have them at maximum, at the edge of the paper. (defun c:CreaA2Layout (/ acadObj doc layouts newLayout pspace vp) (vl-load-com) (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq layouts (vla-get-Layouts doc)) (setq newLayout (vla-Add layouts "A2-Layout")) (vla-put-ConfigName newLayout "DWG To PDF.pc3") (vla-put-StyleSheet newLayout "monochrome.ctb") (vla-put-PlotType newLayout 5) (vla-put-CanonicalMediaName newLayout "ISO_full_bleed_A2_(594.00_x_420.00_mm)";"ISO_A4_(297.00_x_210.00_MM)" ) (vla-put-PaperUnits newLayout acMillimeters) (vla-put-PlotType newLayout acExtents) (vla-put-CenterPlot newLayout :vlax-true) (vla-put-PlotRotation newLayout ac0degrees) ;;; (vla-Activate newLayout) (vla-put-activeLayout doc newLayout) (setq pspace (vla-get-Block newLayout)) ;; Viewport ;;; (setq vp ;;; (vla-AddObject ;;; pspace ;;; "AcDbViewport" ;;; (vlax-3D-point '(0 0 0)) ;;; ) ;;; ) (setq vp (vlax-ename->vla-object (ssname (ssget "x" (list '(0 . "VIEWPORT") (cons 410 "A2-Layout") '(69 . 2))) 0))) (vla-put-Width vp 594) (vla-put-Height vp 420) (vla-put-DisplayLocked vp :vlax-false) (vla-put-customscale vp 1) (vla-put-DisplayLocked vp :vlax-true) (princ) ) 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.