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

0 Members and 2 Guests are viewing this topic.

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #240 on: August 19, 2014, 05:09:58 AM »
@ ribarm: Function _getosmode is missing.

Thanks for testing, Roy... Now fixed...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #241 on: August 19, 2014, 07:09:02 AM »
Tested deeply... For "_tan" and "_per" it won't work correctly...

Too bad and I thought it's useful...

 :cry:
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1778
  • BricsCAD 18
Re: Examples of usage GRREAD - let's share
« Reply #242 on: August 19, 2014, 08:07:06 AM »
@ ribarm:
I think you should always use the (_snap) function when setting the gps variable.
This may be useful:
Code: [Select]
(boole 6  0 16) => 16
(boole 6  8 16) => 24
(boole 6 16 16) =>  0
(boole 6 24 16) =>  8

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #243 on: August 19, 2014, 08:19:08 AM »
I think I fixed it with cheating - used (getpoint) function inside (_snap) and yes you're right Roy... This is similar to what you proposed, only thing that now (getpoint) visibility vector is in front - (grdraw) is invisible... Anyhoo, this works... Thanks for your attention...

Code: [Select]
(defun c:myline ( / *error* osm omo aus ape doc drft osGrv o p s
                    osMark _getosmode get_osmode osmode-grvecs-lst _snap _polarangs _polar _ortho
                    pt loop gr gp oPt gps )

  (vl-load-com)

  (defun *error* (msg)
    (if osm (setvar 'osmode osm))
    (if omo (setvar 'orthomode omo))
    (if aus (setvar 'autosnap aus))
    (if ape (setvar 'aperture ape))
    (if msg (prompt msg))
    (redraw)
    (princ)
  )
 
  (setq osm (getvar 'osmode))
  (setq omo (getvar 'orthomode))
  (setq aus (getvar 'autosnap))
  (if (eq omo 1) (setq o t) (setq o nil))
  (if (eq (logand aus 8) 8) (setq p t) (setq p nil))
  (if (< 0 osm 16384) (setq s t) (setq s nil))
  (setq ape (getvar 'aperture))
  (setvar 'aperture 10)

  (defun _getosmode (os / lst)
      (foreach mode
         '(
              (0001 . "_end")
              (0002 . "_mid")
              (0004 . "_cen")
              (0008 . "_nod")
              (0016 . "_qua")
              (0032 . "_int")
              (0064 . "_ins")
              (0128 . "_per")
              (0256 . "_tan")
              (0512 . "_nea")
              (1024 . "_qui")
              (2048 . "_app")
              (4096 . "_ext")
              (8192 . "_par")
          )
          (if (not (zerop (logand (car mode) os)))
              (setq lst (cons "," (cons (cdr mode) lst)))
          )
      )
      (apply 'strcat (cdr lst))
  )

  (defun osMark (o / s)
    (setq s (/ (getvar "VIEWSIZE") (cadr (getvar "SCREENSIZE")))
          o (cons (trans (car o) 1 3) (cdr o)))

    (grvecs (cdr (assoc (cadr o) osGrv))
            (list (list s 0. 0. (caar o))
                  (list 0. s 0. (cadar o))
                  (list 0. 0. s 0.)
                  (list 0. 0. 0. 1.))))

  (defun get_osmode nil ; by Evgeniy Elpanov
    (mapcar
      (function cdr)
        (vl-remove-if
          (function (lambda (x) (zerop (logand (getvar "OSMODE") (car x)))))
          '((0    . "_non")
            (1    . "_end")
            (2    . "_mid")
            (4    . "_cen")
            (8    . "_nod")
            (16   . "_qua")
            (32   . "_int")
            (64   . "_ins")
            (128  . "_per")
            (256  . "_tan")
            (512  . "_nea")
            (2048 . "_app")))))

  (defun osmode-grvecs-lst (col ass / -ass)
     ; By Evgeniy Elpanov (Modified by Lee Mac)
   
    (setq -ass (- ass))
   
    (list (list "_non"
                col (list 0.0 -ass) (list 0.0  ass)
                col (list -ass 0.0) (list ass 0.0))

          (list "_end"
                col (list -ass -ass) (list -ass  ass)
                col (list (1-  -ass) (1- -ass)) (list (1- -ass) (1+  ass))             
                col (list -ass  ass) (list  ass  ass)
                col (list (1-  -ass) (1+  ass)) (list (1+  ass) (1+  ass))             
                col (list  ass  ass) (list  ass -ass)
                col (list (1+   ass) (1+  ass)) (list (1+  ass) (1- -ass))             
                col (list  ass -ass) (list -ass -ass)
                col (list (1+   ass) (1- -ass)) (list (1- -ass) (1- -ass)))
         
          (list "_mid"
                col (list -ass -ass) (list    0. ass)
                col (list (1-  -ass) (1- -ass)) (list 0. (1+  ass))
                col (list    0. ass) (list  ass -ass)
                col (list 0. (1+  ass)) (list (1+  ass) (1- -ass))
                col (list  ass -ass) (list -ass -ass)
                col (list (1+   ass) (1- -ass)) (list (1- -ass) (1- -ass)))
         
          (list "_cen"
                7   (list (* -ass 0.2) 0.)  (list (*  ass 0.2) 0.)
                7   (list  0. (* -ass 0.2)) (list  0.  (*  ass 0.2))
                col (list    -ass   0.)     (list (* -ass 0.86) (* ass  0.5))
                col (list (* -ass 0.86) (* ass  0.5))  (list (* -ass  0.5) (* ass 0.86))
                col (list (* -ass  0.5) (* ass 0.86))  (list 0. ass)
                col (list 0. ass) (list (* ass 0.5)    (* ass 0.86))
                col (list (* ass 0.5)   (* ass 0.86))  (list (* ass 0.86) (* ass 0.5))
                col (list (* ass 0.86)  (* ass 0.5))   (list ass 0.)
                col (list ass 0.) (list (* ass 0.86)   (* -ass 0.5))
                col (list (* ass 0.86)  (* -ass 0.5))  (list (* ass 0.5) (* -ass 0.86))
                col (list (* ass 0.5)   (* -ass 0.86)) (list 0. -ass)
                col (list 0. -ass)(list (* -ass 0.5)   (* -ass 0.86))
                col (list (* -ass 0.5)  (* -ass 0.86)) (list (* -ass 0.86) (* -ass 0.5))
                col (list (* -ass 0.86) (* -ass 0.5))  (list -ass 0.))

          (list "_nod"
                col (list -ass -ass)    (list ass ass)
                col (list -ass ass)     (list ass -ass)
                col (list -ass 0.)      (list (* -ass 0.86) (* ass 0.5))
                col (list (* -ass 0.86) (* ass 0.5))   (list (* -ass 0.5) (* ass 0.86))
                col (list (* -ass 0.5)  (* ass 0.86))  (list 0. ass)
                col (list 0. ass) (list (* ass 0.5)    (* ass 0.86))
                col (list (* ass 0.5)   (* ass 0.86))  (list (* ass 0.86) (* ass 0.5))
                col (list (* ass 0.86)  (* ass 0.5))   (list ass 0.)
                col (list ass 0.) (list (* ass 0.86)   (* -ass 0.5))
                col (list (* ass 0.86)  (* -ass 0.5))  (list (* ass 0.5) (* -ass 0.86))
                col (list (* ass 0.5)   (* -ass 0.86)) (list 0. -ass)
                col (list 0. -ass)(list (* -ass 0.5)   (* -ass 0.86))
                col (list (* -ass 0.5)  (* -ass 0.86)) (list (* -ass 0.86) (* -ass 0.5))
                col (list (* -ass 0.86) (* -ass 0.5))  (list -ass 0.))

          (list "_qua"
                col (list 0. -ass)   (list -ass 0.)
                col (list 0. (1- -ass))   (list (1- -ass) 0.)
                col (list -ass 0.)   (list 0. ass)
                col (list (1- -ass) 0.)   (list 0. (1+ ass))
                col (list 0. ass)    (list ass 0.)
                col (list 0. (1+ ass))    (list (1+ ass) 0.)
                col (list ass 0.)    (list 0. -ass)
                col (list (1+ ass) 0.)    (list 0. (1- -ass)))

          (list "_int"
                col (list -ass -ass) (list ass ass)
                col (list -ass (1+ -ass)) (list ass (1+ ass))
                col (list (1+ -ass) -ass) (list (1+ ass) ass)
                col (list -ass ass)  (list ass -ass)
                col (list -ass (1+ ass))  (list ass (1+ -ass))
                col (list (1+ -ass) ass)  (list (1+ ass) -ass))

          (list "_ins"
                col (list (* -ass 0.1) (* -ass 0.1)) (list -ass (* -ass 0.1))
                col (list -ass (* -ass 0.1)) (list -ass ass)
                col (list -ass ass) (list (* ass 0.1) ass)
                col (list (* ass 0.1) ass)   (list (* ass 0.1) (* ass 0.1))
                col (list (* ass 0.1) (* ass 0.1))   (list ass (* ass 0.1))
                col (list ass (* ass 0.1))   (list ass -ass)
                col (list ass -ass) (list (* -ass 0.1) -ass)
                col (list (* -ass 0.1) -ass) (list (* -ass 0.1) (* -ass 0.1))
                col (list (1- (* -ass 0.1)) (1- (* -ass 0.1))) (list (1- -ass) (1- (* -ass 0.1)))
                col (list (1- -ass) (1- (* -ass 0.1))) (list (1- -ass) (1+ ass))
                col (list (1- -ass) (1+ ass)) (list (1+ (* ass 0.1)) (1+ ass))
                col (list (1+ (* ass 0.1)) (1+ ass)) (list (1+ (* ass 0.1)) (1+ (* ass 0.1)))
                col (list (1+ (* ass 0.1)) (1+ (* ass 0.1))) (list (1+ ass) (1+ (* ass 0.1)))
                col (list (1+ ass) (1+ (* ass 0.1)))   (list (1+ ass) (1- -ass))
                col (list (1+ ass) (1- -ass)) (list (1- (* -ass 0.1)) (1- -ass))
                col (list (1- (* -ass 0.1))   (1- -ass)) (list (1- (* -ass 0.1)) (1- (* -ass 0.1))))

          (list "_tan"
                col (list -ass ass) (list ass ass)
                col (list (1- -ass) (1+ ass)) (list (1+ ass) (1+ ass))
                col (list -ass 0.)  (list (* -ass 0.86) (* ass 0.5))
                col (list (* -ass 0.86) (* ass 0.5)) (list (* -ass 0.5) (* ass 0.86))
                col (list (* -ass 0.5) (* ass 0.86)) (list 0. ass)
                col (list 0. ass) (list  (* ass 0.5) (* ass 0.86))
                col (list (* ass 0.5)  (* ass 0.86)) (list (* ass 0.86) (* ass 0.5))
                col (list (* ass 0.86)  (* ass 0.5)) (list ass 0.)
                col (list ass 0.) (list (* ass 0.86) (* -ass 0.5))
                col (list (* ass 0.86) (* -ass 0.5)) (list (* ass 0.5) (* -ass 0.86))
                col (list (* ass 0.5) (* -ass 0.86)) (list 0. -ass)
                col (list 0. -ass)(list (* -ass 0.5) (* -ass 0.86))
                col (list (* -ass 0.5)(* -ass 0.86)) (list (* -ass 0.86) (* -ass 0.5))
                col (list (* -ass 0.86)(* -ass 0.5)) (list -ass 0.))

          (list "_per"
                col (list -ass -ass) (list -ass ass)
                col (list (1- -ass)  (1- -ass)) (list (1- -ass) (1+ ass))
                col (list ass -ass)  (list -ass -ass)
                col (list (1+ ass)   (1- -ass)) (list (1- -ass) (1- -ass))
                col (list -ass 0.)   (list 0. 0.)
                col (list -ass -1.)  (list 0. -1.)
                col (list 0. 0.)     (list 0. -ass)
                col (list -1. 0.)    (list -1. -ass))

          (list "_nea"
                col (list -ass -ass) (list ass ass)
                col (list -ass ass)  (list ass ass)
                col (list (1- -ass)  (1+ ass)) (list (1+ ass) (1+ ass))
                col (list -ass ass)  (list ass -ass)
                col (list ass -ass)  (list -ass -ass)
                col (list (1+ ass) (1- -ass)) (list (1- -ass) (1- -ass)))

          (list "_app"
                col (list -ass -ass) (list ass ass)
                col (list ass -ass)  (list -ass ass)
                col (list -ass -ass) (list -ass ass)
                col (list (1- -ass)  (1- -ass)) (list (1- -ass) (1+ ass))
                col (list -ass ass)  (list ass ass)
                col (list (1- -ass)  (1+ ass))  (list (1+ ass) (1+ ass))
                col (list ass ass)   (list ass -ass)
                col (list (1+ ass)   (1+ ass))  (list (1+ ass) (1- -ass))
                col (list ass -ass)  (list -ass -ass)
                col (list (1+ ass)   (1- -ass)) (list (1- -ass) (1- -ass)))))
             
  (defun _snap (p os)
    (if (osnap p (_getosmode os))
      (osnap p (_getosmode os))
      (progn
        (setq loop nil)
      (getpoint p (_getosmode os))
      )
    )
  )

  (defun _polarangs (ang / n k a l)
    (if (/= ang 0.0)
      (progn
        (setq n (/ 360.1 (cvunit ang "radians" "degrees")))
        (setq k -1.0)
        (repeat (1+ (fix n))
          (setq a (* (setq k (1+ k)) ang))
          (setq l (cons a l))
        )
        l
      )
      (list 0.0)
    )
  )

  (defun _polar (p0 p flag ang / a b an)
    (if flag
      (progn
        (setq a (car (vl-sort (_polarangs ang) '(lambda ( a b ) (< a (angle p0 p) b)))))
        (setq b (last (vl-sort (_polarangs ang) '(lambda ( a b ) (< a (angle p0 p) b)))))
        (if (< (abs (- (angle p0 p) a)) (abs (- (angle p0 p) b))) (setq an a) (setq an b))
        (inters p0 (polar p0 an 1.0) p (polar p (+ an (* 0.5 pi)) 1.0) nil)
      )
      p
    )
  )

  (defun _ortho (p0 p flag)
    (if flag
      (_polar p0 p t (* 0.5 pi))
      p
    )
  )

  (setq doc   (vla-get-ActiveDocument
                (vlax-get-acad-object))
       
        drft  (vla-get-drafting
                (vla-get-preferences
                  (vlax-get-acad-object)))
       
        osGrv (osmode-grvecs-lst
                (vla-get-AutoSnapMarkerColor drft)
                  (vla-get-AutoSnapMarkerSize drft)))
 
  ;;;--------- main function ---------;;;

  (setq pt (getpoint "\nPick or specify point : "))
  (setq loop t)
  (while (and loop (/= 3 (car (setq gr (grread 't 15 0)))))
    (redraw)
    (cond
      ( (and (= (car gr) 5) (listp (setq gp (cadr gr))))
        (if (and (< 0 (getvar "OSMODE") 16384)
                 (setq oPt (vl-remove-if (function null)
                             (mapcar
                               (function
                                 (lambda (x / o)
                                   (if (setq o (osnap gp x))
                                     (list (distance gp o) o x gp)))) (get_osmode)))))

          (setq oPt (cdar (vl-sort oPt (function (lambda (a b) (< (car a) (car b)))))))
          (setq oPt (list (osnap gp "_non") "_non" gp)))

        (and oPt (OsMark oPt))
        (cond
          ( (and o p s)
            (setq gps (_snap pt (getvar 'osmode)))
          )
          ( (and o (not p) s)
            (setq gps (_snap pt (getvar 'osmode)))
          )
          ( (and (not o) p s)
            (setq gps (_snap pt (getvar 'osmode)))
          )
          ( (and (not o) (not p) s)
            (setq gps (_snap pt (getvar 'osmode)))
          )
          ( (and o p (not s))
            (setq gps (_ortho pt gp t))
          )
          ( (and o (not p) (not s))
            (setq gps (_ortho pt gp t))
          )
          ( (and (not o) p (not s))
            (setq gps (_polar pt gp t (getvar 'polarang)))
          )
          ( (and (not o) (not p) (not s))
            (setq gps gp)
          )
        )
        (grdraw pt gps 3 1)
      )
      ( (and (= (car gr) 2) (= (cadr gr) 6))
        (cond
          ( (< 0 osm 16384) (setq osm (+ osm 16384)) (setvar 'osmode osm) )
          ( (>= osm 16384) (setq osm (- osm 16384)) (setvar 'osmode osm) )
        )
        (if (eq s t) (setq s nil) (setq s t))
      )
      ( (and (= (car gr) 2) (= (cadr gr) 15))
        (cond
          ( (= omo 0) (setq omo 1) (setvar 'orthomode 1) )
          ( (= omo 1) (setq omo 0) (setvar 'orthomode 0) )
        )
        (if (eq o t) (setq o nil) (setq o t))
      )
      ( (and (= (car gr) 2) (= (cadr gr) 21))
        (cond
          ( (= aus 0) (setq aus 8) (setvar 'autosnap 8) )
          ( (= aus 8) (setq aus 0) (setvar 'autosnap 0) )
          ( (= aus 16) (setq aus 24) (setvar 'autosnap 24) )
          ( (= aus 24) (setq aus 16) (setvar 'autosnap 16) )
        )
        (if (eq p t) (setq p nil) (setq p t))
      )
      ( (and (= (car gr) 2) (= (cadr gr) 23))
        (cond
          ( (= aus 0) (setq aus 16) (setvar 'autosnap 16) )
          ( (= aus 8) (setq aus 24) (setvar 'autosnap 24) )
          ( (= aus 16) (setq aus 0) (setvar 'autosnap 0) )
          ( (= aus 24) (setq aus 8) (setvar 'autosnap 8) )
        )
      )
    )
  )
  (command "_.line" "_non" pt "_non" gps "")
  (*error* nil)
)

 :-P
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #244 on: August 19, 2014, 08:49:39 AM »
Actually, no need for (grread) at all... My example simplify narrows to just a few lines of code...

Code: [Select]
(defun c:myline ( / osm _getosmode _snap pt )
 
  (setq osm (getvar 'osmode))

  (defun _getosmode (os / lst)
      (foreach mode
         '(
              (0001 . "_end")
              (0002 . "_mid")
              (0004 . "_cen")
              (0008 . "_nod")
              (0016 . "_qua")
              (0032 . "_int")
              (0064 . "_ins")
              (0128 . "_per")
              (0256 . "_tan")
              (0512 . "_nea")
              (1024 . "_qui")
              (2048 . "_app")
              (4096 . "_ext")
              (8192 . "_par")
          )
          (if (not (zerop (logand (car mode) os)))
              (setq lst (cons "," (cons (cdr mode) lst)))
          )
      )
      (apply 'strcat (cdr lst))
  )

  (defun _snap (p os)
    (getpoint p (_getosmode os))
  )

  (setq pt (getpoint "\nPick or specify point : "))
  (command "_.line" "_non" pt "_non" (_snap pt osm) "")
  (princ)
)

And I think this conclusion is useful in attempt to make something new... :2funny: :uglystupid2:
M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #245 on: August 19, 2014, 01:47:31 PM »
No joke, I've changed my versions to accept new markers, and when you actually try to implement (getpoint) trick along with (grread) then you realize you have to do it like Evgeniy and Lee did...

Only now I couldn't do it with reltro's code... Maybe someone can, who knows...

M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #246 on: August 19, 2014, 01:49:22 PM »
And this files...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

reltro

  • Guest
Re: Examples of usage GRREAD - let's share
« Reply #247 on: August 19, 2014, 02:27:26 PM »
No joke, I've changed my versions to accept new markers, and when you actually try to implement (getpoint) trick along with (grread) then you realize you have to do it like Evgeniy and Lee did...

Only now I couldn't do it with reltro's code... Maybe someone can, who knows...

M.R.

Can I help u? ;) wich code do u mean?

greets reltro

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #248 on: August 19, 2014, 02:33:39 PM »
Hi reltro... See attachment... This file : Rect,Ratio-bad.lsp

But no really big deal... I am satisfied and with how it's working now as it is...

Regards...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

roy_043

  • Water Moccasin
  • Posts: 1778
  • BricsCAD 18
Re: Examples of usage GRREAD - let's share
« Reply #249 on: August 20, 2014, 04:25:08 AM »
@ ribarm (post #244):
Does this really work in AC?:
Code: [Select]
(defun _snap (p os)
  (getpoint p (_getosmode os))
)
Note that the 'osmode string' is the prompt message.

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #250 on: August 20, 2014, 04:48:51 AM »
You're right Roy... It's message, but in my simply example this function is used, because of not correct results with "_tan" and "_per" snaps... I thought I could imitate (_snap) but from origin point and not from read point of (grread)... Unfortunately this is impossible as aperture can't be so large and never mind that for all other snaps my firstly posted example of c:myline works correct... So still I did conversion of my routines to accept new snap markers...

As always, your observation is excellent, thanks Roy...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

reltro

  • Guest
Re: Examples of usage GRREAD - let's share
« Reply #251 on: August 20, 2014, 02:16:09 PM »
Hi reltro... See attachment... This file : Rect,Ratio-bad.lsp

But no really big deal... I am satisfied and with how it's working now as it is...

Regards...

Hey Marko,
sry, but I do not get the code into my mind... can't rember wich parts of the code I wrote...

Greets reltro

ribarm

  • Water Moccasin
  • Posts: 2335
  • Marko Ribar, architect
Re: Examples of usage GRREAD - let's share
« Reply #252 on: August 20, 2014, 03:54:46 PM »
Hi reltro... See attachment... This file : Rect,Ratio-bad.lsp

But no really big deal... I am satisfied and with how it's working now as it is...

Regards...

Hey Marko,
sry, but I do not get the code into my mind... can't rember wich parts of the code I wrote...

Greets reltro

You posted it here :
http://www.theswamp.org/index.php?topic=12813.msg522054#msg522054

But as I said, no big deal... It's little, how to say, not so adequate for OSNAP implementation, but I did it with "X" marker in a post that follows link...

Thanks for interesting though...

Bye, M.R.
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Lee Mac

  • Seagull
  • Posts: 12373
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #253 on: August 25, 2014, 11:18:16 AM »
Some more examples of grread:

3-Point Rectangle



Star



Circle Tangents


ronjonp

  • Needs a day job
  • Posts: 7126
Re: Examples of usage GRREAD - let's share
« Reply #254 on: August 25, 2014, 11:59:04 AM »
Cool stuff Lee  8)

Windows 10 x64 - AutoCAD /C3D 2020

Custom Build PC