Author Topic: BullsEye.lsp  (Read 3056 times)

0 Members and 1 Guest are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
BullsEye.lsp
« 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:

Code: [Select]
;;;=======================[ 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)
)
« Last Edit: October 28, 2005, 05:54:39 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.

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: BullsEye.lsp
« Reply #1 on: October 28, 2005, 08:26:12 AM »
I get nothing CAB! Program seems to work fine but no bullseye.
TheSwamp.org  (serving the CAD community since 2003)

Mark

  • Custom Title
  • Seagull
  • Posts: 28762
Re: BullsEye.lsp
« Reply #2 on: October 28, 2005, 08:33:25 AM »
Never mind, I got it!!
TheSwamp.org  (serving the CAD community since 2003)

Sdoman

  • Guest
Re: BullsEye.lsp
« Reply #3 on: October 28, 2005, 03:13:56 PM »
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.






CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BullsEye.lsp
« Reply #4 on: October 28, 2005, 05:49:32 PM »
Well try this timer
Code: [Select]
  (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.
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.

Crank

  • Water Moccasin
  • Posts: 1503
Re: BullsEye.lsp
« Reply #5 on: October 29, 2005, 02:16:33 AM »
If (delay 0.005) doesn't work right, perhaps (command ".delay" "5") does.
Vault Professional 2023     +     AEC Collection

Sdoman

  • Guest
Re: BullsEye.lsp
« Reply #6 on: October 29, 2005, 03:35:38 PM »
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))


Code: [Select]

  ;; 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))
  )





CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: BullsEye.lsp
« Reply #7 on: October 29, 2005, 05:33:55 PM »
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.
Code: [Select]
      (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.
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.

Sdoman

  • Guest
Re: BullsEye.lsp
« Reply #8 on: October 29, 2005, 06:01:23 PM »
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