TheSwamp
Code Red => AutoLISP (Vanilla / Visual) => Topic started by: CAB on October 27, 2005, 07:37:24 PM
-
Just for fun. :)
This routine displays a square bullseye at the point supplied.
May be a flashy way to let the user know that a point or object was picked.
Perhaps the NyQuil is getting to me. :lol:
;;;=======================[ BullsEye.lsp ]=======================
;;; Author: Charles Alan Butler
;;; Version: 1.0 Oct. 27, 2005
;;; Purpose: Display a rectangular Bullseye at the pick point
;;; Sub_Routines: -Delay
;;; Requirements: -point list
;;; Returns: -None
;;;==============================================================
(defun bullseye (pt / ar box bs ll lr pb ppdu shp ss swp ul ur vs wsd
delay)
(defun delay (sec / timeout) ; Delay by CAB
(setq timeout (+ (getvar "MILLISECS") (* sec 1000.0)))
(while (> timeout (getvar "MILLISECS")))
)
;|
(defun delay (sec / timeout) ; Delay by CAB
(setq timeout (+ (getvar "Date") (/ sec 86400.0)))
(while (> timeout (getvar "Date")))
)
|;
(setq ss (getvar "SCREENSIZE") ; screen size in pixels
vs (getvar "VIEWSIZE") ; screen height in drawing units
pb (getvar "pickbox") ; get current pickbox size
swp (car ss) ; width of screen in pixels
shp (cadr ss) ; height of screen in pixels
ar (/ swp shp) ; aspect ratio width/height
wsd (* vs ar) ; width of screen dwg units = ratio times height
ppdu (/ wsd swp) ; pixels per drawing unit
box (/ (* vs (* 2 pb)) shp) ; drawing units per pixel
bs (* box 2.0) ; starting box 1/2 diaganal
)
(repeat 10
(setq ur (polar pt (* pi 0.25) bs)
ul (polar pt (* pi 0.75) bs)
ll (polar pt (* pi 1.25) bs)
lr (polar pt (* pi 1.75) bs)
bs (* bs 1.25)
)
;; draw the rectangle
(grvecs (list -256 ll lr lr ur ur ul ul ll))
(delay 0.005)
)
(redraw)
)
(defun c:test (/ ent)
(if (setq ent (entsel "\nPick an object."))
(bullseye (cadr ent))
)
(princ)
)
-
I get nothing CAB! Program seems to work fine but no bullseye.
-
Never mind, I got it!!
-
CAB,
I couldn't get the bullseye to display on my machine. I was able to tweak the delay time to create a noticeable delay but the graphics still wouldn't display long enough for me to really see it (it just flash by super fast). I discovered that if I comment out the delay function and added the following repeat statement, then everything appeared fine.
;(delay 0.005)
(repeat 12000 (princ))
Not sure why the above worked, but the delay didn't. Hope this helps someone.
-
Well try this timer
(defun delay (sec / timeout) ; Delay by CAB
(setq timeout (+ (getvar "MILLISECS") (* sec 1000.0)))
(while (> timeout (getvar "MILLISECS")))
)
This one is a little better but still only good down to to .01 sec on my machine.
Not sure why.
Also the Redraw does not always work on my system.
Might be the display card.
-
If (delay 0.005) doesn't work right, perhaps (command ".delay" "5") does.
-
Just thought I post an alternate method to giving visual feedback to the user. What it does is make the entity the user selected "blink" or "twitch", just enough to not be annoying, yet give a solid signal to the user that the entity selected is accepted.
If you want to try it, paste the snip below into the command line. First argument is an ename, second is number of times to blink, third is delay time. Adjust delay argument to suit your PC's speed. This snip works good for me using a 3.0 GHz PC.
(blink (car (entsel)) 2 0.1))
;; Function: Blink
;;
;; Makes an entity blink on and off
;;
;; Requires function Wait and three arguments:
;;
;; ename is an entity name
;; count is the number of times to blink (integer)
;; delay is amount of time between blinks (real number)
;;
;; Suggested argument values:
;; count = [0,1,2,3] = the number of time to blink
;; delay = [0.05 0.2] = seconds to hide/show
;; note that as procesor speeds increase,
;; you'll need to adjust the delay time
;; to achieve the same effect
;;
(defun Blink (ename count delay)
(repeat count
(redraw ename 2) ;_ hide
(wait delay)
(redraw ename 1) ;_show
(wait delay)
)
)
;
;;
;; Function: Wait
;;
;; Thanks to Tony Tanzillo
;;
(defun wait (seconds / stop)
(setq stop (+ (getvar "DATE") (/ seconds 86400.0)))
(while (> stop (getvar "DATE")) (princ))
)
-
Hey,
Neat alternative.
I am having trouble with my computer and I had to change your code to this to get it to
display anything.
(redraw ename 3) ; Highlight
(wait delay)
(redraw ename 4) ; UnHighlight
And I see TT has beat me to the delay function. Perhaps the Princ is needed I had not
included that in my version.
-
Cab,
I've used the blink function for years on my home and work PCs, and also on many different coworkers computers a few different companies. But I've never seen the redraw problem you must be experiencing.
I don't know if TT penned the Wait function or not. But he did post it at the link below. He also mentioned having a problem seeing the redraw work correctly.
http://groups.google.com/group/autodesk.autocad.customization/browse_thread/thread/fedca06e503ecec1/293bf77997f43fc5?lnk=st&q=defun+wait+group:autodesk*&rnum=1&hl=en#293bf77997f43fc5