Move a Rectangle Using the Top Left Corner to an Assigned Coordinate

Move a Rectangle Using the Top Left Corner to an Assigned Coordinate

Anonymous
Not applicable
1,013 Views
2 Replies
Message 1 of 3

Move a Rectangle Using the Top Left Corner to an Assigned Coordinate

Anonymous
Not applicable

In our layout tab we have multiple viewports already assigned and displayed. To apply them to the layout we simply select the viewport we need and move it to our title block using endpoint snaps. The location of the title block never moves. I would like to have routine that will allow me to select the desired viewport and automatically select the top left corner of the viewport box and then move it to the correct location on the block.

 

Currently my code is:

 

(defun c:mvp ();moves selected viewport to the correct location on the title block
    (setvar "osmode" 1)
    (command "move" (ssget) "" (getpoint "\nSelect Top Left Corner as Base Point") "-22.55050,-16.50248,0")
    (setvar "osmode" 4607)
    (princ)
)

 

Which works well, but instead of having to select the base point I would like to it select the top left corner automatically once the object is selected.

 

How do I calculate where that corner will be when I may have multiple viewports at different locations?

 

4-24-2017 9-26-45 AM.png

0 Likes
Accepted solutions (1)
1,014 Views
2 Replies
Replies (2)
Message 2 of 3

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

... instead of having to select the base point I would like to it select the top left corner automatically once the object is selected.

 

How do I calculate where that corner will be when I may have multiple viewports at different locations?

 


It stores the center point of a Viewport in the 10-code entry in entity data, the width in the 40-code entry, and the height in the 41-code entry.  In simplest terms [untested]:

 

....

(setq

  vp (car (entsel "\nSelect Viewport: "))

  vpdata (entget vp)

  vpmid (cdr (assoc 10 vpdata)); midpoint

); setq

(command "move" vp ""

  (list

    (- (car vpmid) (/ (cdr (assoc 40 vpdata)) 2)); X coordinate

    (+ (cadr vpmid) (/ (cdr (assoc 41 vpdata)) 2)); Y coordinate

  ); list

  "-22.55050,-16.50248,0"

); command

....

Kent Cooper, AIA
Message 3 of 3

Anonymous
Not applicable

Thank you so much! Works like a charm!

0 Likes