Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Rotate multiple lines around their midpoints

12 REPLIES 12
Reply
Message 1 of 13
Anonymous
2088 Views, 12 Replies

Rotate multiple lines around their midpoints

Sorry for re-posting, but I ment midpoint instead of center.
Is it possible to select several different line entities and have them each
rotated around its midpoint, or end point, so afterwards all have the same
direction specified by a number or specified by direction of another entity?
I wish command matchprop had that rotation option in its Settings.
Thanks
Przemek
12 REPLIES 12
Message 2 of 13
Anonymous
in reply to: Anonymous

Hi ppanek,
for easy understand post here your drawing before and after revision.

"ppanek" wrote in message
news:5622906@discussion.autodesk.com...
Sorry for re-posting, but I ment midpoint instead of center.
Is it possible to select several different line entities and have them each
rotated around its midpoint, or end point, so afterwards all have the same
direction specified by a number or specified by direction of another entity?
I wish command matchprop had that rotation option in its Settings.
Thanks
Przemek
Message 3 of 13
thatcadguy
in reply to: Anonymous

(defun c:rotatespec (/ ss ang ct enlist pt1 pt2 mid dang)
(setq ss (ssget '((0 . "LINE")))
ang (getangle "\nSpecify angle:")
ct 0
)
(repeat (sslength ss)
(setq enlist (entget (ssname ss ct))
pt1 (cdr (assoc 10 enlist))
pt2 (cdr (assoc 11 enlist))
mid (polar pt1 (angle pt1 pt2) (* 0.5 (distance pt1 pt2)))
dang (angle mid pt1)
)
(command "_.rotate" (ssname ss ct) "" mid "_r" (/ (* 180.0 dang) pi) (/ (* 180.0 ang) pi))
(setq ct (1+ ct))
)
)

-----------------------
http://www.CADgasm.tk/
Message 4 of 13
v.azarko
in reply to: Anonymous

Rotates any objects around of them center BoundingBox
;Multiple Rotation
(defun c:mrot (/ ERRCOUNT MAXPT MINPT MIPT MNPT MXPT OBJSET VLAOBJ PTLST
XLST YLST)
(vl-load-com)
(if (not srot:ang)
(setq srot:ang (/ pi 2))
)
(setq oldAng srot:ang
srot:ang (getangle
(strcat "\nSpecify rotation angle <"
(angtos srot:ang)
">: "
)
)
) ; end setq
(if (null srot:ang)
(setq srot:ang oldAng)
)
(setq errCount 0
ptLst '()
) ; en setq
(while t
(princ "\nSelect objects and press Enter or Esc to Quit.")
(if
(not (setq objSet (ssget "_I")))
(setq objSet (ssget))
) ; end if
(if objSet
(progn
(setq objSet
(mapcar 'vlax-ename->vla-object
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex objSet))
)
)
)
(foreach obj objSet
(vla-GetBoundingBox obj 'MinPt 'MaxPt)
(setq mnPt (vlax-safearray->list MinPt)
mxPt (vlax-safearray->list MaxPt)
miPt (polar mnPt
(angle mnPt mxPt)
(* 0.5 (distance mnPt mxPt))
)
)
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-rotate
(list obj (vlax-3D-Point miPt) srot:ang)
)
)
(setq errCount (1+ errCount))
)
) ; end foreach
(if (/= 0 errCount)
(princ (strcat "\n"
(itoa errCount)
" objects were on locked layer! "
)
)
) ; end if
) ; end progn
) ; end if
) ; end while
(princ)
)
Message 5 of 13
Anonymous
in reply to: Anonymous

Here is small drawing

"Adesu" wrote in message
news:5622969@discussion.autodesk.com...
Hi ppanek,
for easy understand post here your drawing before and after revision.

"ppanek" wrote in message
news:5622906@discussion.autodesk.com...
Sorry for re-posting, but I ment midpoint instead of center.
Is it possible to select several different line entities and have them each
rotated around its midpoint, or end point, so afterwards all have the same
direction specified by a number or specified by direction of another entity?
I wish command matchprop had that rotation option in its Settings.
Thanks
Przemek
Message 6 of 13
Anonymous
in reply to: Anonymous

