Author Topic: Examples of usage GRREAD - let's share  (Read 199078 times)

0 Members and 2 Guests are viewing this topic.

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Examples of usage GRREAD - let's share
« Reply #45 on: December 22, 2009, 02:40:18 PM »
« Last Edit: December 22, 2009, 02:54:41 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.

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Examples of usage GRREAD - let's share
« Reply #46 on: December 22, 2009, 03:03:54 PM »
No, the vlax-curve... functions don't work on blocks.
so, we will cheat a little :)
Code: [Select]
(defun c:LPer (/ #Ent #Read *error*)
  (defun *error* (msg) (and #Ent (entdel #Ent)) (princ msg))
  (and
    (setq #Ent (nentselp "\nSelect curve: "))
    (vl-position (cdr (assoc 0 (entget (car #Ent))))
'("LWPOLYLINE" "ARC" "LINE" "CIRCLE" "ELLIPSE")
    )
    (setq #Read (caddr #Ent)
  #Ent (entmakex (append (entget (car #Ent)) (list (cons 60 1))))
    )
    (or (not #Read)
(not (vla-transformby (vlax-ename->vla-object #Ent) (vlax-tmatrix #Read)))
    )
    (not
      (while (not (eq 25 (car (setq #Read (grread T 15 0)))))
(princ "\rSpecify point for line: ")
(redraw)
(if (vl-consp (cadr #Read))
  (grdraw (vlax-curve-getclosestpointto #Ent (trans (cadr #Read) 1 0) T)
  (trans (cadr #Read) 1 0)
  1
  )
)
(if (eq 3 (car #Read))
  (entmake
    (list '(0 . "LINE")
  (cons 10 (vlax-curve-getclosestpointto #Ent (trans (cadr #Read) 1 0) T))
  (cons 11 (trans (cadr #Read) 1 0))
    )
  )
)
      )
    )
    (entdel #Ent)
  )
  (redraw)
  (princ)
)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #47 on: December 22, 2009, 03:07:46 PM »
Damn it! I've even used vla-transformby before. Hell, I have a rotation extraction sub that uses this exact method. I can't believe I didn't think of it.  :|
Very nice Vovka. :)

No, the vlax-curve... functions don't work on blocks.
so, we will cheat a little :)
Code: [Select]
(defun c:LPer (/ #Ent #Read *error*)
  (defun *error* (msg) (and #Ent (entdel #Ent)) (princ msg))
  (and
    (setq #Ent (nentselp "\nSelect curve: "))
    (vl-position (cdr (assoc 0 (entget (car #Ent))))
'("LWPOLYLINE" "ARC" "LINE" "CIRCLE" "ELLIPSE")
    )
    (setq #Read (caddr #Ent)
  #Ent (entmakex (append (entget (car #Ent)) (list (cons 60 1))))
    )
    (or (not #Read)
(not (vla-transformby (vlax-ename->vla-object #Ent) (vlax-tmatrix #Read)))
    )
    (not
      (while (not (eq 25 (car (setq #Read (grread T 15 0)))))
(princ "\rSpecify point for line: ")
(redraw)
(if (vl-consp (cadr #Read))
  (grdraw (vlax-curve-getclosestpointto #Ent (trans (cadr #Read) 1 0) T)
  (trans (cadr #Read) 1 0)
  1
  )
)
(if (eq 3 (car #Read))
  (entmake
    (list '(0 . "LINE")
  (cons 10 (vlax-curve-getclosestpointto #Ent (trans (cadr #Read) 1 0) T))
  (cons 11 (trans (cadr #Read) 1 0))
    )
  )
)
      )
    )
    (entdel #Ent)
  )
  (redraw)
  (princ)
)
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

David Bethel

  • Swamp Rat
  • Posts: 656
Re: Examples of usage GRREAD - let's share
« Reply #48 on: December 23, 2009, 07:15:49 AM »
Just a simple grread call:

Code: [Select]
;;;GET SINGLE LETTER RESPONSE WITH OUT ENTER
;;;USEAGE  (getsltr '("Y" "N"))
(defun getsltr (al / in cl)
   (foreach a al
      (setq cl (cons (ascii (strcase a t)) cl)
            cl (cons (ascii (strcase a)) cl)))
   (while (not (member in cl))
          (princ "\n")
          (prin1 al)
          (princ ":   ")
          (setq in (cadr (grread))))
   (strcase (chr in)))

-David
R12 Dos - A2K

ronjonp

  • Needs a day job
  • Posts: 7526
Re: Examples of usage GRREAD - let's share
« Reply #49 on: December 23, 2009, 02:51:54 PM »
Just adding to Vovkas Alan's routine  :-P...this one stores the segments added and sorts to the closest one  :-)

Code: [Select]
(defun c:lpers (/ *error* #ent #read clpt clr el ent lname pt x)
  (defun *error* (msg) (and #ent (mapcar 'entdel #ent)) (princ msg))
  (and
    (setq #ent (nentselp "\nSelect curve: "))
    (vl-position
      (cdr (assoc 0 (setq el (entget (car #ent)))))
      '("LWPOLYLINE" "ARC" "LINE" "CIRCLE" "ELLIPSE")
    )
    (setq clr (cdr (assoc 62 (entget (tblobjname "layer" (cdr (assoc 8 el)))))))
    (setq lname (cdr (assoc 8 el)))
    (setq #read (caddr #ent)
 #ent (entmakex (append (entget (car #ent)) (list (cons 60 1))))
    )
    (or (not #read)
(not (vla-transformby (vlax-ename->vla-object #ent) (vlax-tmatrix #read)))
    )
    (setq #ent (list #ent))
    (not
      (while (not (eq 2 (car (setq #read (grread t 15 0)))))
(princ "\rSpecify point for line: ")
(redraw)
(if (vl-consp (setq pt (cadr #read)))
 (progn
   (setq ent
  (car
    (mapcar
      'cdr
      (vl-sort
(mapcar '(lambda (x)
   (cons (distance (setq pt (trans (cadr #read) 1 0))
   (setq clpt (vlax-curve-getclosestpointto
x
(trans (cadr #read) 1 0)
      )
   )
 )
 x
   )
 )
#ent
)
(function (lambda (d1 d2) (< (car d1) (car d2))))
      )
    )
  )
   )
   (grdraw (setq clpt (setq clpt (vlax-curve-getclosestpointto ent pt))) pt clr)
 )
)
(if (eq 3 (car #read))
 (setq
   #ent (cons (entmakex
(list '(0 . "LINE") (cons 8 lname) (cons 10 clpt) (cons 11 pt))
      )
      #ent
)
 )
)
      )
    )
  )
  (redraw)
  (princ)
)
« Last Edit: December 23, 2009, 09:26:22 PM by ronjonp »

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #50 on: December 23, 2009, 03:02:19 PM »
Mine and Ron's collaborative effort to combat boredom  :evil:

Code: [Select]
(defun c:bored (/ cir cnt gr lst n d)
  (setq lst (list (getvar 'viewctr) (getvar 'viewctr)) cnt 0)
 
  (while (eq 5 (car (setq gr (grread nil 5 1))))
    (redraw)
    (setq cir nil n 0 lst (append lst (list (last lst) (cadr gr))) cnt (1+ cnt))
   
    (if (< 100 cnt) (setq lst (cddr lst)))
   
    (repeat 50 (setq d (/ (distance (car lst) (last lst)) 4.))
      (repeat 4
        (setq cir (cons (polar (car lst)
                               (* (setq n (1+ n)) (/ (* pi 2) 50)) d) cir))
        (setq d (/ d 2.))))
   
    (grvecs (append (list (rem (/ cnt 100) 255)) lst cir)))
 
  (princ))


wizman

  • Bull Frog
  • Posts: 290
Re: Examples of usage GRREAD - let's share
« Reply #51 on: December 23, 2009, 03:32:44 PM »
Good Codes Guys, here's my simple addition:


Code: [Select]
(defun c:test (/ grr ent entlist inp pt1 pt2)
    ;;
    ;;
    (defun MkLine (p1 p2)
        (entmakex (list (cons 0 "LINE")
                        (cons 10 p1)
                        (cons 11 p2)
                  ) ;_ list
        ) ;_ entmakex
    ) ;_ defun
    ;;
    ;;
    (if
        (and
            (setq pt1 (getpoint "\n>>>...Pick Points...>>>: "))
            (setq pt2 (getpoint pt1))
            (setq ent (mkline pt1 pt2))
            (setq entlist (list ent))
        ) ;_ and
           ;;
           ;;
           (progn
               (while
                   (progn
                       (setq grr (grread t 7 0)
                             inp (car grr)
                       ) ;_ setq
                       (if (= (length entlist) 1)
                           (setq entlist (cons (mkline pt2 (cadr grr)) entlist))
                       ) ;_ if
                       (cond
                           ((= inp 3)
                            (setq entlist (cons (mkline (cadr grr) pt1) entlist))
                            (setq pt1 (cadr grr))
                           )
                           ((or (= inp 25) (= inp 11))
                            nil
                           )
                           ((= inp 5)
                            (foreach x entlist
                                (entmod
                                    (subst
                                        (cons 11 (cadr grr))
                                        (assoc 11 (entget x))
                                        (entget x)
                                    ) ;_ subst
                                ) ;_ entmod
                                (not (redraw x 3))
                            ) ;_ foreach
                           )
                       ) ;_ cond
                   ) ;_ progn
               ) ;_ while
               (foreach x entlist
                   (redraw x 4)
               ) ;_ foreach
           ) ;_ progn
           ;;
           ;;
    ) ;_ if
    (princ)
) ;_ defun
;;
;;
;;WIZ_24DEC09

« Last Edit: December 31, 2009, 08:34:34 AM by wizman »

wizman

  • Bull Frog
  • Posts: 290
Re: Examples of usage GRREAD - let's share
« Reply #52 on: December 23, 2009, 03:42:52 PM »
Quote
so, we will cheat a little

another cheat is to just explode the block.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #53 on: December 23, 2009, 03:45:25 PM »
Very nice Ron!
I didn't expect so much to come out of what little my initial contribution was.

Just adding to Vovkas routine...this one stores the segments added and sorts to the closest one  :-)

Code: [Select]
(defun c:lpers (/ *error* #ent #read clpt clr el ent lname pt x)
  (defun *error* (msg) (and #ent (mapcar 'entdel #ent)) (princ msg))
  (and
    (setq #ent (nentselp "\nSelect curve: "))
    (vl-position
      (cdr (assoc 0 (setq el (entget (car #ent)))))
      '("LWPOLYLINE" "ARC" "LINE" "CIRCLE" "ELLIPSE")
    )
    (setq clr (cdr (assoc 62 (entget (tblobjname "layer" (cdr (assoc 8 el)))))))
    (setq lname (cdr (assoc 8 el)))
    (setq #read (caddr #ent)
  #ent (entmakex (append (entget (car #ent)) (list (cons 60 1))))
    )
    (or (not #read)
(not (vla-transformby (vlax-ename->vla-object #ent) (vlax-tmatrix #read)))
    )
    (setq #ent (list #ent))
    (not
      (while (not (eq 2 (car (setq #read (grread t 15 0)))))
(princ "\rSpecify point for line: ")
(redraw)
(if (vl-consp (setq pt (cadr #read)))
  (progn
    (setq ent
   (car
     (mapcar
       'cdr
       (vl-sort
(mapcar '(lambda (x)
    (cons (distance (setq pt (trans (cadr #read) 1 0))
    (setq clpt (vlax-curve-getclosestpointto
x
(trans (cadr #read) 1 0)
       )
    )
  )
  x
    )
  )
#ent
)
(function (lambda (d1 d2) (< (car d1) (car d2))))
       )
     )
   )
    )
    (grdraw (setq clpt (setq clpt (vlax-curve-getclosestpointto ent pt))) pt clr)
  )
)
(if (eq 3 (car #read))
  (setq
    #ent (cons (entmakex
(list '(0 . "LINE") (cons 8 lname) (cons 10 clpt) (cons 11 pt))
       )
       #ent
)
  )
)
      )
    )
  )
  (redraw)
  (princ)
)

Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Examples of usage GRREAD - let's share
« Reply #54 on: December 23, 2009, 03:56:01 PM »
Just adding to Vovkas routine...this one stores the segments added and sorts to the closest one  :-)
Ron, stop discrediting me, 95% of the code is Alan's :)

Mine and Ron's collaborative effort to combat boredom  :evil:
guys, i'm having fun with it, coooool :)

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #55 on: December 23, 2009, 04:11:54 PM »
Just adding to Vovkas routine...this one stores the segments added and sorts to the closest one  :-)
Ron, stop discrediting me, 95% of the code is Alan's :)
:-(
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Examples of usage GRREAD - let's share
« Reply #56 on: December 23, 2009, 04:39:42 PM »
hey don't be sad, Alan
i didn't mean to say that you code is bad or something, i meant that i personally never use grread.
writing lisps for years i still haven't found any way i could use grread. it's because of the lack of fantasy i suppose :)

Lee Mac

  • Seagull
  • Posts: 12905
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #57 on: December 23, 2009, 06:53:32 PM »
IMO GrRead would be a TON more useful if it support OSnap...

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Examples of usage GRREAD - let's share
« Reply #58 on: December 23, 2009, 07:38:10 PM »
I second that :-)
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.

alanjt

  • Needs a day job
  • Posts: 5352
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #59 on: December 23, 2009, 09:46:08 PM »
hey don't be sad, Alan
i didn't mean to say that you code is bad or something, i meant that i personally never use grread.
writing lisps for years i still haven't found any way i could use grread. it's because of the lack of fantasy i suppose :)
No offense taken. :)

I don't really use grread, with the lack of functionality (input, which can be emulated, but it's still pretty shaky and osnaps) it's just not worth the aggravation.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox