TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Andrea on November 11, 2009, 09:28:10 AM

Title: lastpoint on rotate
Post by: Andrea on November 11, 2009, 09:28:10 AM
Hi all..

any one have an idea on how to get the last point when we make ROTATE ?   :|
Title: Re: lastpoint on rotate
Post by: efernal on November 11, 2009, 10:11:33 AM
did you try
(getvar "LASTPOINT")
?

ef
Title: Re: lastpoint on rotate
Post by: Andrea on November 11, 2009, 10:20:48 AM
did you try
(getvar "LASTPOINT")
?

ef

LASTPOINT return the rotation basepoint not the last one..

Title: Re: lastpoint on rotate
Post by: efernal on November 11, 2009, 11:25:49 AM
if the rotation angle is get by clicking another point, this one will be the last...

ef
Title: Re: lastpoint on rotate
Post by: Andrea on November 11, 2009, 12:09:13 PM
if the rotation angle is get by clicking another point, this one will be the last...

ef



that what i've thougth...but
.....the LASTPOINT give me the basepoint of rotation
Title: Re: lastpoint on rotate
Post by: CAB on November 11, 2009, 02:15:46 PM
Create your own Rotate command. :)
Title: Re: lastpoint on rotate
Post by: Andrea on November 11, 2009, 04:29:14 PM
Create your own Rotate command. :)


 :?
Title: Re: lastpoint on rotate
Post by: CAB on November 11, 2009, 06:46:11 PM
Try this, quick & dirty. 8-)
Code: [Select]
;;  CAB 11.11.09
;;  Simulate the rotate command
(defun Rotate (ss BasePoint / ip ObjList i ename ip grr
               ANG BPT LASTROT OBJANG ROT STARTANG)
  (defun GroupRotate (objects bpt ang)
    (setq bpt (vlax-3D-point bpt))
    (mapcar (function (lambda (x) (vla-rotate x bpt ang))) Objects)
  )

  (setq ObjAng 0.0
        rot 0.0
  )
  (setq StartAng ObjAng)      ; save angle before rotation begins
  (setq i -1)
  (while (setq ename (ssname ss (setq i (1+ i))))
    (setq ObjList (cons (vlax-ename->vla-object ename) ObjList))
  )

  (while (progn
           (redraw)
           (cond
             ((eq 3 (car (setq grr (grread T 15 0))))
              (setq ip (cadr grr))
              nil
             )

             ((and (eq 2 (car grr)) (eq 13 (cadr grr)))
              (GroupRotate ObjList BasePoint (- StartAng LastRot))
              (setq ip nil)
             )

             ((eq 5 (car grr)) ; point from mouse, update star
              (setq rot (angle BasePoint (trans (setq ip (cadr grr)) 1 0)))
                              ; pointer angle
              (GroupRotate ObjList BasePoint (- rot ObjAng))
              (setq ObjAng rot) ; update object current angle
              (and (>= ObjAng (* 2 pi)) (setq ObjAng (- ObjAng (* 2 pi))))
                              ; correct if >= 2pi
              (setq LastRot ObjAng)
              t
             )
           )
         )
  )
  ip
)

Code: [Select]
(defun c:MyRotate (/ ss bpt)
  (and
    (princ "\nSelect objects to rotate:")
    (setq ss (ssget))
    (setq bpt (getpoint "\nSpecify base point: "))
    (princ "\nSpecify rotation angle. ")
    (princ (rotate ss bpt))
  )
  (princ)
)
Title: Re: lastpoint on rotate
Post by: alanjt on November 11, 2009, 07:38:28 PM
Very cool Alan. I knew it was possible, I just wasn't sure what math to apply. I'll have to do a little studying. :)

