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

0 Members and 1 Guest are viewing this topic.

alanjt

  • Needs a day job
  • Posts: 5328
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #90 on: March 07, 2011, 10:38:47 AM »
You could also use fields within a block to display the coordinates.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

stevesfr

  • Newt
  • Posts: 54
Re: Examples of usage GRREAD - let's share
« Reply #91 on: March 07, 2011, 11:56:19 AM »
It does have a dependence on the TTF file being available.

I have modified it slightly, perhaps try the attached.

Lee, one thing puzzles me...  when the program inserts the leader block and you explode it, the attributes are listed as North, East, Elev, and Description.    However before exploding, the attributes are really East, North, Elev and Description.   How did the North and East get reversed ?  I know you math guys think of x and y, but we engineers/surveyors think N and E  (y and x).  How can we get the block to tell the "truth" ?
Steve
Can't remember what I'm supposed to forget.

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #92 on: March 07, 2011, 03:01:08 PM »
It does have a dependence on the TTF file being available.

I have modified it slightly, perhaps try the attached.

Lee, one thing puzzles me...  when the program inserts the leader block and you explode it, the attributes are listed as North, East, Elev, and Description.    However before exploding, the attributes are really East, North, Elev and Description.   How did the North and East get reversed ?  I know you math guys think of x and y, but we engineers/surveyors think N and E  (y and x).  How can we get the block to tell the "truth" ?
Steve

That's probably a mistake on my part - I changed the code quite hastily to get it to work for you...

Please try the updated code.
« Last Edit: March 07, 2011, 04:11:35 PM by Lee Mac »

stevesfr

  • Newt
  • Posts: 54
Re: Examples of usage GRREAD - let's share
« Reply #93 on: March 07, 2011, 04:33:48 PM »
Lee,  thanks mate. 
Steve
Can't remember what I'm supposed to forget.

alanjt

  • Needs a day job
  • Posts: 5328
  • Standby for witty remark...
« Last Edit: March 08, 2011, 12:46:25 PM by alanjt »
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #95 on: March 07, 2011, 05:33:42 PM »
That looks crazy!  :lol:

Was looking at Evgeniy's example of 'line<45' at the start of the thread, perhaps this might be another way to code it:

