Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*ppanek
Message 1 of 13 (369 Views)

Rotate multiple lines around their midpoints

369 Views, 12 Replies
06-11-2007 02:59 PM
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
*Adesu
Message 2 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-11-2007 05:29 PM in reply to: *ppanek
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
Distinguished Contributor
thatcadguy
Posts: 856
Registered: ‎04-27-2007
Message 3 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-11-2007 09:56 PM in reply to: *ppanek
(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/
Contributor
v.azarko
Posts: 17
Registered: ‎06-12-2007
Message 4 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 05:22 AM in reply to: *ppanek
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)
)
*ppanek
Message 5 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 07:46 AM in reply to: *ppanek
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
*ppanek
Message 6 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 07:54 AM in reply to: *ppanek
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/
*ppanek
Message 7 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 07:57 AM in reply to: *ppanek
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)
)
*ppanek
Message 8 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 08:01 AM in reply to: *ppanek
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/
Contributor
v.azarko
Posts: 17
Registered: ‎06-12-2007
Message 9 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 09:04 AM in reply to: *ppanek
;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")
Distinguished Contributor
thatcadguy
Posts: 856
Registered: ‎04-27-2007
Message 10 of 13 (369 Views)

Re: Rotate multiple lines around their midpoints

06-12-2007 06:15 PM in reply to: *ppanek
it rotates them around the midpoint on my computer, and it should on yours unless you modified my code

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community