CAD2005 Posted June 7 Posted June 7 (edited) I don't know anything about lisp ! I found the lisp to calculate hach area on the web. I would like to ask you who understand lisp to help me calculate the area in m2. area = 5000 x 5000 = 25m2 (defun C:hatcharea () (hatcharea)) (defun hatcharea ( / ss area i eo pt) (setq ss (ssget '((0 . "hatch"))) area 0 i 0 ) (cond ((and(and ss) (> (sslength ss) 0)) (repeat (sslength ss) (setq eo (vlax-ename->vla-object (ssname ss i))) (setq area (+ area (vlax-get eo 'Area))) (setq i (+ i 1)) ) (while (not pt)(setq pt (getpoint "\nSelect area text insertion point >"))) (command "text" pt "" "" (strcat "Area = " (rtos area 2 2) " sq. units") "") ) ) (princ) ) Edited July 9 by SLW210 Added Code Tags!! Quote
Isaac26a Posted June 7 Posted June 7 (edited) Like this? (defun C:hatcharea () (hatcharea)) (defun hatcharea ( / ss area i eo pt) (setq ss (ssget '((0 . "hatch"))) area 0 i 0 ) (cond ((and(and ss) (> (sslength ss) 0)) (repeat (sslength ss) (setq eo (vlax-ename->vla-object (ssname ss i))) (setq area (+ area (vlax-get eo 'Area))) (setq i (+ i 1)) ) (while (not pt)(setq pt (getpoint "\nSelect area text insertion point >"))) (setq area (/ area 1000000.)) (command "text" pt "" "" (strcat "Area = " (rtos area 2 2) " m2") "") ) ) (princ) ) Edited June 7 by Isaac26a Quote
CAD2005 Posted June 7 Author Posted June 7 (edited) thank you very much @Isaac26a please see and help me This lisp calculates the area of a closed polyline. I want to record the result as you edited area = 5000x5000 = 25m2 (defun rh:dxf (code lst) (cdr (assoc code lst))) (defun c:plarea ( / cmde ent e_typ e_lst area vtx x_lst y_lst z_lst x_pt y_pt z_pt c_lst v_lst) (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 );end_setq (cond ( (= e_typ "POLYLINE") (setq ent (entnext ent) vtx (rh:dxf 10 (entget ent)) );end_setq (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)) );end_setq (if (< (length vtx) 3) (setq vtx (reverse (cons 0.0 (reverse vtx))))) );end_while (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)) );end_setq (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))) );end_foreach (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)) );end_setq ) );end_cond (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 (rtos area 2 3)) );end_list );end_entmakex );end_while (if cmde (setvar 'cmdecho cmde)) );end_defun Edited July 9 by SLW210 Added Code Tags!! Quote
BIGAL Posted June 7 Posted June 7 This is a simple way to get a centroid of a pline. (setq obj (vlax-ename->vla-object (car ent))) (setq cpt (osnap (vlax-curve-getStartPoint obj) "gcen")) 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.