Author Topic: simple rotate function  (Read 3111 times)

0 Members and 1 Guest are viewing this topic.

hyposmurf

  • Guest
simple rotate function
« on: October 17, 2006, 08:13:41 AM »
I'm simply looking for a couple of lisps that will rotate objects by preset values like -90,90,180 degrees etc.Heres what I'd like he lisp to do:

Initiate the rotate command
ask user to select the objects to be rotated
automatically use the midpoint of the objects slelected for the basepoint
rotate the objects a specified angle
Ive tried doing this myself and just get to the point of specifying the basepoint,just want this part to be automatic not have to pick the point.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: simple rotate function
« Reply #1 on: October 17, 2006, 08:22:44 AM »
automatically use the midpoint of the objects slelected for the basepoint

Just to clarify, you are rotating the group selected as a whole based on the groups center.
Use of the bounding box may get you what you want here.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: simple rotate function
« Reply #2 on: October 17, 2006, 08:31:48 AM »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: simple rotate function
« Reply #3 on: October 17, 2006, 08:54:14 AM »
Taking your pseudo code a step farther:
Start Your rotate routine
ask user to select the objects to be rotated
ask user for rotation angle using get keyword
calculate the bounding box center
rotate the ss as a whole
done


Code: [Select]
Start Your rotate routine
    not much to do here
ask user to select the objects to be rotated
   prompt the user
   use ssget to collect the objects
ask user for rotation angle using getint - getkword won't work with numbers
   (setq ans (getint "\nEnter the rotation angle [90\180\270] "))
calculate the bounding box center
   (setq cen (get_bb_cen ss)) ; use one of the bb center routines
rotate the ss as a whole
   use the rotate command
done


Out of time here got to run.
« Last Edit: October 17, 2006, 11:38:51 AM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: simple rotate function
« Reply #4 on: October 17, 2006, 12:16:21 PM »
Hummm, talking to my self again, not a good sign. :-o

Here is a simple routine do do what you wanted.

Code: [Select]
;;  By CAB 10/17/06
;;  Rotate a ss at center of ss by user angle
(defun c:rotatess (/ ss ll-ur cenpt rang)
  ;;  This is my variation of a routine by Joe Burke
  ;;  returns a point list ((lower left)(upper right))
  (defun ssboundingbox (ss / i ent lst ptlst mnpt mxpt)
    (setq i -1)
    (while (setq ent (ssname ss (setq i (1+ i))))
      (setq lst (cons (vlax-ename->vla-object ent) lst))
    )
    (mapcar '(lambda (x)
               (vla-getboundingbox x 'mnpt 'mxpt)
               (setq ptlst (cons (vlax-safearray->list mnpt) ptlst))
               (setq ptlst (cons (vlax-safearray->list mxpt) ptlst))
             )
            lst
    )
     ;following by Tony Tanzillo
    (list
      (apply 'mapcar (cons 'min ptlst))
      (apply 'mapcar (cons 'max ptlst))
    )
  )

  ;;  Start here
  (prompt "\nSelect objects to rotate")
  (if (setq ss (ssget))
    (progn
      (setq ll-ur (ssboundingbox ss))
      (setq cenpt (polar (car ll-ur)
                         (angle (car ll-ur) (cadr ll-ur))
                         (/ (distance (car ll-ur) (cadr ll-ur)) 2)))
      (while
        (progn
          (setq rang
                 (cond ((getint "\nEnter the rotation angle [90/180/270] <90>"))
                       (90)))
          (if (not (vl-position rang '(90 180 270 -90)))
            (not (prompt "\nError  Angle must be 90 180 270, please re-enter.")))
        )
      )
      ;;(command "_.rotate" ss "" "_non" cenpt rang)
      ;;  Vla-rotate
      (setq rang  (/ (* rang pi) 180.0)) ; deg to rad
      (setq cenpt (vlax-3D-point cenpt))
      (setq i -1)
      (while (setq ent (ssname ss (setq i (1+ i))))
        (vla-rotate (vlax-ename->vla-object ent) cenpt rang)
      )

    )
  )
  (princ)
)
« Last Edit: October 17, 2006, 02:05:20 PM by CAB »
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

hyposmurf

  • Guest
Re: simple rotate function
« Reply #5 on: October 19, 2006, 08:02:11 AM »
No CAB your not going mad,  :-)I just have limited time lately to do anything!
Thanks alot for your help that last routine is pretty cool.What I was hoping to do was have one lisp for rotating -90 another for 90 and another for -180 and 180 etc that way it would then work alot faster.Maybe if I make copies of the lisp and change the highlighted bit of code

(cond ((getint "\nEnter the rotation angle [90/180/270] <90>"))
                       (90)))

to the desired value,though I'd have to hit return each time how would I get around this?Once again thanks :wink:


CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: simple rotate function
« Reply #6 on: October 19, 2006, 08:31:10 AM »
OK, Here is a variation

Code: [Select]
;;  The following are the command line pre set rotate routines
(defun c:ss90()
  (rotatess 90)
  (princ)
)
(defun c:ss180()
  (rotatess 180)
  (princ)
)
(defun c:ss-90()
  (rotatess 270)
  (princ)
)

(defun c:ss270()
  (rotatess 270)
  (princ)
)

;; the following works line this
;;  you enter rss <space key> <number> <enter>
(defun c:rss(/ ang)
      (while
        (progn
          (setq ang
                 (cond ((getint "\nEnter the rotation angle [90/180/270] <90>"))
                       (90)))
          (if (not (vl-position ang '(90 180 270 -90)))
            (not (prompt "\nError  Angle must be 90 180 270, please re-enter.")))
        )
      )
  (rotatess ang)
  (princ)
)



;;  By CAB 10/18/06
;;  Rotate a ss at center of ss by angle argument
(defun rotatess ( rang / ss ll-ur cenpt rang)
  ;;  This is my variation of a routine by Joe Burke
  ;;  returns a point list ((lower left)(upper right))
  (defun ssboundingbox (ss / i ent lst ptlst mnpt mxpt)
    (setq i -1)
    (while (setq ent (ssname ss (setq i (1+ i))))
      (setq lst (cons (vlax-ename->vla-object ent) lst))
    )
    (mapcar '(lambda (x)
               (vla-getboundingbox x 'mnpt 'mxpt)
               (setq ptlst (cons (vlax-safearray->list mnpt) ptlst))
               (setq ptlst (cons (vlax-safearray->list mxpt) ptlst))
             )
            lst
    )
     ;following by Tony Tanzillo
    (list
      (apply 'mapcar (cons 'min ptlst))
      (apply 'mapcar (cons 'max ptlst))
    )
  )

  ;;  Start here
  (prompt (strcat  "\nSelect objects to rotate " (itoa rang) " deg."))
  (if (setq ss (ssget))
    (progn
      (setq ll-ur (ssboundingbox ss))
      (setq cenpt (polar (car ll-ur)
                         (angle (car ll-ur) (cadr ll-ur))
                         (/ (distance (car ll-ur) (cadr ll-ur)) 2)))
      ;;(command "_.rotate" ss "" "_non" cenpt rang)
      ;;  Vla-rotate
      (setq rang  (/ (* rang pi) 180.0)) ; deg to rad
      (setq cenpt (vlax-3D-point cenpt))
      (setq i -1)
      (while (setq ent (ssname ss (setq i (1+ i))))
        (vla-rotate (vlax-ename->vla-object ent) cenpt rang)
      )

    )
  )
  (princ)
)


PS angles 180 and -180 are the same  :-)
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Joe Burke

  • Guest
Re: simple rotate function
« Reply #7 on: October 19, 2006, 11:10:22 AM »
Might be of interest?

Code: [Select]
(defun c:RotateAtPoint ( / a pt p1 p2 ssc)
  (if
    (and
      (setq a (getangle "\nKeyin angle or pick two points: "))
      (setq pt (getpoint "\nPick rotation point: "))
      (setq p1 (polar pt (* pi 1.75) 0.05)
            p2 (polar pt (* pi 0.75) 0.05)
            ssc (ssget "C" p1 p2)
      )
    )
    (command "._rotate" ssc "" pt (angtos a 0 14))
  )
  (princ)
) ;end

hyposmurf

  • Guest
Re: simple rotate function
« Reply #8 on: October 20, 2006, 04:45:16 PM »


PS angles 180 and -180 are the same  :-)

Engage brain before typing  :-D.

I'll both those routines on Monday as Im CADless at home at moment.Thanks
« Last Edit: October 20, 2006, 04:46:38 PM by hyposmurf »

hyposmurf

  • Guest
Re: simple rotate function
« Reply #9 on: October 23, 2006, 08:06:14 AM »
Sweet CAB thats exactly what I was looking for  8-).Thank you oh lisp guru.
I wouldnt have been able to come up with that in a million years. :-)

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: simple rotate function
« Reply #10 on: October 23, 2006, 08:13:09 AM »
You're welcome.
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.