nestation Posted July 4 Posted July 4 (edited) (defun c:BB ( / ss index asum e obj tmparea msp spt txtobj ) (if (setq ss (ssget (list (cons 0 "CIRCLE,ARC,LWPOLYLINE,ELLIPSE,SPLINE")))) (progn (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq index 0 asum 0) (repeat (sslength ss) (setq e (ssname ss index)) (setq obj (vlax-ename->vla-object e)) (setq tmparea (vla-get-area obj)) (setq asum (+ asum tmparea)) (setq index (1+ index)) ) (prompt (strcat "\nTotal area = " (rtos asum 2 2))) (initget 1) (setq spt (getpoint "\nText start point: ")) (setq txtobj (vla-addtext msp (rtos asum 2 2) (vlax-3d-point spt) (getvar "textsize"))) ) ) (princ) ) (vl-load-com) (prompt "\n[ ASUM ]") (princ) hi there. i'm a Autolisp biginner. I would like to get your help. The result value of the above Autolisp is in this form. 234,234,243 (maybe ㎟) But I want this form as a result value. 234㎡ I look forward to your earnest help. Edited July 4 by SLW210 Added Code Tags! Quote
SLW210 Posted July 4 Posted July 4 Please use Code Tags for your code in the future. (<> in the editor toolbar) Quote
EnM4st3r Posted July 4 Posted July 4 you can use (cvunit asum "sq_mm" "sq_m") to convert it. Additionally you could read insunits to check if that unit is actually used. (defun c:BB ( / ss index asum e obj tmparea msp spt txtobj dwgunit) (if (setq ss (ssget (list (cons 0 "CIRCLE,ARC,LWPOLYLINE,ELLIPSE,SPLINE")))) (progn (setq msp (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) (setq index 0 asum 0) (repeat (sslength ss) (setq e (ssname ss index)) (setq obj (vlax-ename->vla-object e)) (setq tmparea (vla-get-area obj)) (setq asum (+ asum tmparea)) (setq index (1+ index)) ) (if (not (setq dwgunit (cdr (assoc (getvar "insunits") '((4 . "sq_mm")(5 . "sq_cm")(6 . "sq_m")))))) (progn (princ "\nError with dwg unit")(exit))) (setq asum (cvunit asum dwgunit "sq_m")) (prompt (strcat "\nTotal area = " (rtos asum 2 2) " m²")) (initget 1) (setq spt (getpoint "\nText start point: ")) (setq txtobj (vla-addtext msp (strcat (rtos asum 2 2) " m²") (vlax-3d-point spt) (getvar "textsize"))) ) ) (princ) ) 1 Quote
BIGAL Posted July 4 Posted July 4 (edited) sq mm to sq m is just a division. (/ 234234234 1e6) 234.234234 (/ 234234234 1000000) 234 (/ 224234234 1000000.) 224.234234 (setq str (strcat "Area is " (rtos area 2 2) "m" (chr 178))) "Area is 123.45m²" The chr 178 can be different in some text fonts. Edited July 4 by BIGAL 1 Quote
nestation Posted July 8 Author Posted July 8 On 7/4/2024 at 9:26 PM, SLW210 said: Please use Code Tags for your code in the future. (<> in the editor toolbar) Oh, I'm sorry. I was confused because it's been a while ~ Thank you 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.