Author Topic: SOLVED! How can we find line's start and end point Z coordinates  (Read 1696 times)

0 Members and 1 Guest are viewing this topic.

scorpion76

  • Guest
I write code like this but i guess i have a little error :)
I want to calculate start and end point of line's Z coordinate.

Code: [Select]
(defun c:bol( / lne z1 z2 )
(setq lne (entsel "\nSelect Line..:"))

 (setq z1 (cdr (assoc 10 lne))) ;start point z value
 (setq z2 (cdr (assoc 11 lne))) ;end point z value

 (princ z1)

 )
« Last Edit: August 14, 2018, 04:23:04 PM by scorpion76 »

Crank

  • Water Moccasin
  • Posts: 1503
Re: How can we find line's start and end point Z coordinates
« Reply #1 on: August 14, 2018, 06:18:36 AM »
Code: [Select]
(setq lne (entget (car (entsel "\nSelect Line..:"))))
Code: [Select]
(setq z1 (cadddr (assoc 10 lne))) ;start point z valueor
Code: [Select]
(setq z1 (last (assoc 10 lne)))) ;start point z value
Vault Professional 2023     +     AEC Collection

scorpion76

  • Guest
Re: How can we find line's start and end point Z coordinates
« Reply #2 on: August 14, 2018, 06:37:09 AM »
Thanks Mr Crank for your reply, i write like this;

Code: [Select]
(defun c:bol( / lne z1 z2 z3 z4 strt end1)
;(setq lne (entsel "\nSelect Line..:"))

  (setq lne (entget (car (entsel "\nSelect Line..:"))))

  (setq z1 (cdr (assoc 10 lne)))

  (setq z2 (cdr (assoc 11 lne)))

  (setq strt (assoc 10 lne))
  (setq end1 (assoc 11 lne))

  (setq z3 (cddr z1)) ;start point z value
  (setq z4 (cddr z2)) ;end point z value

(command "text" "j" "tl" strt "1" "0" z3) ;
(command "text" "j" "tl" end1 "1" "0" z4) ;
)

I want to write at the start point , z coordinate and location of end point, z coordinat too.
« Last Edit: August 14, 2018, 06:41:23 AM by scorpion76 »

scorpion76

  • Guest
Re: How can we find line's start and end point Z coordinates
« Reply #3 on: August 14, 2018, 04:22:18 PM »
SOLVED...

Code: [Select]
(defun c:bol( / lne z1 z2 z3 z4 )


  (setq lne (entget (car (entsel "\nSelect Line..:"))))

  (setq z1 (cdr (assoc 10 lne)))

  (setq z2 (cdr (assoc 11 lne)))


  (setq z3 (caddr z1)) ;start point z value CDDR DEGIL CADDR
  (setq z4 (caddr z2)) ;end point z value CDDR DEGIL CADDR

(command "text" "j" "tl" z1 "1" "0" (rtos z3 2 2))
(command "text" "j" "tl" z2 "1" "0" (rtos z4 2 2))


 
(princ) ; PROGRAMIN DUZGUN SONLANMASI ICIN GEREKLI BITIS
)

ronjonp

  • Needs a day job
  • Posts: 7529
Re: SOLVED! How can we find line's start and end point Z coordinates
« Reply #4 on: August 15, 2018, 09:06:28 AM »
Some minor comments:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:bol (/ lne z1 z2 z3 z4)
  2.   ;; Check that the pick is  valid and we actually have a line
  3.   ;; Entget will $h!+ the bed if you pass it nothing
  4.   (if (and (setq lne (car (entsel "\nSelect Line..:"))) (= "LINE" (cdr (assoc 0 (entget lne)))))
  5.     (progn (setq z1 (cdr (assoc 10 (entget lne))))
  6.            (setq z2 (cdr (assoc 11 (entget lne))))
  7.            (setq z3 (caddr z1))         ;start point z value CDDR DEGIL CADDR
  8.            (setq z4 (caddr z2))         ;end point z value CDDR DEGIL CADDR
  9.            (command "text" "j" "tl" z1 "1" "0" (rtos z3 2 2))
  10.            (command "text" "j" "tl" z2 "1" "0" (rtos z4 2 2))
  11.     )
  12.   )
  13.   (princ)                               ; PROGRAMIN DUZGUN SONLANMASI ICIN GEREKLI BITIS
  14. )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC