@nislam04,
I used the VLIDE 'Format' tool to improve readability of your posted code.
Here are the changes I made to add a comma (,) after the Z1 value:
Original:
(if (= tip "LWPOLYLINE")
(while (setq eg (member (assoc 10 eg) eg))
(setq ;|a000|;
pnt (cdr (car eg))
$rr (cons (dfn_ent_point10 "2,3" pnt) $rr)
eg (cdr eg)
)
)
)
Modified:
(if (= tip "LWPOLYLINE")
(while (setq eg (member (assoc 10 eg) eg))
(setq ;|a000|;
pnt (cdr (car eg))
$rr (cons (strcat (dfn_ent_point10 "2,3" pnt) ",") $rr)
eg (cdr eg)
);_setq
);_while
);_if
This resulted in an extra comma after the last coordinate.
I added code to remove the extra comma from the first element in the $rr list.
Here are the code changes:
Original:
(if (/= $rr nil)
(setq ;|a000|;
tmp (apply (read rst) (reverse $rr))
fly (open fna "a")
nop (write-line tmp fly)
nop (close fly)
)
)
Modified:
(if (/= $rr nil)
(progn
;; remove "," from first element in list
(if (= (substr (car $rr) (strlen (car $rr)) 1) ",")
(setq
$rr (LM:SubstNth
(substr (car $rr) 1 (1- (strlen (car $rr)))) ;; first element in list with ending "," removed
0 ;; position 0 in $rr list
$rr ;; the list
);_LM:SubstNth
);_setq
);_if
;;
(setq ;|a000|;
tmp (apply (read rst) (reverse $rr))
fly (open fna "a")
nop (write-line tmp fly)
nop (close fly)
);_setq
);_progn
);_if
I used (and credited) code from Lee Mac ( @Lee_Mac ) to substitute the first element in the list with the string that has had the extra comma removed.
Source: http://www.lee-mac.com/substn.html
;;---------------------=={ Subst Nth }==----------------------;;
;; ;;
;; Substitutes an item at the nth position in a list. ;;
;;------------------------------------------------------------;;
;; Author: Lee Mac, Copyright © 2011 - www.lee-mac.com ;;
;;------------------------------------------------------------;;
;; Arguments: ;;
;; a - item to substitute ;;
;; n - position in list to make the substitution ;;
;; l - list in which to make the substitution ;;
;;-----------------------------------------------------Show more-------;;
;; Returns: Resultant list following the substitution ;;
;;------------------------------------------------------------;;
(defun LM:SubstNth ( a n l / i )
(setq i -1)
(mapcar '(lambda ( x ) (if (= (setq i (1+ i)) n) a x)) l))
Be advised - your code does not output the correct Z value for LWPolylines that are not at elevation Z=0.
I have attached the code with my changes shown above.
I hope this is helpful. Please mark as solution if this answers your request.
Regards,
Jerry
-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional