Author Topic: More help with grread & grvecs...  (Read 2912 times)

0 Members and 1 Guest are viewing this topic.

BazzaCAD

  • Guest
More help with grread & grvecs...
« on: January 15, 2008, 01:25:48 AM »
I borrowed some great code from CAB here:
http://www.theswamp.org/index.php?topic=18537.0
and I have a few questions about my test code.
1. Why is there a leftover rubber band from when the line was first picked (and how do I get read of it)?
2. Why when you stop moving the mouse\pause do the rubber bands disappear?


Code: [Select]
(defun C:test ( / lin elst pt_str pt_end xPoint)
  (setq lin (car (entsel "\nSelect Line: ")))
  (setq elst (entget lin))
  (setq pt_str (cdr (assoc 10 elst)))
  (setq pt_end (cdr (assoc 11 elst)))
  (setq xPoint (getpt pt_str pt_end))
)

(defun getpt (pt_str pt_end /  done grr typ key vecs)
  (princ "\nPick Point: ")
  (while
    (progn
      (setq grr (grread 't 4 1)
            typ (car grr)
            key (cadr grr)
      )
      (if vecs (grvecs vecs))  ; draw vectors
      (cond
        ((= typ 2) ; if keyboard
         (if (or (= key 13) (= key 32)) ; Enter or Space Bar
           (setq key nil)
           t
         )
        )
        ((= typ 3) nil) ; point picked
        ((= typ 5)
         (grvecs (list -256 pt_str key key pt_end))
         t
        ) ; mouse
      )
    )
  );_ while
  (if (= typ 3)
    key
  )
)

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: More help with grread & grvecs...
« Reply #1 on: January 15, 2008, 04:05:57 AM »
try this
Code: [Select]
(defun getpt (pt_str pt_end / done grr typ key vecs)
  (princ "\nPick Point: ")
  (while (progn (setq grr (grread 't 4 1)
      typ (car grr)
      key (cadr grr)
)
(redraw)
(if vecs
  (grvecs vecs)
)   ; draw vectors
(cond ((= typ 2)   ; if keyboard
       (if (or (= key 13) (= key 32)) ; Enter or Space Bar
(setq key nil)
t
       )
      )
      ((= typ 3) nil)   ; point picked
      ((= typ 5) (grvecs (list -256 pt_str key key pt_end)) t) ; mouse
)
)
  ) ;_ while
  (if (= typ 3)
    key
  )
)

Pepe

  • Newt
  • Posts: 87
Re: More help with grread & grvecs...
« Reply #2 on: January 15, 2008, 10:05:15 AM »
Another way to write it:

Code: [Select]
(defun C:test ( / lin elst pt_str pt_end xPoint)
  (setq lin (car (entsel "\nSelect Line: ")))
  (setq elst (entget lin))
  (setq pt_str (cdr (assoc 10 elst)))
  (setq pt_end (cdr (assoc 11 elst)))
  (setq xPoint (getpt pt_str pt_end))
)

(defun getpt (pt_str pt_end / done grr typ key vecs)
  (princ "\nPick Point: ")
  (while
    (progn
      (setq grr (grread 't 4 1) typ (car grr) key (cadr grr))
      (if vecs (grvecs vecs))
      (cond ((= typ 2) (if (or (= key 13) (= key 32)) (setq key nil) t))
    ((= typ 3) nil)
    ((= typ 5) [color=red](grvecs (setq vecs (list -256 pt_str key key pt_end)))[/color] t))
      )
    )
  (if (= typ 3) key)
  )

This works only if you use color -256 (or 256) for GRVECS, as Autolisp help says:

"AutoCAD colors are in the range 0–255. If the color value is greater than 255,
succeeding vectors are drawn in XOR ink, which complements anything it draws over
and which erases itself when overdrawn."

For any other color, better VovKa's solution. In this case you can avoid

Code: [Select]
(if vecs (grvecs vecs))
as it's not useful.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: More help with grread & grvecs...
« Reply #3 on: January 15, 2008, 10:12:06 AM »
Here is your revised code:
Code: [Select]
(defun getpt (pt_str pt_end /  done grr typ key vecs)
  (princ "\nPick Point: ")
  (while
    (progn
      (setq grr (grread 't 4 1)
            typ (car grr)
            key (cadr grr)
      )
      (if vecs (grvecs vecs))  ; draw vectors
      (cond
        ((= typ 2) ; if keyboard
         (if (or (= key 13) (= key 32)) ; Enter or Space Bar
           (setq key nil)
           t
         )
        )
        ((= typ 3) nil) ; point picked
        ((= typ 5)
         (setq vecs (list -256 pt_str key key pt_end))
         t
        ) ; mouse
      )
    )
  );_ while
  (if (= typ 3)
    key
  )
)
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.

BazzaCAD

  • Guest
Re: More help with grread & grvecs...
« Reply #4 on: January 15, 2008, 07:00:08 PM »
Thx for the help guys,
Pepe's code seamed to work best. Sorry CAB but, I'm still stuck with a left over rubber band in your revised version of the code.
But your original "Detail Indicator Tool" works great. :)