I tested this rotatespec code and it rotates all lines around their
midpoints by specified angle, instead of rotating them so they all have the
same direction after rotation. Please see attached drawing to Adesu
response.



wrote in message news:5623098@discussion.autodesk.com...
(defun c:rotatespec (/ ss ang ct enlist pt1 pt2 mid dang)
(setq ss (ssget '((0 . "LINE")))
ang (getangle "\nSpecify angle:")
ct 0
)
(repeat (sslength ss)
(setq enlist (entget (ssname ss ct))
pt1 (cdr (assoc 10 enlist))
pt2 (cdr (assoc 11 enlist))
mid (polar pt1 (angle pt1 pt2) (* 0.5 (distance pt1 pt2)))
dang (angle mid pt1)
)
(command "_.rotate" (ssname ss ct) "" mid "_r" (/ (* 180.0 dang) pi) (/
(* 180.0 ang) pi))
(setq ct (1+ ct))
)
)

-----------------------
http://www.CADgasm.tk/
Message 7 of 13
Anonymous
in reply to: Anonymous

I tested this mrot code and it rotates all lines around their
midpoints by specified angle, instead of rotating them so they all have the
same direction after rotation. Please see attached drawing to Adesu
response.

wrote in message news:5623306@discussion.autodesk.com...
Rotates any objects around of them center BoundingBox
;Multiple Rotation
(defun c:mrot (/ ERRCOUNT MAXPT MINPT MIPT MNPT MXPT OBJSET VLAOBJ PTLST
XLST YLST)
(vl-load-com)
(if (not srot:ang)
(setq srot:ang (/ pi 2))
)
(setq oldAng srot:ang
srot:ang (getangle
(strcat "\nSpecify rotation angle <"
(angtos srot:ang)
">: "
)
)
) ; end setq
(if (null srot:ang)
(setq srot:ang oldAng)
)
(setq errCount 0
ptLst '()
) ; en setq
(while t
(princ "\nSelect objects and press Enter or Esc to Quit.")
(if
(not (setq objSet (ssget "_I")))
(setq objSet (ssget))
) ; end if
(if objSet
(progn
(setq objSet
(mapcar 'vlax-ename->vla-object
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex objSet))
)
)
)
(foreach obj objSet
(vla-GetBoundingBox obj 'MinPt 'MaxPt)
(setq mnPt (vlax-safearray->list MinPt)
mxPt (vlax-safearray->list MaxPt)
miPt (polar mnPt
(angle mnPt mxPt)
(* 0.5 (distance mnPt mxPt))
)
)
(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-rotate
(list obj (vlax-3D-Point miPt) srot:ang)
)
)
(setq errCount (1+ errCount))
)
) ; end foreach
(if (/= 0 errCount)
(princ (strcat "\n"
(itoa errCount)
" objects were on locked layer! "
)
)
) ; end if
) ; end progn
) ; end if
) ; end while
(princ)
)
Message 8 of 13
Anonymous
in reply to: Anonymous

Please disregard my previous response, it was for V.Azarko but I used your
command name.

I tested this rotatespec code and it rotates all lines to one specified
direction, but each line is rotated around some unspecified point, instead
of each line's midpoint. Please see attached drawing to Adesu
response. Thanks.



