0 Members and 1 Guest are viewing this topic.
(defun _rtos (n) (rtos n 2 2)) ; for 2 decimals
(defun _foo (e) (list (vlax-curve-getarea e) (cdr (assoc 38 (entget e))))
Command: TESTSelect objects: Specify opposite corner: 6 foundSelect objects:; error: bad argument type: numberp: "712.46"
(defun c:test (/ _foo _rtos a b r s v) ;; RJP » 2021-09-17 (defun _rtos (n) (rtos n 2 2)) (defun _foo (e) (list (_rtos (vlax-curve-getarea e)) (_rtos (cdr (assoc 38 (entget e)))))) (cond ((and (setq s (ssget '((0 . "*polyline") (-4 . "&=") (70 . 1)))) (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) ) (setq s (mapcar '_foo s)) (setq s (vl-sort s '(lambda (r j) (> (car r) (car j))))) (while (cadr s) (setq a (car s) b (cadr s) s (cdr s) ) ;; Average of areas multiplied by height = volume (setq v (* (/ (apply '+ (mapcar 'car (list a b))) 2) (abs (apply '- (mapcar 'cadr (list a b))))) ) (princ (strcat "\n(" (_rtos (cadr a)) " - " (_rtos (cadr b)) ") = " (_rtos v) " m3" ) ) (setq r (cons v r)) ) (princ (strcat "\nV = " (_rtos (apply '+ r))" m3")) (textscr) ) ) (princ))
(defun c:test2 (/ _foo _rtos a b r s v) ;; RJP » 2021-09-17 (defun _foo (e) (list (vlax-curve-getarea e) (cdr (assoc 38 (entget e))))) (defun _rtos (n) (rtos n 2 2)) (cond ((and (setq s (ssget '((0 . "*polyline") (-4 . "&=") (70 . 1)))) (setq s (vl-remove-if 'listp (mapcar 'cadr (ssnamex s)))) ) (setq s (mapcar '_foo s)) (setq s (vl-sort s '(lambda (r j) (> (car r) (car j))))) (while (cadr s) (setq a (car s) b (cadr s) s (cdr s) ) ;; Average of areas multiplied by height = volume (setq v (* (/ (apply '+ (mapcar 'car (list a b))) 2) (abs (apply '- (mapcar 'cadr (list a b))))) ) (setq ar (/ (apply '+ (mapcar 'car (list a b))) 2) ) (setq dh (abs (apply '- (mapcar 'cadr (list a b)))) ) (princ (strcat "\n(" (_rtos (cadr a)) " - " (_rtos (cadr b)) ") " (_rtos ar) " m2 " (_rtos dh) " m " (_rtos v) " m3" )) (setq r (cons v r)) ) (princ (strcat "\nV = " (_rtos (apply '+ r))" m3")) (textscr) ) ) (princ))
Hi ronjonp. If you see in the first post I already haveCode: [Select] (defun _rtos (n) (rtos n 2 2)) ; for 2 decimals But if you see the test.dwg file the volumes are not correct, because in this lineCode: [Select] (defun _foo (e) (list (vlax-curve-getarea e) (cdr (assoc 38 (entget e))))the area is calculated from the polyline with more than 2 decimals. See the calculations in test.dwg. So I want in every calculation to have 2 decimals.Can you help?Thanks
Hi ribarm. I add your code but is not working. I have this errorCode: [Select]Command: TESTSelect objects: Specify opposite corner: 6 foundSelect objects:; error: bad argument type: numberp: "712.46"
(defun _foo (e) (princ (strcat (_rtos (vlax-curve-getarea e)) " " (_rtos (cdr (assoc 38 (entget e))))))
; make table example; By Alan H info@alanh.com.au; 2018(defun c:ahmaketable (/ colwidth numcolumns numrows objtable rowheight sp vgad vgao vgms)(vl-load-com)(setq sp (vlax-3d-point (getpoint "pick a point for table")))(Setq vgms (vla-get-modelspace (vla-get-activedocument (vlax-get-acad-object)))) ;(setq numrows 5)(setq numcolumns 5)(setq rowheight 2.5)(setq colwidth 60)(setq objtable (vla-addtable vgms sp numrows numcolumns rowheight colwidth))(vla-settext objtable 0 0 "DRAWING REGISTER"); TABLE TITLE(vla-settext objtable 1 0 "DRAWING NUMBER") (vla-settext objtable 1 1 "DRAWING TITLE") (vla-settext objtable 1 2 "C")(vla-settext objtable 1 3 "D")(vla-settext objtable 1 4 "E")(vla-settext objtable 2 0 "1")(vla-settext objtable 3 0 "2")(vla-settext objtable 4 0 "3")(command "_zoom" "e")(princ))
(vla-insertrows objtable numrows rowheight 1)