Nikon Posted February 24 Posted February 24 I want to create a viewport in the space of a layout, the dimensions of which are equal to the specified polyline frame. But I get an error. Select a polyline: ; error: invalid argument type: consp <Object name: 7fffef13920> (defun c:crViewportFromPL ( / pts minPt maxPt width height) (setq pline (car (entsel "\nSelect a polyline: "))) (if (and pline (= (cdr (assoc 0 (entget pline))) "LWPOLYLINE")) (progn (setq pts (vl-remove-if 'listp (mapcar 'cdr (entget pline)))) (setq minPt (list (apply 'min (mapcar 'car pts)) (apply 'min (mapcar 'cadr pts)))) (setq maxPt (list (apply 'max (mapcar 'car pts)) (apply 'max (mapcar 'cadr pts)))) (setq width (- (car maxPt) (car minPt)))) (setq height (- (cadr maxPt) (cadr minPt)))) (command "_.-VPORTS" "_M" "1" "1" "0" "0" width height) ) ) (princ) ) Quote
GLAVCVS Posted February 24 Posted February 24 Hi Nikon With this code (vl-remove-if 'listp (mapcar 'cdr (entget pline)))) you can't get the list of points Quote
GLAVCVS Posted February 24 Posted February 24 Replace it with this (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline)))) 1 Quote
Nikon Posted February 24 Author Posted February 24 On 2/24/2025 at 7:24 PM, GLAVCVS said: Replace it with this (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline)))) Expand Thanks, but the viewport is not being created in the sheet space, and the model space is divided into 4 viewports. ??? Quote
BIGAL Posted February 24 Posted February 24 Maybe use (setq pline (car (entsel "\nPick pline "))) (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline))))) (command "Mview" (car pts)(caddr pts)) (command "Mspace") (command "Zoom" "E") 1 Quote
GLAVCVS Posted February 24 Posted February 24 (edited) (defun c:crViewportFromPL ( / pts minPt maxPt width height lst) (setq pline (car (entsel "\nSelect a polyline: "))) (if (and pline (= (cdr (assoc 0 (entget pline))) "LWPOLYLINE")) (progn (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline)))) (setq minPt (list (apply 'min (mapcar 'car pts)) (apply 'min (mapcar 'cadr pts)))) (setq maxPt (list (apply 'max (mapcar 'car pts)) (apply 'max (mapcar 'cadr pts)))) (setq width (- (car maxPt) (car minPt))) ) (setq height (- (cadr maxPt) (cadr minPt))) ) (if (setq lst (layoutlist)) (progn (setvar 'CTAB (car lst)) (vl-cmdf "_zoom" "_w" minPt maxPt) ) ) ;;; (command "_.-VPORTS" "_M" "1" "1" "0" "0" width height) ) Edited February 24 by GLAVCVS 1 Quote
GLAVCVS Posted February 24 Posted February 24 (edited) The best option is probably what BIGAL proposes '(command "zoom" "E")' This way you avoid having to get the list of points Edited February 24 by GLAVCVS Quote
GLAVCVS Posted February 25 Posted February 25 On 2/24/2025 at 10:18 PM, GLAVCVS said: The best option is probably what BIGAL proposes '(command "zoom" "E")' This way you avoid having to get the list of points Expand EXCEPT, if there are more objects in the drawing, of course. 1 Quote
Nikon Posted February 25 Author Posted February 25 (edited) On 2/24/2025 at 10:18 PM, GLAVCVS said: The best option is probably what BIGAL proposes '(command "zoom" "E")' This way you avoid having to get the list of points Expand @GLAVCVS Yes, you're right. How to make the viewport display what is in the frame? Edited February 25 by Nikon Quote
Nikon Posted February 25 Author Posted February 25 (edited) On 2/24/2025 at 10:13 PM, BIGAL said: Maybe use (setq pline (car (entsel "\nPick pline "))) (setq pts (mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline))))) (command "Mview" (car pts)(caddr pts)) (command "Mspace") (command "Zoom" "E") Expand How to make the viewport display what is in the frame? Everything that is in the model's space gets into the viewport. Edited February 25 by Nikon Quote
BIGAL Posted February 25 Posted February 25 Ok once you make a viewport you need to zoom to a point inside Mspace, you can set the scale of the viewport also in this 2 step process. (command "zoom" "C" (getpoint '\PIck center point ") 100) (command "zoom" (strcat (rtos scale 2 2) "XP) When you zoom C it sets the viewport centre point, using scaleXP ie 4XP resets the viewport scale but keeps the centre point. If you have rectangs in Model space then yes can make layouts that match. You need to start with something like this. I have made rectangs that follow a pline. The software finds them and makes layouts. Another version allows user placement, both methods can be used then layouts made. Happy to discuss how its done, are you metric or imperial ? There is some behind the scenes set up. 1 Quote
Nikon Posted February 26 Author Posted February 26 (edited) On 2/25/2025 at 9:43 PM, BIGAL said: Happy to discuss how its done, are you metric or imperial ? ? There is some behind the scenes set up. Expand @BIGAL Thanks. Yes, I'm very interested. I use the metric system. But first, I would like to understand with a simple example how to get a viewport based on the selected frame. For example, I have 3 frames in my model. I want to select one frame and get a viewport in the layout space that displays only the selected frame, not the entire drawing. And with the option to choose the scale. Edited February 26 by Nikon Quote
BIGAL Posted February 26 Posted February 26 You do it in reverse to what you asked. you enter scale 1st. Then draw a rectang that matches the viewport in the layout scaled up or down to match scale. The other way is just pick a pt and use ZOOM C PT scale when in mspace use a dummy value for scale, then use zoom scXP the sc is simple for metres (setq sc (/ 1000 requiredscale) ) similar for mm a factor of 1000. The rotated rectangs answer will cost you a cup of coffee, as need to set up the rectang size to match say choices in paper size. 1 Quote
GLAVCVS Posted February 26 Posted February 26 On 2/26/2025 at 6:17 AM, Nikon said: @BIGAL Thanks. Yes, I'm very interested. I use the metric system. But first, I would like to understand with a simple example how to get a viewport based on the selected frame. For example, I have 3 frames in my model. I want to select one frame and get a viewport in the layout space that displays only the selected frame, not the entire drawing. And with the option to choose the scale. Expand If I understand correctly, you want the 'LayOut' viewport to adapt proportionally to the selected rectangular polyline to display, by zooming, its content? 1 Quote
Nikon Posted February 27 Author Posted February 27 On 2/26/2025 at 10:33 PM, GLAVCVS said: If I understand correctly, you want the 'LayOut' viewport to adapt proportionally to the selected rectangular polyline to display, by zooming, its content? Expand Yes, that's right. Quote
BIGAL Posted February 27 Posted February 27 I did give you an answer if you want rectangs start with the Viewport rectang the width and height in your layout title block. Then you draw the rectang to suit using the scale factor. Look at this front end. The match rotation part will cost you a coffee. (cond ((and (= sz "A0")(= orien "Landscape")) (setq ht 780.0 wid 1160.0 xpt 878.0 xwid 62.0 yht 32.0)) ((and (= sz "A1")(= orien "Landscape")) (setq Ht 541.0 wid 831.0 xpt 542.0 xwid 62.0 yht 32.0)) ((and (= sz "A1")(= orien "Portrait")) (setq Ht 774.0 wid 571.0 xpt 229.0 xwid 62.0 yht 32.0)) ((and (= sz "A2")(= orien "Landscape")) (setq ht 367.0 wid 584.0 xpt 295.5 xwid 62.0 yht 32.0)) ((and (= sz "A2")(= orien "Portrait")) (setq ht 554.0 wid 410.0 xpt 209.5 xwid 41.0 yht 23.0)) ((and (= sz "A3")(= orien "Landscape")) (setq ht 247.0 wid 400.0 xpt 200.0 xwid 41.0 yht 23.0)) ((and (= sz "A3")(= orien "Portrait")) ( close-drawrecs)) ((= sz "A4") (setq ht 180.0 wid 287.0)) ) Draw rectangs.mp4Fetching info... 1 Quote
Nikon Posted February 27 Author Posted February 27 (edited) On 2/27/2025 at 8:06 AM, BIGAL said: I did give you an answer if you want rectangs start with the Viewport rectang the width and height in your layout title block. Then you draw the rectang to suit using the scale factor. Look at this front end. The match rotation part will cost you a coffee. Expand I guess my English is really bad. I have A2, A3 frames in the model space... I want to select a frame and get a VP in the layout space of an A2 or A3 sized shit that displays the contents of one selected frame. No turns are needed yet... Edited February 27 by Nikon Quote
GLAVCVS Posted February 27 Posted February 27 As Bigal says, unless you already have code for this, writing a tool like that is well worth 1 coffee. Or 2. I'll try to write something when I have enough time. Unless someone already has something to do this and is generous enough to share it 1 Quote
Nikon Posted February 27 Author Posted February 27 (edited) On 2/27/2025 at 9:13 AM, GLAVCVS said: As Bigal says, unless you already have code for this, writing a tool like that is well worth 1 coffee. Or 2. I'll try to write something when I have enough time. Unless someone already has something to do this and is generous enough to share it Expand I already owe 50 cups of coffee to you and Mr. BIGAL for your help, where do you want it delivered? Edited February 27 by Nikon Quote
GLAVCVS Posted February 27 Posted February 27 On 2/27/2025 at 8:47 AM, Nikon said: I guess my English is really bad. I have A2, A3 frames in the model space... I want to select a frame and get a VP in the layout space of an A2 or A3 sized shit that displays the contents of one selected frame. No turns are need Expand 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. 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.