Code: [Select]
(defun c:test ( / p l g )
  (if (setq p (getpoint "\nSpecify First Point: "))
    (progn
      (setq l
        (entget
          (entmakex
            (list
              (cons 0 "LINE") (cons 10 (trans p 1 0)) (cons 11 (trans p 1 0))
            )
          )
        )
      )
      (princ "\nSpecify Next Point: ")
      (while (= 5 (car (setq g (grread t 13 0))))
        (entupd
          (cdr
            (assoc -1
              (entmod
                (list (assoc -1 l)
                  (cons 11
                    (trans
                      (polar p (/ pi 4.)
                        (
                          (if
                            (minusp
                              (
                                (lambda ( n )
                                  (- (caddr (trans (cadr g) 1 n)) (caddr (trans p 1 n)))
                                )
                                (polar '(0. 0. 0.) (/ pi 4.) 1.)
                              )
                            )
                            - +
                          )
                          (distance p (cadr g))
                        )
                      )
                      1 0
                    )
                  )
                )
              )
            )
          )
        )
      )
    )
  )
  (princ)
)

chlh_jd

  • Guest
Re: Examples of usage GRREAD - let's share
« Reply #96 on: March 08, 2011, 05:59:47 AM »
hi Goodfellas ,
Have you encountered grread cursor lag, particularly in the drawing which has a large number of TrueType fonts used .
e.g.
Code: [Select]
(defun cs_ENTSEL (STR FILTER / PT SS_NAME area_mid SS old_modemacro)
  (setq old_modemacro (getvar "MODEMACRO"))    
  (if (/= (type STR) 'STR)
    (progn
      (princ "\n变量类型不对,STR应为字符串。\n")
      (eval NIL)
    )
    (progn
      (if (/= (type FILTER) 'list)
(progn
 (princ "\n变量类型不对,FILTER应为表。\n")
 (eval NIL)
)
(progn
 (princ STR)
 (setq PT (grread t 4 2))
 (setq is_go_on t)
 (while (and (/= 3 (car PT))
     (/= 25 (car pt))
     is_go_on
)
   (cond
     ((and (= 2 (car pt))
   (or (= 13 (cadr pt)) (= 32 (cadr pt)))
      ) ;_Enter,Space.
      (setq is_go_on nil)
     )
     ((and (= 2 (car pt))
   (or (= 115 (cadr pt)) (= 83 (cadr pt)))
      ) ;_S set arg.
      (if (dcl_Form_IsActive CS_ODCLINIT)
nil
(c:asd)
      )
      (setq is_go_on t)
     )
     (t
      (progn
(if (= 5 (car PT))
  (progn
    (setq PT (cadr PT))
    (setq SS (ssget PT FILTER)) ;_perhaps this take a lag !
    (if SS_NAME
      (progn
(redraw SS_NAME 4) ;_release high-display .
      )
    )
  ) ;_progn
)
(setq SS_NAME NIL)
(if SS
  (progn
    (setq str (cdr (assoc 1 (entget (ssname SS 0)))))
    (setq SS_NAME (ssname SS 0))
    (redraw SS_NAME 3)
  )
  (setvar "MODEMACRO" old_modemacro)
)
      ) ;_progn
     )
   ) ;_cond
   (setq PT (grread t 4 2))
 ) ;_while
 (setvar "MODEMACRO" old_modemacro)  
 (if (/= 25 (car pt))
   (progn
     (setq PT (cadr PT))
     (setq SS (ssget PT FILTER))
     (if SS_NAME
(redraw SS_NAME 4)
     )
     (setq SS_NAME NIL)
     (if SS
(progn
 (setq SS_NAME (ssname SS 0))
 (list PT SS_NAME)
)
(list PT)
     )
   )
   nil
 )
)
      )
    )
  )
)
for test code
Code: [Select]
(defun c:test (/ en)
  (setq
      en
       (cs_ENTSEL
"\n请选取计算书或配筋文字[设置(S)]:"
'((1
   .
   "G*[-=]*,*[-=]*[-=]*,VT*[-=]*,*%%13[01234]*,N*%%13[01234],*L*,*[xX]*"
  )
 )
       )
    )
  (princ en)
  )

« Last Edit: March 08, 2011, 06:11:01 AM by chlh_jd »

alanjt

  • Needs a day job
  • Posts: 5328
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #97 on: March 08, 2011, 10:16:36 AM »
That looks crazy!  :lol:

Was looking at Evgeniy's example of 'line<45' at the start of the thread, perhaps this might be another way to code it:
Nicely done Lee. I  actually coded this just yesterday and was wondering how you could code it to account for the opposite direction.

Code: [Select]
(defun _grAtAngle (pt ang / gr point)
  (while
    (progn (setq gr (grread T 15 0))
           (cond ((eq 5 (car gr)) (redraw) (grdraw pt (polar pt ang (distance pt (cadr gr))) 7 -1) T)
                 ((eq 3 (car gr)) (setq point (cadr gr)) (redraw))
           )
    )
  )
  point
)

Don't think I ever linked these:  http://www.theswamp.org/index.php?topic=33469.0

Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #98 on: March 08, 2011, 10:47:27 AM »
Cheers Alan :-)

Perhaps two methods:

Code: [Select]
(defun line<ang ( p a / g )
  (while (= 5 (car (setq g (grread t 13 0)))) (redraw)
    (grdraw p
      (polar p a
        (
          (if
            (minusp
              (
                (lambda ( n )
                  (- (caddr (trans (cadr g) 1 n)) (caddr (trans p 1 n)))
                )
                (polar '(0. 0. 0.) a 1.)
              )
            )
            - +
          )
          (distance p (cadr g))
        )
      )
      -1
    )
  )
  (redraw) (if (listp (cadr g)) (cadr g))
)

Code: [Select]
(defun line<ang ( p a / g )
  (while (= 5 (car (setq g (grread t 13 0)))) (redraw)
    (grdraw p
      (polar p a
        (
          (if (minusp (cos (- (angle p (polar p a 1.)) (angle p (cadr g)))))
            - +
          )
          (distance p (cadr g))
        )
      )
      -1
    )
  )
  (redraw) (if (listp (cadr g)) (cadr g))
)

 :-)

alanjt

  • Needs a day job
  • Posts: 5328
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #99 on: March 08, 2011, 10:57:38 AM »
Cheers Alan :-)

Perhaps two methods:

Code: [Select]
(defun line<ang ( p a / g )
  (while (= 5 (car (setq g (grread t 13 0)))) (redraw)
    (grdraw p
      (polar p a
        (
          (if
            (minusp
              (
                (lambda ( n )
                  (- (caddr (trans (cadr g) 1 n)) (caddr (trans p 1 n)))
                )
                (polar '(0. 0. 0.) a 1.)
              )
            )
            - +
          )
          (distance p (cadr g))
        )
      )
      -1
    )
  )
  (redraw) (if (listp (cadr g)) (cadr g))
)

Code: [Select]
(defun line<ang ( p a / g )
  (while (= 5 (car (setq g (grread t 13 0)))) (redraw)
    (grdraw p
      (polar p a
        (
          (if (minusp (cos (- (angle p (polar p a 1.)) (angle p (cadr g)))))
            - +
          )
          (distance p (cadr g))
        )
      )
      -1
    )
  )
  (redraw) (if (listp (cadr g)) (cadr g))
)

 :-)
