Move a drawing to 0,0

Move a drawing to 0,0

ccsmith25
Contributor Contributor
651 Views
5 Replies
Message 1 of 6

Move a drawing to 0,0

ccsmith25
Contributor
Contributor

I would like to ask for your support to get a lisp file to automatize the following process.

About a random drawing we could identify the min and max boundary points.

getvar "extmin", getvar "extmax".

 

Form these points the center of the drawing could be determined. Than it should be solved that the center of the drawing moved to the 0,0 coordinate.

 

Thanks for any solution in this topic.

0 Likes
Accepted solutions (1)
652 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

The EXTMIN and EXTMAX System Variables expand as new things are drawn farther outboard, but they don't pull back when things are removed until a Zoom All or Zoom Extents.  So if you need to do that first, then after a Zoom Extents you can just use the VIEWCTR System Variable for Moving, and don't need to calculate the middle of the drawn elements.

 

(defun C:MA00 () ; = Move All to 0,0 [those are zeroes, not the letter O]

  (command

    "_.zoom" "_extents"

    "_.move" "_all" "" "_non" (getvar 'viewctr) "_non" "0,0,0"

    "_.zoom" "_c" "_non" "0,0" ""

  )

  (princ)

)

 

[Spelling out the "_center" option in Zoom, or just "_cen", is taken as an Osnap call....]

Kent Cooper, AIA
0 Likes
Message 3 of 6

ccsmith25
Contributor
Contributor

Thank you. Your solution is what I am looking for.

0 Likes
Message 4 of 6

calderg1000
Mentor
Mentor

Regards @ccsmith25 

Try this code with Getvar extmin, extmax.
Although I think it would be better to apply (Vla-getboundingbox min max) and then
get the minimum and maximum points of the bounding rectangle of the selection of objects

 

(defun c:mm (/ i j x y)
  (setq i (getvar 'extmin)
        j (getvar 'extmax)
  )
  (vl-cmdf "_rectangle" i j)
  (vl-cmdf "_move"
           (ssget "_c" i j) ""
           "non"
           (mapcar '(lambda (x y) (/ (+ x y)2)) i j)
           "non"
           '(0. 0. 0.)
  )
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes
Message 5 of 6

Sea-Haven
Mentor
Mentor

Have a look at this Minimum Bounding Box | Lee Mac Programming (lee-mac.com)

 

Be careful with extmax, min as you can have like a object at some obscure point so a center will take that into account. Selecting what you want to reference and use lee-mac program to work out Min pt of box then use extmax extmin to reselect objects and move min pt box to 0,0. I dont like working in -ve values.

0 Likes
Message 6 of 6

calderg1000
Mentor
Mentor

Dear @ccsmith25 

I have verified that extmin, extmax, tend to be unpredictable and require a zoom extension to work well.
If you have objects outside of the current view, it is recommended that you place them on a frozen layer before applying the routine.
The rectangle drawn is just to check the location of the center of the objects moved to '(0. 0. 0.)

 

(defun c:mm (/ i j x y)
  (vl-cmdf "_zoom" "e")
  (setq i (getvar 'extmin)
        j (getvar 'extmax)
  )
  (vl-cmdf "_rectangle" "non" i "non" j)
  (vl-cmdf "_move"
           (ssget "_c" i j)
           ""
           "non"
           (mapcar '(lambda (x y) (/ (+ x y) 2)) i j)
           "non"
           '(0. 0. 0.)
           "_zoom"
           "c"
           "non"
           '(0. 0. 0.)
           ""
  )
)

 

 


Carlos Calderon G
EESignature
>Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

0 Likes