wrote in message news:5623098@discussion.autodesk.com...
(defun c:rotatespec (/ ss ang ct enlist pt1 pt2 mid dang)
(setq ss (ssget '((0 . "LINE")))
ang (getangle "\nSpecify angle:")
ct 0
)
(repeat (sslength ss)
(setq enlist (entget (ssname ss ct))
pt1 (cdr (assoc 10 enlist))
pt2 (cdr (assoc 11 enlist))
mid (polar pt1 (angle pt1 pt2) (* 0.5 (distance pt1 pt2)))
dang (angle mid pt1)
)
(command "_.rotate" (ssname ss ct) "" mid "_r" (/ (* 180.0 dang) pi) (/
(* 180.0 ang) pi))
(setq ct (1+ ct))
)
)

-----------------------
http://www.CADgasm.tk/
Message 9 of 13
v.azarko
in reply to: Anonymous

;Rotates Line objects around of them center BoundingBox
;Multiple Rotation Line on Absolute Angle
(defun c:mrotL (/ ERRCOUNT MAXPT MINPT MIPT MNPT MXPT OBJSET VLAOBJ PTLST
XLST YLST ANG)
;-------------------------------------------
;; Argument: angle in radians, any number including negative.
;; Returns: normalized angle in radians between zero and (* pi 2)
(defun NormalAngle (a)
(if (numberp a)
(angtof (angtos a 0 14) 0))
)
(vl-load-com)
(if (not srot:ang)
(setq srot:ang (/ pi 2))
)
(setq oldAng srot:ang
srot:ang (getangle
(strcat "\nSpecify absolute angle <"
(angtos srot:ang)
">: "
)
)
) ; end setq
(if (null srot:ang)
(setq srot:ang oldAng)
)
(setq errCount 0
ptLst '()
) ; en setq
(princ "\nSelect Line objects and press Enter.")
(if
(not (setq objSet (ssget "_I" '((0 . "LINE")))))
(setq objSet (ssget '((0 . "LINE"))))
) ; end if
(if objSet
(progn
(sssetfirst)
(setq objSet
(vl-remove-if
'listp
(mapcar 'cadr (ssnamex objSet))
)
)

(foreach obj objSet
(setq mnPt (cdr(assoc 10 (entget obj)))
mxPt (cdr(assoc 11 (entget obj)))
miPt (polar mnPt (angle mnPt mxPt)
(* 0.5 (distance mnPt mxPt)))
Ang (- srot:ang (angle mnPt mxPt))
Ang (NormalAngle Ang)
)

(if
(vl-catch-all-error-p
(vl-catch-all-apply
'vla-rotate
(list (vlax-ename->vla-object obj) (vlax-3D-Point miPt) ang)
)
)
(setq errCount (1+ errCount))
)
) ; end foreach
(if (/= 0 errCount)
(princ (strcat "\n"
(itoa errCount)
" objects were on locked layer! "
)
)
) ; end if
) ; end progn
) ; end if
(princ)
)
(princ "\nType MrotL in command line")
Message 10 of 13
thatcadguy
in reply to: Anonymous

it rotates them around the midpoint on my computer, and it should on yours unless you modified my code
Message 11 of 13
wolffeelings
in reply to: v.azarko

This code worked very good for me. Thanks a lot!

Message 12 of 13
Kent1Cooper
in reply to: wolffeelings


@wolffeelings wrote:

This code worked very good for me. Thanks a lot!


v.azarko may not still be around, but....

 

I looked that over, and noticed some things that could be done more simply, and what seemed like some shortcomings, and came up with the attached RotateLinesAbsAng.lsp and its RLAA command.  Aside from being shorter, some of the functional differences are:

 

Lines on locked Layers can be filtered out during selection, reporting on any that it finds in the selection process, rather than trying to rotate them, counting up the errors that result from those on locked Layers, and reporting the count of those afterwards.

 

Theirs asks for the angle after selection in the pre-selected-items [noun-verb] mode [obviously], but before selection in the verb-noun mode.  Mine asks for it after selection in both cases, which is also more analagous to the way regular Rotate works.

 

In noun-verb mode, theirs keeps all pre-selected items highlighted, even those that are not Lines or are on locked Layers and therefore won't be rotated, while asking for the angle.  In verb-noun mode, it highlights even Lines that are on locked Layers during selection.  Mine shows only the Lines that will be rotated highlighted, in both modes.

 

If you type U after using theirs, it doesn't undo just what that command did, but goes back past that to undo whatever previous command you did!  Using U after mine undoes its own operations only.

 

And some other little things....

Kent Cooper, AIA
Message 13 of 13
wolffeelings
in reply to: Kent1Cooper

Thanks a lot! I will try it out! 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

”Boost