Added reference line:
Code: [Select]
;;  CAB 11.11.09
;;  Simulate the rotate command
(defun Rotate (ss BasePoint / ip ObjList i ename ip grr
               ANG BPT LASTROT OBJANG ROT STARTANG)
  (defun GroupRotate (objects bpt ang)
    (setq bpt (vlax-3D-point bpt))
    (mapcar (function (lambda (x) (vla-rotate x bpt ang))) Objects)
  )

  (setq ObjAng 0.0
        rot 0.0
  )
  (setq StartAng ObjAng)      ; save angle before rotation begins
  (setq i -1)
  (while (setq ename (ssname ss (setq i (1+ i))))
    (setq ObjList (cons (vlax-ename->vla-object ename) ObjList))
  )

  (while (progn
           (cond
             ((eq 3 (car (setq grr (grread T 15 0))))
              (setq ip (cadr grr))
              nil
             )

             ((and (eq 2 (car grr)) (eq 13 (cadr grr)))
              (GroupRotate ObjList BasePoint (- StartAng LastRot))
              (setq ip nil)
             )

             ((eq 5 (car grr)) ; point from mouse, update star
              (setq rot (angle BasePoint (trans (setq ip (cadr grr)) 1 0)))
              (redraw)
              (grdraw BasePoint ip 7)
                              ; pointer angle
              (GroupRotate ObjList BasePoint (- rot ObjAng))
              (setq ObjAng rot) ; update object current angle
              (and (>= ObjAng (* 2 pi)) (setq ObjAng (- ObjAng (* 2 pi))))
                              ; correct if >= 2pi
              (setq LastRot ObjAng)
              t
             )
           )
         )
  )
  (redraw)
  ip
)
Title: Re: lastpoint on rotate
Post by: CAB on November 11, 2009, 08:51:35 PM
Excellent, thanks.  :-)
Title: Re: lastpoint on rotate
Post by: CAB on November 12, 2009, 12:14:34 AM
Catches locked layers:
Code: [Select]
;;  CAB 11.12.09
;;  Simulate the rotate command
;;  ss may be a selection set or list of enames or vla objects
(defun Rotate (ss BasePoint / ip ObjList i ename ip grr rot layrs obj doc
              LastRot ObjAng)
  (defun GroupRotate (objects bpt ang)
    (setq bpt (vlax-3D-point bpt))
    (mapcar (function (lambda (x) (vla-rotate x bpt ang))) Objects)
  )
  (defun LayUnLocked (Obj layrs)
   (= :vlax-false (vla-get-Lock (vla-Item  layrs (vla-get-Layer Obj))))
  )
 
  (setq ObjAng 0.0
        rot    0.0
        doc    (vla-get-ActiveDocument (vlax-get-acad-object))
        Layrs  (vla-get-Layers doc)
  )
  (vla-endundomark doc)
  (vla-startundomark doc)
  (cond
    ((= (type ss) 'PICKSET)
      (setq i -1)
      (while (setq ename (ssname ss (setq i (1+ i))))
        (if (LayUnLocked (setq obj (vlax-ename->vla-object ename)) Layrs)
          (setq ObjList (cons obj ObjList))
        )
      ))
    ((= (type (car ss)) 'ENAME)
     (mapcar (function (lambda(x)
        (if (LayUnLocked (setq obj (vlax-ename->vla-object x)) Layrs)
          (setq ObjList (cons obj ObjList))
        )))
      ss)
    )
    (t
     (mapcar (function (lambda(x)
        (if (LayUnLocked x Layrs)
          (setq ObjList (cons x ObjList))
        )))
      ss)
    )
  )

  (while (progn
           
           (cond
             ((eq 3 (car (setq grr (grread T 15 0))))
              (setq ip (cadr grr))
              nil
             )

             ((and (eq 2 (car grr)) (eq 13 (cadr grr)))
              (GroupRotate ObjList BasePoint (- LastRot))
              (setq ip nil)
             )

             ((eq 5 (car grr)) ; point from mouse, update star
              (redraw)
              (setq rot (angle BasePoint (trans (setq ip (cadr grr)) 1 0)))
              (grdraw BasePoint ip 7); pointer angle
              (GroupRotate ObjList BasePoint (- rot ObjAng))
              (setq ObjAng rot) ; update object current angle
              (and (>= ObjAng (* 2 pi)) (setq ObjAng (- ObjAng (* 2 pi)))) ; correct if >= 2pi
              (setq LastRot ObjAng)
              t
             )
           )
         )
  )
  (redraw)
  (vla-endundomark doc)
  ip
)
Title: Re: lastpoint on rotate
Post by: Andrea on November 12, 2009, 06:44:20 PM
nice Allan !  thanks..

I'll take your code as example.   :wink:


but ..

what about all Osnaps ? ortho ? input ?
I mean...why doing a new existing command only to take the last pickpoint ?
is there realy no way to get it ?

 :|
Title: Re: lastpoint on rotate
Post by: CAB on November 12, 2009, 07:35:49 PM
Not that I know of.

This too is inaccurate if osnaps are used.
Code: [Select]
  (command "_rotate" pause)
  (while (>(getvar "CMDACTIVE")0) (command pause))
  (cadr (grread 1 1))
Title: Re: lastpoint on rotate
Post by: Andrea on November 12, 2009, 09:27:51 PM
aaahh.....

there it is...

Code: [Select]
(command "._rotate" (ssget) "")
(while (>(getvar "CMDACTIVE")0) (command pause))
(setq Lastpoint (osnap (cadr (grread 1 1)) "_end"))

Thanks Allan.. :roll:
It miss precision without Osnap..but near the goal.
Title: Re: lastpoint on rotate
Post by: Serge J. Gianolla on November 12, 2009, 09:29:15 PM
nice Allan !  thanks..

I'll take your code as example.   :wink:


but ..

what about all Osnaps ? ortho ? input ?
I mean...why doing a new existing command only to take the last pickpoint ?
is there realy no way to get it ?

 :|
Salut Andrea,

Is the @ helping you, like in
Command: PL
PLINE
Specify start point: @
Title: Re: lastpoint on rotate
Post by: CAB on November 12, 2009, 11:30:05 PM
aaahh.....

there it is...

Code: [Select]
(command "._rotate" (ssget) "")
(while (>(getvar "CMDACTIVE")0) (command pause))
(setq Lastpoint (osnap (cadr (grread 1 1)) "_end"))

Thanks Allan.. :roll:
It miss precision without Osnap..but near the goal.
The problem I ran into in my testing is that if the object you snap to is also being moved the rotate command will snap to the phantom object
but when you execute the osnap the object is no longer there & nil is returned.  :?