Author Topic: Grread Ortho  (Read 1528 times)

0 Members and 1 Guest are viewing this topic.

hanhphuc

  • Newt
  • Posts: 64
Grread Ortho
« on: September 01, 2017, 09:14:42 AM »
hi guys, time flies happy September!
Just try to mimic ortho tracking by grread, sorry if anyone has done this before?
Here's my very basic attempt, no error handling etc..
To test just draw a 3-point-lwpolyline, then hover the mouse along entity or endpoints.

hope to see variants , thanks
Code: [Select]

(defun c:orthotest (/ xy xsnap lst d dat en ent fct in ip l mid midp midy n p px x y )
;hanhphuc 01.09.2017

  ;convert 2d point list
  (defun xy (p) (list (car p) (cadr p)))

  ;intersect osnap visual effect
  (defun xsnap (pt co)
    (grvecs
      (apply 'append
             (mapcar ''((x)
                        (list
                         co
                         pt
                         (polar pt (* x pi) (* 10. (/ (getvar 'viewsize) (cadr (getvar 'screensize)))))
                         )
                        )
                     '(0.25 0.75 1.25 1.75)
                     )
             )
      )
    pt
    )
 
  (and
       (setq ent (entsel "\nPick polyline.. "))
       (setq en (car ent))
       (= (cdr (assoc 0 (entget en))) "LWPOLYLINE")
       (not (redraw en 3))
       (setq l (mapcar ''((x) (xy (trans (cdr x) 0 1)))
                       (vl-remove-if ''((x) (/= (car x) 10)) (entget en))
                       )
             )
       (if (/= (length l) 3)
         (progn (cond ((> (length l) 3) (alert "\nThe selected polyline exceeds 3 vertices!"))
                      ((= (length l) 2) (alert "\nSelected polyline does not have vertices! New vertex added."))
                      )
                (setq p (mapcar ''((a b) (* 0.5 (+ a b))) (car l) (last l))
                      l (list (car l) p (last l))
                      p (xsnap p 40)
                      )
                )
         l
         )
       (setq lst l ; begin & end list
             ip  (cadr l)
             d   (- (car (last l)) (caar l))
             )
       (progn (while (and d (setq dat (grread t 2 13)) (= (car dat) 5) (setq p (cadr dat)))
                (redraw)
                (setq px (cond ((osnap p "nea"))
                               (p)
                               )
                      )
               
                ;FLEXIBLE END SNAP
                (setq fct (* 1e+5 (/ (getvar 'viewsize) (cadr (getvar 'screensize)))); polar max scale screen
                      n   (car (vl-sort-i (mapcar ''((x) (distance p x)) l) '<))
                      l   (subst (xy px) (nth n lst) lst)
                      )
                (if (= n 1) ;*** flag middle position between begin & end ***
                  (setq ip   (xy px)
                        l    (subst ip (cadr lst) lst)
                        midp (mapcar ''((a b) (* 0.5 (+ a b))) (car l) (caddr l))
                        x    (car midp)
                        mid  (equal (car ip) x (/ d 100.))
                        ip   (if mid
                               (progn (repeat 2 (grdraw midp (polar midp (* pi 0.5) (* d (setq fct (- fct)))) 7 1))
                                      (setq in
                                             (cond
                                               ((equal
                                                  (distance ip
                                                            (setq in (xy (inters (car lst) (cadr lst) midp (polar midp (* pi 0.5) d) nil)))
                                                            )
                                                  0.0
                                                  (/ d 100.)
                                                  )
                                                (xsnap in 6)
                                                (cadr in)
                                                )
                                               ((equal
                                                  (distance ip
                                                            (setq in (xy (inters (cadr lst) (last lst) midp (polar midp (* pi 0.5) d) nil)))
                                                            )
                                                  0.0
                                                  (/ d 100.)
                                                  )
                                                (xsnap in 6)
                                                (cadr in)
                                                )
                                               (t (xsnap (list x (cadr ip)) 40) (cadr ip))
                                               )
                                            )
                                      (list x in)
                                      ) ; progn
                               ip
                               )
                        l    (list (car l) ip (last l))
                        ) ;setq
                  (setq ip   (cadr lst)
                        y    (cadadr lst)
                        midy (equal (cadr (nth n l)) y (* (/ (getvar 'viewsize) (cadr (getvar 'screensize))) 1.0))
                        px   (if midy
                               (progn (setq px (list (car px) y))
                                      (repeat 2 (grdraw (cadr lst) (polar (cadr lst) 0. (* d (setq fct (- fct)))) 7 1))
                                      (xsnap px 40)
                                      px
                                      )
                               (xy px)
                               )
                        l    (subst px (nth n lst) lst)
                        )
                  ) ; if
               
                (mapcar ''((a b)
                           (grdraw
                            a
                            b
                            (if
                             mid
                             1
                             8
                             )
                            )
                           )
                        l
                        (cdr l)
                        )

                ) ; while
              (redraw)
         
              (entmakex (vl-list* '(0 . "LWPOLYLINE")
                        '(100 . "AcDbEntity")
                        '(100 . "AcDbPolyline")
                        '(70 . 0)
                        (cons 90 (length l))
                        (mapcar ''((x) (cons 10 (trans x 1 0))) l)
                        )
              )
           
              (if en
                (entdel en)
                )
              ) ; progn
       ) ;and

  (princ)
  )


p/s: The demo purposely referenced to the middle (between 2 endpoints), not exactly at the vertex

[EDIT] Attachment added. Demo: dynamic changes on curve


« Last Edit: September 01, 2017, 08:35:25 PM by hanhphuc »
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments

Lee Mac

  • Seagull
  • Posts: 12922
  • London, England
Re: Grread Ortho
« Reply #1 on: September 01, 2017, 12:37:55 PM »
Interesting program, though a little buggy as the cursor is moved around...

You may find this of some interest: Ortho Point

hanhphuc

  • Newt
  • Posts: 64
Re: Grread Ortho
« Reply #2 on: September 01, 2017, 01:40:21 PM »
Interesting program, though a little buggy as the cursor is moved around...

You may find this of some interest: Ortho Point

Wow the legend always steps ahead! your Ortho programs are more generic nice !
buggy maybe d divided by 100, i should subscribe your site more often very good resources.
Thanks Lee for the input

[EDIT] Image attachment issue solved
p/s: It seems failed to embed by image tag?
[ img ] http://imgur.com/tNI7jCH ?[/ img]

« Last Edit: September 01, 2017, 08:09:10 PM by hanhphuc »
( apply 'equal "hp" "happy" "hạnh phúc" "ハッピー" "幸福" "행복" ) ; error: too many arguments