lisp to rotate multiple objects to a central point.

lisp to rotate multiple objects to a central point.

jtm2020hyo
Collaborator Collaborator
3,918 Views
9 Replies
Message 1 of 10

lisp to rotate multiple objects to a central point.

jtm2020hyo
Collaborator
Collaborator

I need rotate multiple objects to a unique central point, no matter the way, like photos:

 

image.pngimage.png

 

 

0 Likes
Accepted solutions (1)
3,919 Views
9 Replies
Replies (9)
Message 2 of 10

dlanorh
Advisor
Advisor
Are they all the same type of object i.e. a block?
If they are blocks are they all the same block?
Will this always be the case or is this a one of a kind lisp?
The questions are endless...

I am not one of the robots you're looking for

Message 3 of 10

Satish_Rajdev
Advocate
Advocate

For quick start, let me know in case of any modification :

(defun c:test ( / e i ip s p)
  (if (and (setq s (ssget '((0 . "insert"))))
	   (setq p (getpoint "\nSpecify unique central point : "))
      )
    (repeat (setq i (sslength s))
      (setq e (ssname s (setq i (1- i))))
      (setq ip (cdr (assoc 10 (entget e))))
      (command-s "_.rotate" e "" ip "_r" ip (polar ip (* pi 0.5) 1.0) p)
    )
  )
  (princ)
)

Best Regards,
Satish Rajdev


REY Technologies | Linked IN | YouTube Channel


 

Message 4 of 10

DannyNL
Advisor
Advisor

A 'heavily' modified version of the code @Satish_Rajdev to take into account the direction of the block you want to have pointed to your central point. Yeah...I know....but I really just like the VL* commands Smiley Wink

 

In the example below the block has been defined as seen on screen, so the blocks are inserted with a rotation angle of 0. But the result should be that the north of the block is rotated to your central point, so there needs to be an offset angle to work with; in this case 90 or (0.5 * pi). In the code of @Satish_Rajdev this is a hard-coded value.
But as this may be different for different blocks, an additional input is required to provide the offset angle to work with. Effective the block offset angle specifies which side of the block should be directed to your central point and this code also takes into account the current rotation angle of the blocks.

 

AutoRotateBlocks.gif

 

(defun c:Test (/ T_Selection T_Point T_OffsetAngle T_Object T_Angle)
   (if
      (and
         (setq T_Selection (ssget '((0 . "INSERT"))))
	 (setq T_Point (getpoint "\nSpecify unique central point : "))
         (not (initget 1))
         (setq T_OffsetAngle (* pi (/ (getreal "\nOffset block angle : ") 180)))
      )
      (progn
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Object (vl-remove-if '(lambda (T_Item) (listp (cadr T_Item))) (ssnamex T_Selection))
            (setq T_Object (vlax-ename->vla-object (cadr T_Object)))         
            (setq T_Angle (angle (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint T_Object))) T_Point))
            (vla-put-Rotation T_Object (- T_Angle T_OffsetAngle))
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
   )
   (princ)
)

 

Message 5 of 10

ВeekeeCZ
Consultant
Consultant

@DannyNL wrote:

... 

In the example below the block has been defined as seen on screen, so the blocks are inserted with a rotation angle of 0. But the result should be that the north of the block is rotated to your central point, so there needs to be an offset angle to work with; in this case 90 or (0.5 * pi). In the code of @Satish_Rajdev this is a hard-coded value.

Let's say that using the (getreal) is +1. But using the (getangle) would be +2!

Message 6 of 10

DannyNL
Advisor
Advisor
Accepted solution

Haha....my bad....you are absolutely right!

Let's just say it's almost weekend and I'm already losing my edge a bit on Thursday's afternoon Smiley Wink

 

The code as it should have been the first time Smiley Happy

(defun c:Test (/ T_Selection T_Point T_OffsetAngle T_Object T_Angle)
   (if
      (and
         (setq T_Selection (ssget '((0 . "INSERT"))))
	 (setq T_Point (getpoint "\nSpecify unique central point : "))
         (not (initget 1))
         (setq T_OffsetAngle (getangle "\nOffset block angle : "))
      )
      (progn
         (vla-StartUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
         (foreach T_Object (vl-remove-if '(lambda (T_Item) (listp (cadr T_Item))) (ssnamex T_Selection))
            (setq T_Object (vlax-ename->vla-object (cadr T_Object)))         
            (setq T_Angle (angle (vlax-safearray->list (vlax-variant-value (vla-get-InsertionPoint T_Object))) T_Point))
            (vla-put-Rotation T_Object (- T_Angle T_OffsetAngle))
         )
         (vla-EndUndoMark (vla-get-ActiveDocument (vlax-get-acad-object)))
      )
   )
   (princ)
)
Message 7 of 10

jtm2020hyo
Collaborator
Collaborator

@DannyNL @ВeekeeCZ @Satish_Rajdev @dlanorh

 

thanks for the help. my max respect for all.

0 Likes
Message 8 of 10

Anonymous
Not applicable

i want to rotate more objects with mtext. see my attachment. i want rotate multiple circles +mtexts of circle's own center. not metext center. can you help me

Message 9 of 10

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

i want to rotate more objects with mtext. see my attachment. i want rotate multiple circles +mtexts of circle's own center. not metext center. can you help me


I assume from your description that these are not Blocks with Attributes [that would make it much easier].  Are those text parts each one  Mtext object with the number as subscript, or is the "D" a separate object  from the "2"?

 

[And if the center of the Circle is the rotation base point, Rotating the Circle itself serves no purpose....]

Kent Cooper, AIA
Message 10 of 10

jtm2020hyo
Collaborator
Collaborator

@Kent1Cooper wrote:

@Anonymous wrote:

i want to rotate more objects with mtext. see my attachment. i want rotate multiple circles +mtexts of circle's own center. not metext center. can you help me


I assume from your description that these are not Blocks with Attributes [that would make it much easier].  Are those text parts each one  Mtext object with the number as subscript, or is the "D" a separate object  from the "2"?

 

[And if the center of the Circle is the rotation base point, Rotating the Circle itself serves no purpose....]


 

can be added text, mtext, rtext, block with attributes and more objects to this lisp?

that would be great

0 Likes