Care to explain the method/math? I *think* I get the cosine one, but I'm not 100% and I don't understand the trans one at all.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #100 on: March 08, 2011, 11:15:02 AM »
Care to explain the method/math? I *think* I get the cosine one, but I'm not 100% and I don't understand the trans one at all.

For the Cosine one, I use the angle enclosed by a unit vector (call it 'u') from the basepoint at angle 'a', and the vector formed by the basepoint and cursor position (call it 'v'), with the angle measured anticlockwise from vector 'v' to vector 'u'. For quadrants where the cursor lies above the vector perpendicular to vector 'u', the angle enclosed is either < pi/2 or > 3pi/2, and for those quadrants where the cursor lies below, the angle is pi/2 < ang < 3pi/2. I then use the fact that the cosine function changes sign for these intervals.

For the 'trans' method, I define a coordinate system whose normal is in the direction of vector 'u', then I take the elevation of the cursor position relative to the base point as defined in this new coordinate system, should the difference be negative, the cursor lies in the quadrants below the vector perpendicular to vector 'u', else it lies above.

Quick Diagram (don't have too much time atm):



Hope this is somewhat clear  :|

Lee
« Last Edit: March 08, 2011, 11:20:11 AM by Lee Mac »

alanjt

  • Needs a day job
  • Posts: 5328
  • Standby for witty remark...
Re: Examples of usage GRREAD - let's share
« Reply #101 on: March 08, 2011, 12:39:30 PM »
OK, I understand the cosine one. The trans one is a little beyond me - haven't spent much time messing with trans, other than the norm (no pun intended), but I'm going to study it some more. Thanks, Lee.
Civil 3D 2019 ~ Windohz 7 64bit
Dropbox

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #102 on: March 08, 2011, 01:44:21 PM »
You're welcome Alan.

Lee Mac

  • Seagull
  • Posts: 12372
  • London, England
Re: Examples of usage GRREAD - let's share
« Reply #103 on: March 08, 2011, 02:48:36 PM »
My above explanation regarding the 'trans' method was quite poor, so I have spent some time constructing a diagram that will hopefully explain the method with more clarity.

I shall link you to the image, since it is rather large for the post:

Trans Diagram

The part of the code we are concerned with is:

Code: [Select]
(
  (lambda ( n )
    (- (caddr (trans (cadr g) 1 n)) (caddr (trans p 1 n)))
  )
  (polar '(0. 0. 0.) a 1.)
)

On my diagram I have labelled the Base Point ['p' in the code], and a diagrammatic cursor represents the Cursor Position ['(cadr g)' in the code]. The WCS is shown in cyan in the diagram.

Now, I define a coordinate system with Normal vector at an angle 'a' to the WCS X-Axis, this coordinate system I have shown in green. The normal vector in the code is the unit vector:

Code: [Select]
(polar '(0. 0. 0.) a 1.)
For WCS this vector would be '(0.0 0.0 1.0).

In this coordinate system, just need to check the difference in elevation (Z-Value) between the Cursor position (transformed to be relative to the new Coordinate System) and the Base Point (also transformed to be expressed relative to the new Coordinate System). These elevations are shown in dashed red in the diagram.

Hence, as shown in the code:

Code: [Select]
(- (caddr (trans (cadr g) 1 n)) (caddr (trans p 1 n)))
I subtract the Z-Coordinate of the transformed Cusor Position from the Z-Coordinate of the transformed Base Point, if negative, the cursor is below the X-Axis of the defined coordinate system, and hence the direction needs to be reversed.

I hope this is clearer - if you have any questions, just ask.

Lee
« Last Edit: March 09, 2011, 09:11:26 AM by Lee Mac »

chlh_jd

  • Guest
Re: Examples of usage GRREAD - let's share
« Reply #104 on: March 08, 2011, 07:35:06 PM »
hi
another use just for fun .
Code: [Select]
(defun fe-follow-mouse (_sset / pos_mouse pt_mouse pt)
  ;;(command "_.copy" _sset "" (list 0 0 0) (list 0 0 0))
  (setvar "OSMODE" 0)
  (command)
  (setq pt (cadr (grread t 1 0)))
  (while (= (car (setq pos_mouse (grread t 1 0))) 5)
    (setq pt_mouse (cadr pos_mouse))
    (command "_.move" _sset "" pt pt_mouse)
    (setq pt pt_mouse)
  )
)