sd2006 Posted yesterday at 03:35 PM Posted yesterday at 03:35 PM (edited) Could you please take a look and explain why this Lisp program is producing this result? 27807.35m² Please help me adjust the result. 27807.35m² I know nothing about Lisp. thank you . (defun rh:dxf (code lst) (cdr (assoc code lst))) (defun c:aa ( / cmde ent e_typ e_lst area vtx x_lst y_lst z_lst x_pt y_pt z_pt c_lst v_lst ss sum) (cond ( (/= 0 (getvar 'cmdecho)) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) ) ) (while (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 3) (70 . 5) (-4 . "OR>") ) )) (setq ent (ssname ss 0) e_typ (rh:dxf 0 (setq e_lst (entget ent))) area (getpropertyvalue ent "area") v_lst nil ) (cond ( (= e_typ "POLYLINE") (setq ent (entnext ent) vtx (rh:dxf 10 (entget ent)) ) (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx))))) (while (/= "SEQEND" (cdr (assoc 0 (entget ent)))) (setq v_lst (cons vtx v_lst) ent (entnext ent) vtx (rh:dxf 10 (entget ent)) ) (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx))))) ) (setq x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst)) y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst)) ) (if (= (setq sum (apply '+ (mapcar '(lambda (x) (caddr x)) v_lst))) 0.0) (setq z_pt 0.0) (setq z_pt (/ sum (length v_lst))) ) ) ( (= e_typ "LWPOLYLINE") (setq z_pt (rh:dxf 38 e_lst)) (foreach pr e_lst (if (= (car pr) 10) (setq v_lst (cons (cdr pr) v_lst))) ) (setq x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst)) y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst)) ) ) ) (setq c_lst (list x_pt y_pt z_pt)) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 c_lst) (cons 40 (getvar 'textsize)) (cons 71 5) (cons 72 5) (cons 1 (strcat (rtos (/ area 1000000.0) 2 2) "m²")) ; (cons 1 (rtos (/ area 1000000.0) 2 3)) ; If you don't need the suffix "m²" ) ) ) (if cmde (setvar 'cmdecho cmde)) ) Edited yesterday at 03:43 PM by SLW210 Added Code Tags!! Quote
SLW210 Posted yesterday at 03:45 PM Posted yesterday at 03:45 PM Please use Code Tags for your code in the future. (press the <> in the editor toolbar) Quote
mhupp Posted yesterday at 04:00 PM Posted yesterday at 04:00 PM (edited) chr instead of string. (cons 1 (strcat (rtos (/ area 1000000.0) 2 2) "m" (chr 0178))) also might be the font your using. https://www.cadtutor.net/forum/topic/75383-text-ascii/#findComment-596226 Edited 22 hours ago by mhupp 2 Quote
yangguoshe Posted 13 hours ago Posted 13 hours ago try this (cons 1 (strcat (rtos (/ area 1000000.0) 2 2) "m\U+00B2")) 1 Quote
sd2006 Posted 3 hours ago Author Posted 3 hours ago thank you @yangguoshe but error error: no function definition: RH:DXF help me. Quote
pkenewell Posted 54 minutes ago Posted 54 minutes ago 2 hours ago, sd2006 said: thank you @yangguoshe but error error: no function definition: RH:DXF help me. You must've copied the changes into your code incorrectly. "RH: DXF" is already defined in your original code. (defun rh:dxf (code lst) (cdr (assoc code lst))) Attached is your original code with @mhupp's change: (defun rh:dxf (code lst) (cdr (assoc code lst))) (defun c:aa ( / cmde ent e_typ e_lst area vtx x_lst y_lst z_lst x_pt y_pt z_pt c_lst v_lst ss sum) (cond ( (/= 0 (getvar 'cmdecho)) (setq cmde (getvar 'cmdecho)) (setvar 'cmdecho 0) ) ) (while (setq ss (ssget "_+.:E:S" '((0 . "POLYLINE,LWPOLYLINE") (-4 . "<OR") (70 . 1) (70 . 3) (70 . 5) (-4 . "OR>") ) )) (setq ent (ssname ss 0) e_typ (rh:dxf 0 (setq e_lst (entget ent))) area (getpropertyvalue ent "area") v_lst nil ) (cond ( (= e_typ "POLYLINE") (setq ent (entnext ent) vtx (rh:dxf 10 (entget ent)) ) (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx))))) (while (/= "SEQEND" (cdr (assoc 0 (entget ent)))) (setq v_lst (cons vtx v_lst) ent (entnext ent) vtx (rh:dxf 10 (entget ent)) ) (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx))))) ) (setq x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst)) y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst)) ) (if (= (setq sum (apply '+ (mapcar '(lambda (x) (caddr x)) v_lst))) 0.0) (setq z_pt 0.0) (setq z_pt (/ sum (length v_lst))) ) ) ( (= e_typ "LWPOLYLINE") (setq z_pt (rh:dxf 38 e_lst)) (foreach pr e_lst (if (= (car pr) 10) (setq v_lst (cons (cdr pr) v_lst))) ) (setq x_pt (/ (apply '+ (mapcar '(lambda (x) (car x)) v_lst)) (length v_lst)) y_pt (/ (apply '+ (mapcar '(lambda (x) (cadr x)) v_lst)) (length v_lst)) ) ) ) (setq c_lst (list x_pt y_pt z_pt)) (entmakex (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 10 c_lst) (cons 40 (getvar 'textsize)) (cons 71 5) (cons 72 5) (cons 1 (strcat (rtos (/ area 1000000.0) 2 2) "m" (chr 0178))) ; (cons 1 (strcat (rtos (/ area 1000000.0) 2 2) "m²")) ; (cons 1 (rtos (/ area 1000000.0) 2 3)) ; If you don't need the suffix "m²" ) ) ) (if cmde (setvar 'cmdecho cmde)) ) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.