Author Topic: rotate multiple objects around midpoints  (Read 2273 times)

0 Members and 1 Guest are viewing this topic.

eldanimal

  • Mosquito
  • Posts: 16
rotate multiple objects around midpoints
« on: March 21, 2018, 12:05:41 PM »
I found some code to rotate objects around their basepoints....I am trying to edit the code to rotate single segment leaders around the midpoints instead.  I am not succeeding, and I would appreciate some help if anyone sees what I am doing wrong:

Code: [Select]
;* Rotate Multiple
;* Rotates many entities around their respective basepoints
;* allows selection by AUTOCAD selection sets or SSX.
;* Written by David Husch, January 1991

(defun c:rom ()
 (vl-load-com)
  (prompt "Select Entities to Rotate, <ENTER> for SSX.")
  (setq ss (ssget))
  (setq num (sslength ss))
  (setq x 0)
  (if ss
  (if (setq ang (getreal "Enter Rotation Angle: "))
  (repeat num
  (setq ename (ssname ss x))
    (setq elist (entget ename))
(setq pnt (mapcar '*(mapcar '+(cdr (assoc 10 elist)) (cdr (assoc 11 elist)) '(0.5 0.5 0.5))))
(command "_Rotate" ename "" pnt ang)
      (setq x (1+ x))
    )
  )
    )
  )


As is, it is merely returning the real number rotation angle and crapping out.

Thanks all,
Dan

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: rotate multiple objects around midpoints
« Reply #1 on: March 21, 2018, 01:51:26 PM »
Your current code will only work for Lines (whose endpoints are defined using DXF groups 10 & 11).

For single-segment leaders, use something like:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rom ( / a b e i p s x )
  2.     (if (and (setq a (getangle "\nSpecify rotation angle: "))
  3.              (setq s (ssget "_:L" '((0 . "LINE,LWPOLYLINE,LEADER"))))
  4.         )  
  5.         (repeat (setq i (sslength s))
  6.             (setq i (1- i)
  7.                   e (ssname s i)
  8.                   x (entget e)
  9.             )
  10.             (if (= "LINE" (cdr (assoc 0 x)))
  11.                 (setq p (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (cdr (assoc 10 x)) (cdr (assoc 11 x))))
  12.                 (setq p (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) x))
  13.                       p (mapcar '(lambda ( x ) (/ x (length p))) (apply 'mapcar (cons '+ p)))
  14.                 )
  15.             )
  16.             (command "_.rotate" e "" "_non" p (angtos a))
  17.         )
  18.     )
  19.     (princ)
  20. )

Does not attempt to account for UCS/View settings.
Doesn't check whether polylines/leaders are single-segmented or not.

eldanimal

  • Mosquito
  • Posts: 16
Re: rotate multiple objects around midpoints
« Reply #2 on: September 13, 2018, 10:40:55 AM »
Lee,

Thank you for this.  My apologies for not acknowledging it sooner.

Dan

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: rotate multiple objects around midpoints
« Reply #3 on: September 15, 2018, 01:56:45 PM »
You're most welcome Dan.  :-)

meja

  • Newt
  • Posts: 47
Re: rotate multiple objects around midpoints
« Reply #4 on: August 15, 2021, 08:09:20 AM »
Your current code will only work for Lines (whose endpoints are defined using DXF groups 10 & 11).

For single-segment leaders, use something like:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:rom ( / a b e i p s x )
  2.     (if (and (setq a (getangle "\nSpecify rotation angle: "))
  3.              (setq s (ssget "_:L" '((0 . "LINE,LWPOLYLINE,LEADER"))))
  4.         )  
  5.         (repeat (setq i (sslength s))
  6.             (setq i (1- i)
  7.                   e (ssname s i)
  8.                   x (entget e)
  9.             )
  10.             (if (= "LINE" (cdr (assoc 0 x)))
  11.                 (setq p (mapcar '(lambda ( a b ) (/ (+ a b) 2.0)) (cdr (assoc 10 x)) (cdr (assoc 11 x))))
  12.                 (setq p (mapcar 'cdr (vl-remove-if-not '(lambda ( x ) (= 10 (car x))) x))
  13.                       p (mapcar '(lambda ( x ) (/ x (length p))) (apply 'mapcar (cons '+ p)))
  14.                 )
  15.             )
  16.             (command "_.rotate" e "" "_non" p (angtos a))
  17.         )
  18.     )
  19.     (princ)
  20. )

Does not attempt to account for UCS/View settings.
Doesn't check whether polylines/leaders are single-segmented or not.
Hi,Lee.I want to know how to rotate texts or mtexts  in the same time around their text box center?many thx!

BIGAL

  • Swamp Rat
  • Posts: 1409
  • 40 + years of using Autocad
Re: rotate multiple objects around midpoints
« Reply #5 on: August 15, 2021, 07:52:46 PM »
If I understand correct you can use Boundingbox in a lisp and rotate around the centre of the box.

Code: [Select]
(defun c:wow ( / ent obj ang mp)
(vl-load-com)
(setq ent (car (entsel "pick object ")))
(setq obj (vlax-ename->vla-object ent))
(vla-GetBoundingBox obj 'minpoint 'maxpoint)
(setq pointmin (vlax-safearray->list minpoint))
(setq pointmax (vlax-safearray->list maxpoint))
(setq mp (mapcar '* (mapcar '+ pointmin pointmax) '(0.5 0.5)))
(setq ang (getreal "\nenter angle "))
(command "rotate" ent "" mp ang)
(princ)
)
A man who never made a mistake never made anything