Author Topic: Can someone please help me pinpoint the grread  (Read 2377 times)

0 Members and 1 Guest are viewing this topic.

RAIN CODE

  • Guest
Can someone please help me pinpoint the grread
« on: April 25, 2012, 09:24:13 AM »
 Hello everyone.

I am a amateur autolisp programmer, not really a good one  :oops:. Hope one the guru here can help me with my grread problem.

I have downloaded the Troy AutoLisp grread game (written by Terry Miller), copied part of the code from the Troy game to my program. The weird thing is the grread won't move until I move the mouse, unlike the Troy program worked with streaming output, even without touching the mouse. I added a princ after the grread, Amazingly the Troy program printed out coordinates even without moving the mouse (The Troy game can be downloaded here -
http://web2.airmail.net/terrycad/LISP/Troy-I.lsp)

I would appreciated any help. (Hope one of the Guru will tell me what my program is missing)

Thank you very much.  :-)
Sorry for the lousy grammar   :oops:

Below is my short program -

;;--------------------------------------------------------------------------------------------------------------------
;; trying to make grread streaming output.
(defun c:tg ()
 
  (setq loop t)
  (setq Previous@ (grread t 4))
  (setq cr_pt (getpoint "\npick pt for circle-red")
    cw_pt (getpoint "\npick pt for circle-white")
  )
  (command "circle" cr_pt 3)
  (command "chprop" "l" "" "c" "1" "")
  (setq cr_name (entlast))
  (command "circle" cw_pt 3)
  (command "chprop" "l" "" "c" "7" "")
  (setq cw_name (entlast))
 
  (while Loop
    (if (not (setq Read@ (grread t 4)))     ;; problem here is, grread is not streaming, it pause when mouse not moving
      (setq Read@ Previous@)
      )
   
    (if (and (/= Previous@ nil) (not (equal (cadr Previous@) (cadr Read@) 0.001))) (move_white))      ;; mouse moved then move white circle

    ;; red circle supposed to move even user not moving the mouse.
    ;; like the Troy.lsp - Troy moves around even when mouse not moving
    (move_red)                                   
   
    (princ Read@)       
    (setq Code# (nth 0 Read@))
    (if (= Code# 2)        ;; key pressed then
      (setq loop nil)        ;; exit loop
    )
    (setq Previous@ Read@)
  )
 
  (princ)
)

(princ "\ntest grread movement.LSP loaded...type tg to test")
   

;; --------------------
;; move square
;; --------------------
(defun move_red ()
  (command "move" cr_name "" "0,0" "@1<0.5")
)
;; --------------------
;; move circle
;; --------------------
(defun move_white ()
  (command "move" cw_name "" "0,0" "@1<0.5")
)
;; ---------------------------------------------------------------------------------------- end of lisp






roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Can someone please help me pinpoint the grread
« Reply #1 on: April 30, 2012, 06:48:52 AM »
I think your code already works the way you want it to work. But because of the cmdecho setting you just don't notice it. I have made some changes to your code to clarify things.

BTW: It is the move command that "tricks" the (grread) function into grabbing a new point.

Code: [Select]
(defun c:tg ( / cr_name cw_name cr_pt cw_pt i Loop Previous@ Read@)
  (setvar 'cmdecho 0)
  (setq cr_pt (getpoint "\nPick pt for circle-red: ")
        cw_pt (getpoint "\nPick pt for circle-white: ")
  )
  (command "circle" cr_pt 3)
  (command "chprop" "l" "" "c" "1" "")
  (setq cr_name (entlast))
  (command "circle" cw_pt 3)
  (command "chprop" "l" "" "c" "7" "")
  (setq cw_name (entlast))

  (setq i 0)
  (setq Loop t)
  (while Loop
    (setq Read@ (grread t 4))
    (print (setq i (1+ i)))
    (print Read@)
    (if
      (and Previous@ (not (equal (cadr Previous@) (cadr Read@) (/ (getvar 'viewsize) 500))))
      (move_white)
    )
    (move_red)
    (if (= (car Read@) 2)    ;; key pressed then
      (setq loop nil)        ;; exit loop
    )
    (setq Previous@ Read@)
  )

  (setvar 'cmdecho 1)
  (princ)
)

;; --------------------
;; move square
;; --------------------
(defun move_red ()
  (command "move" cr_name "" "0,0" "@1<0.5")
)
;; --------------------
;; move circle
;; --------------------
(defun move_white ()
  (command "move" cw_name "" "0,0" "@1<0.5")
)

(princ "\nTest grread movement.LSP loaded... Type TG to test ")
(princ)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Can someone please help me pinpoint the grread
« Reply #2 on: April 30, 2012, 07:21:18 AM »
I think its actually a Regen that will cause grread to continue without user input, e.g.:

Code - Auto/Visual Lisp: [Select]
  1. (defun c:tg2 ( / o p ) (vl-load-com)
  2.     (setq p (getvar 'viewctr))
  3.     (setq o
  4.             (vlax-3D-point (cons (+ (car p) (/ (getvar 'viewsize) 5.0)) (cdr p)))
  5.             (/ (getvar 'viewsize) 20.0)
  6.         )
  7.     )
  8.     (setq p (vlax-3D-point p))
  9.     (while (= 5 (car (grread t 14 1)))
  10.         (vla-rotate o p 0.0175)
  11.         (command "_.regen")
  12.     )
  13.     (princ)
  14. )

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Can someone please help me pinpoint the grread
« Reply #3 on: April 30, 2012, 10:33:13 AM »
Maybe it's a Bricscad thing, but only Test_GR_4 from the code below will do the trick for me.

Code: [Select]
(defun c:Test_GR_1 ( / i grResult)
  (setvar 'cmdecho 0)
  (setq i 0)
  (while (= (car (setq grResult (grread t 4))) 5)
    (print (setq i (1+ i)))
    (print grResult)
    (command "_.regen")
  )
  (setvar 'cmdecho 1)
  (princ)
)

(defun c:Test_GR_2 ( / i grResult)
  (setvar 'cmdecho 0)
  (setq i 0)
  (while (= (car (setq grResult (grread t 4))) 5)
    (print (setq i (1+ i)))
    (print grResult)
    (command "_.zoom" "_center" (getvar 'viewctr) (getvar 'viewsize))
  )
  (setvar 'cmdecho 1)
  (princ)
)

(defun c:Test_GR_3 ( / i grResult)
  (setvar 'cmdecho 0)
  (setq i 0)
  (while (= (car (setq grResult (grread t 4))) 5)
    (print (setq i (1+ i)))
    (print grResult)
    (command "_.pan" '(0 0 0) '(0 0 0))
  )
  (setvar 'cmdecho 1)
  (princ)
)

(defun c:Test_GR_4 ( / i grResult)
  (entmake (list '(0 . "POINT") (cons 10 (getvar 'viewctr))))
  (setvar 'cmdecho 0)
  (setq i 0)
  (while (= (car (setq grResult (grread t 4))) 5)
    (print (setq i (1+ i)))
    (print grResult)
    (command "_.move" (entlast) "" '(0 0 0) '(0 0 0))
  )
  (setvar 'cmdecho 1)
  (princ)
)

RAIN CODE

  • Guest
Re: Can someone please help me pinpoint the grread
« Reply #4 on: May 05, 2012, 05:43:03 AM »
Hi, guys

Thanks for the help. I emailed Terry days ago and he replied me. It has something to do with refreshing the screen.
Lee Mac is right. Regen will make grread do streaming output. A simple (command "zoom" nil nil) will also do the trick.
And we are able to write games for autocad and I am sooooooooo excited and I am going to write a game. Hope I could get it work.
I will post it if I finish writing the game.

Guys. Autocad can also make sound. Check out the dos Lib for wav sound.

Well...please excuse me... I have a game to write.