Author Topic: setting to ZERO the ZETA of VERTEXES . . .  (Read 1342 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 725
setting to ZERO the ZETA of VERTEXES . . .
« on: May 31, 2021, 04:43:14 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun C:LINE,PLINE>ZETA-ZERO ( / i ind n-rep new-el p10 p11 ss x-el x-en x-et x-pt)
  2.    (setq ss (LM:SSGET "\nselect LINEs and POLYLINEs to SET VERTEXES to ZETA=0 : " '(((0 . "LINE,LWPOLYLINE"))) ) )
  3.    (setq n-rep (sslength ss) ind 0)
  4.    (repeat n-rep
  5.       (setq x-en   (ssname ss ind )
  6.             x-el   (entget x-en   )
  7.             x-et   (:DXF 0 x-el   )
  8.       )
  9.       (cond
  10.          (   (= x-et "LINE")
  11.              (setq p10 (:DXF 10 x-el)   p11 (:DXF 11 x-el)
  12.                     x-el (subst (cons 10 (list (car p10) (cadr p10) 0.0) ) (cons 10 p10)  x-el)
  13.                     x-el (subst (cons 11 (list (car p11) (cadr p11) 0.0) ) (cons 11 p11)  x-el)
  14.              )
  15.              (entmod x-el)
  16.          )
  17.          (   (= x-et "LWPOLYLINE")
  18.              (setq  new-el
  19.                    (mapcar '(lambda (i)
  20.                               (if (and (= (car i) 10) (setq x-pt (cdr i)))
  21.                                  (cons 10 (list (car x-pt) (cadr x-pt) 0.0))
  22.                                  i
  23.                               )
  24.                            )
  25.                           x-el
  26.                   )
  27.              )
  28.              (entmod new-el) (entupd x-en)
  29.              ;   (setq new-el-s new-el)  
  30.          )
  31.       )
  32.       (setq ind (+ 1 ind) )
  33.    )
  34. )

Why with LWPOLYLINE it doesn't work ?

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #1 on: May 31, 2021, 05:00:01 AM »
ok

I need to change the elevation too !

38 !


And if the LWPOLYLINE is 3D-rotated and its UCS is not WCS ?

what to do to project it in the XY plane?

TRANS ? i suppose !  :idiot2:

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #2 on: May 31, 2021, 06:56:26 AM »
Untested, you are missing sub functions (LM:ssget) and (:DXF)...

Code - Auto/Visual Lisp: [Select]
  1. (defun C:LINE,PLINE>ZETA-ZERO ( / i ind n-rep new-el p10 p11 ss x-el x-en x-et x-pt )
  2.   (setq ss (LM:SSGET "\nselect LINEs and POLYLINEs to SET VERTEXES to ZETA=0 : " '(((0 . "LINE,LWPOLYLINE"))) ) )
  3.   (setq n-rep (sslength ss) ind 0)
  4.   (repeat n-rep
  5.      (setq x-en   (ssname ss ind )
  6.            x-el   (entget x-en   )
  7.            x-et   (:DXF 0 x-el   )
  8.      )
  9.      (cond
  10.         (   (= x-et "LINE")
  11.             (setq p10 (:DXF 10 x-el)   p11 (:DXF 11 x-el)
  12.                    x-el (subst (cons 10 (list (car p10) (cadr p10) 0.0) ) (cons 10 p10)  x-el)
  13.                    x-el (subst (cons 11 (list (car p11) (cadr p11) 0.0) ) (cons 11 p11)  x-el)
  14.             )
  15.             (entmod x-el)
  16.         )
  17.         (   (= x-et "LWPOLYLINE")
  18.             (setq new-el
  19.                   (mapcar '(lambda (i)
  20.                              (if (and (= (car i) 10) (setq x-pt (cdr i)))
  21.                                 (cons 10 (trans x-pt x-en 1))
  22.                                 i
  23.                              )
  24.                           )
  25.                          x-el
  26.                  )
  27.             )
  28.             (setq new-el (subst (cons 210 (trans '(0.0 0.0 1.0) 1 0 t)) (assoc 210 new-el) new-el))
  29.             (setq new-el (subst (cons 38 0.0) (assoc 38 new-el) new-el))
  30.             (entmod new-el) (entupd x-en)
  31.         )
  32.      )
  33.      (setq ind (+ 1 ind) )
  34.   )
  35. )
  36.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #3 on: May 31, 2021, 08:04:13 AM »
;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
    (princ msg)
    (setvar 'nomutt 1)
    (setq sel (vl-catch-all-apply 'ssget arg))
    (setvar 'nomutt 0)
    (if (not (vl-catch-all-error-p sel)) sel)
)

(defun :DXF (code elist) (cdr (assoc code elist)))

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #4 on: May 31, 2021, 08:09:25 AM »
Code - Auto/Visual Lisp: [Select]
  1. (defun C:LINE,PLINE>ZETA-ZERO ( / i ind n-rep new-el p10 p11 ss x-el x-en x-et x-pt)
  2.    ;   (:UNDO-GROUP-BEGIN)
  3.    (setq ss (LM:ssget "\nselect LINEs and POLYLINEs to SET VERTEXES to ZETA=0 : " '(((0 . "LINE,LWPOLYLINE"))) ) )
  4.    (setq n-rep (sslength ss) ind 0)
  5.    (repeat n-rep
  6.       (setq x-en    (ssname ss ind )
  7.             x-el   (entget x-en   )
  8.             x-et   (:DXF 0 x-el   )
  9.       )
  10.       (cond
  11.          (   (= x-et "LINE")
  12.              (setq p10 (:DXF 10 x-el)   p11 (:DXF 11 x-el)
  13.                     x-el (subst (cons 10 (list (car p10) (cadr p10) 0.0) ) (cons 10 p10)  x-el)
  14.                     x-el (subst (cons 11 (list (car p11) (cadr p11) 0.0) ) (cons 11 p11)  x-el)
  15.              )
  16.              (entmod x-el)
  17.          )
  18.          
  19.          (   (= x-et "LWPOLYLINE")
  20.              (setq  new-el
  21.                   (mapcar '(lambda (i)
  22.                               (cond
  23.                                  (   (and (= (car i) 10) (setq x-pt (cdr i) ) )  
  24.                                     (cons 10 (list (car x-pt) (cadr x-pt) 0.0))
  25.                                  )
  26.                                  (   (and (= (car i) 38) (/= (cdr i) 0.0))
  27.                                     (cons 38 0.0)
  28.                                  )
  29.                                  (t i)
  30.                               )
  31.                            )
  32.                            x-el
  33.                   )
  34.              )
  35.              (entmod new-el)   (entupd x-en)
  36.              ;   (setq new-el-s new-el)  
  37.          )
  38.       )
  39.       (setq ind (+ 1 ind) )
  40.    )
  41.    ;   (:UNDO-GROUP-END)
  42.    ind
  43. )

this is the working code . . .
. . .
but i want understand
if the LWPOLYLINE is 3D-rotated and its CS is not parallel to WCS
what to do to project it to get its projection in the XY plane . . .
. . .
I suppose I have to study some Lee Mac code  . . .
« Last Edit: May 31, 2021, 08:18:01 AM by domenicomaria »

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #5 on: June 01, 2021, 03:51:59 AM »
i am trying to project a (3d rotated) lwpolyline in the XY plane.

The following code, works.

It modifies the lwpolyline and the result is the projection of it, in the XY plane
. . .
but the good result, is TRANSLATED along the Y axis !

And I am not able to understand why this happens !

I probably omit a displacement . . .

When I use TRANS ?


Code - Auto/Visual Lisp: [Select]
  1. (defun :DXF (code elist) (cdr (assoc code elist)))
  2. (defun C:LWP>XY ( / i new-el x-210 x-el x-en x-pt )
  3.    (setq x-en  (car (entsel "\nselect a LWPOLYLINE to project into XY plane : "))
  4.          x-el  (entget   x-en )
  5.          x-210 (:DXF 210 x-el )
  6.    )
  7.              
  8.    (setq  new-el
  9.          (mapcar '(lambda (i)
  10.                      (cond
  11.                         (   (and (= (car i) 10) (setq x-pt (trans (cdr i) x-210 0) ) )
  12.                             (cons 10 (list (car x-pt) (cadr x-pt) ) )
  13.                         )
  14.                         (   (= (car i) 38)  (cons 38 0.0)   )
  15.                         (   (= (car i) 210) (cons 210 '(0 0 1) )   )
  16.                         (t i)
  17.                      )
  18.                   )
  19.                   x-el
  20.          )
  21.    )
  22.    (entmod new-el)
  23.    (entupd x-en)
  24.    (setq new-el-s new-el)
  25. )
« Last Edit: June 01, 2021, 03:55:40 AM by domenicomaria »

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #6 on: June 01, 2021, 09:06:56 AM »
you need to translate the points as 3D points. IOW you need to add the elevation to the 2D GC 10 points, translate, and then remove the Z.

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #7 on: June 01, 2021, 01:11:23 PM »
you need to translate the points as 3D points. IOW you need to add the elevation to the 2D GC 10 points, translate, and then remove the Z.

Code - Auto/Visual Lisp: [Select]
  1. (defun :DXF (code elist) (cdr (assoc code elist)))
  2. (defun :PT-3D>2D (ptx) (list (car ptx)(cadr ptx)))
  3. (defun :PT-SET-Z (ptx z) (list (car ptx)(cadr ptx) z) )
  4.  
  5. (defun C:LWP>XY ( / i new-el x-38 x-el x-en x-pt )
  6.    
  7.    (setq x-en  (car (entsel "\nselect POLYLINEs to project into XY plane : "))
  8.          x-el  (entget   x-en )
  9.          x-38  (:DXF 38  x-el )
  10.    )
  11.              
  12.    (setq  new-el
  13.          (mapcar '(lambda (i)
  14.                      (cond
  15.                         (   (and (= (car i) 10)
  16.                                 (setq x-pt (:PT-SET-Z (cdr i) x-38) )
  17.                                 (setq x-pt (trans x-pt x-en 0 t) )
  18.                             )
  19.                             (cons 10 (:PT-3D>2D x-pt) )
  20.                         )
  21.                         (   (= (car i) 38)  (cons 38 0.0)   )
  22.                         (   (= (car i) 210) (cons 210 '(0 0 1) )   )
  23.                         (t i)
  24.                      )
  25.                   )
  26.                   x-el
  27.          )
  28.    )
  29.    (entmod new-el)
  30.    (entupd x-en)
  31. )
  32.  
  33.  
  34. (defun c:k () (C:LWP>XY) )


roy_043
thank you.

It works well, now .
But I have still to understand well, why it works . . .

ciao

domenicomaria

  • Swamp Rat
  • Posts: 725
Re: setting to ZERO the ZETA of VERTEXES . . .
« Reply #8 on: June 03, 2021, 01:32:18 AM »
however, I found this SUPERFLATTEN, which is "slightly"  :? :lol: better. . .

http://www.theswamp.org/index.php?topic=18153.0