Jump to content

Recommended Posts

Posted

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)
)

 

Posted

Hi Nikon
With this code

(vl-remove-if 'listp (mapcar 'cdr (entget pline))))


you can't get the list of points

Posted

Replace it with this
 

(mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline))))

 

  • Thanks 1
Posted
1 hour ago, GLAVCVS said:

Replace it with this
 

(mapcar 'cdr (vl-remove-if-not '(lambda (x) (= (car x) 10)) (entget pline))))

Thanks, but the viewport is not being created in the sheet space, and the model space is divided into 4 viewports.

???

Posted

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")

 

  • Like 1
Posted (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 by GLAVCVS
  • Like 1
Posted (edited)

The best option is probably what BIGAL proposes
'(command "zoom" "E")'

This way you avoid having to get the list of points

Edited by GLAVCVS
Posted
6 hours ago, GLAVCVS said:

The best option is probably what BIGAL proposes
'(command "zoom" "E")'

This way you avoid having to get the list of points

 

EXCEPT, if there are more objects in the drawing, of course.

  • Thanks 1
Posted (edited)
8 hours ago, GLAVCVS said:

The best option is probably what BIGAL proposes
'(command "zoom" "E")'

This way you avoid having to get the list of points

@GLAVCVS Yes, you're right.

How to make the viewport display what is in the frame?

Edited by Nikon
Posted (edited)
8 hours ago, 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")

How to make the viewport display what is in the frame?

model.png    layout.png

Everything that is in the model's space gets into the viewport.

2025-02-25 10 02 10.png

Edited by Nikon
Posted

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.

 

Multiradio2col34.png.e8f8746b7256073461193bead0dea7a0.png

layout1.png.9d03ab6cd7fbd5b4a128c15fbe0c31bf.png

 

Happy to discuss how its done, are you metric or imperial ? There is some behind the scenes set up.

  • Like 1
Posted (edited)
8 hours ago, BIGAL said:

Happy to discuss how its done, are you metric or imperial ? ? There is some behind the scenes set up.

@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 by Nikon
Posted

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.

  • Thanks 1
Posted
16 hours ago, 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.

 

If I understand correctly, you want the 'LayOut' viewport to adapt proportionally to the selected rectangular polyline to display, by zooming, its content?

  • Thanks 1
Posted
7 hours ago, 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?

Yes, that's right.

Posted

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))
)

Multiradio2col34.png.e8f8746b7256073461193bead0dea7a0.png

 

 

  • Thanks 1
Posted (edited)
41 minutes ago, 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.

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 by Nikon
Posted

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

  • Thanks 1
Posted (edited)

 

3 hours ago, 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

I already owe 50 cups of coffee to you and Mr. BIGAL for your help, where do you want it delivered?☕✈️

Edited by Nikon
Posted
4 hours ago, 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

 

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.

  • Agree 1

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...