TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started 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 ? :|
-
did you try
(getvar "LASTPOINT")
?
ef
-
did you try
(getvar "LASTPOINT")
?
ef
LASTPOINT return the rotation basepoint not the last one..
-
if the rotation angle is get by clicking another point, this one will be the last...
ef
-
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
-
Create your own Rotate command. :)
-
Create your own Rotate command. :)
:?
-
Try this, quick & dirty. 8-)
;; 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
)
(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)
)
-
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:
;; 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
)
-
Excellent, thanks. :-)
-
Catches locked layers:
;; 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
)
-
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 ?
:|
-
Not that I know of.
This too is inaccurate if osnaps are used.
(command "_rotate" pause)
(while (>(getvar "CMDACTIVE")0) (command pause))
(cadr (grread 1 1))
-
aaahh.....
there it is...
(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.
-
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: @
-
aaahh.....
there it is...
(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. :?