Code Red > AutoLISP (Vanilla / Visual)

simple rotate function

(1/3) > >>

hyposmurf:
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:

--- Quote from: hyposmurf on October 17, 2006, 08:13:41 AM ---automatically use the midpoint of the objects slelected for the basepoint
--- End quote ---

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.

CAB:
For ideas on rotate look at these
http://www.theswamp.org/index.php?topic=2787.0

http://www.theswamp.org/index.php?topic=2089.0

For a bounding box look at these
http://www.theswamp.org/index.php?topic=2088.msg26617#msg26617

http://www.theswamp.org/index.php?topic=5909.msg73376#msg73376

Why not post your code & someone will help you work through it.

CAB:
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: ---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
--- End code ---


Out of time here got to run.

CAB:
Hummm, talking to my self again, not a good sign. :-o

Here is a simple routine do do what you wanted.


--- Code: ---;;  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)
)
--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version