Nikon Posted January 18 Posted January 18 (edited) Hi everybody! The foundation ditch is in 2d. Dimensions in the drawing in mm I want to get the volume using the truncated pyramid formula, but I don't have enough knowledge 1. Specify PL1 (get area S1, m2) 2. Specify PL2 (get area S2, m2) 3. Enter the value of the pit height h, m 4. Substitute the values in the formula V=1/3h(S1+S2+sqrt(S1*S2)) and get the volume of the pit V = 60 m3 (linear scale coefficient 0.000001) 5. Insert the V value into the drawing (or show it on the command string) ; volume of the excavation 2d (defun C:W2d( / ) (vl-load-com) (setvar "CMDECHO" 0) (setq PL1 (car (entsel "\nSpecify the polyline PL1:"))) ; ?receive the area S1? (mapcar 'cdr (vl-remove-if '(lambda (x) (/= (car x) 10)) (entget (ssname (ssget "_:S" '((0 . "LWPOLYLINE"))) 0)) ) ) ) (setq PL2 (car (entsel "\nSpecify the polyline PL2:"))) ; ?receive the area S2? ; enter the height (h) of the excavation ; insert values (S1, S2, h) into the formula V=1/3h(S1+S2+sqrt(S1*S2)) ; and get the result m3 (linear scale coefficient 0.000001)... Edited January 18 by Nikon Quote
BIGAL Posted January 18 Posted January 18 (edited) So ; ?receive the area S1? (setq s1 (vlax-get (vlax-ename->vla-object pl1) 'area)) (setq h (getreal "\nEnter height ")) Not tested formula V=1/3h(S1+S2+sqrt(S1*S2)) (setq s1s2 (* s1 s2)) (setq s1s2 (sqrt s1s2)) (setq s1s2 (+ s1 s2 s1s2)) (setq vol (/ s1s2 (* 3.0 h))) Edited January 19 by BIGAL 1 Quote
Isaac26a Posted January 19 Posted January 19 (edited) Hope this solves your problem, just the linear scale is missing, but I guess you can handle it from here. ;;; Volume of a truncated piramid square based ;;; https://www.cadtutor.net/forum/topic/79210-the-volume-of-the-foundation-ditch-through-lisp/ (defun C:W2d( / h oe pl1 pl2 s1 s2 v) (vl-load-com) (setq oe (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq pl1 (car (entsel "\nSpecify the polyline PL1:"))) (setq s1 (vla-get-area (vlax-ename->vla-object pl1))) (setq pl2 (car (entsel "\nSpecify the polyline PL2:"))) (setq s2 (vla-get-area (vlax-ename->vla-object pl2))) (setq h (getreal "\nEnter the height (h) of the excavation: ")) (setq v (* (/ (+ s1 s2 (sqrt (* s1 s2))) (* 3 1000000)) h)) (princ (strcat "\nThe Volume of the excavation is: " (rtos v 2 3) " m3")) (setvar 'cmdecho oe) (princ) ) Edited January 19 by Isaac26a 1 Quote
Nikon Posted January 19 Author Posted January 19 (edited) @BIGAL thanks. I'm learning a little bit... @Isaac26a, thanks. The code works well, but the formula is incorrect: (setq v (/ (+ s1 s2 (sqrt (* s1 s2))) (* 3 h))) I'm replacing 1/3 with 0.33333 (setq v (* (+ s1 s2 (sqrt (* s1 s2))) (* 0.333333 h))) This code counts correctly ;;; Volume of a truncated piramid square based ;;; https://www.cadtutor.net/forum/topic/79210-the-volume-of-the-foundation-ditch-through-lisp/ (defun C:W2d( / h oe pl1 pl2 s1 s2 v) (vl-load-com) (setq oe (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq pl1 (car (entsel "\nSpecify the polyline PL1:"))) (setq s1 (vla-get-area (vlax-ename->vla-object pl1))) (setq pl2 (car (entsel "\nSpecify the polyline PL2:"))) (setq s2 (vla-get-area (vlax-ename->vla-object pl2))) (setq h (getreal "\nEnter the height (h) of the excavation: ")) (setq v (* (+ s1 s2 (sqrt (* s1 s2))) (* 0.333333 0.000001 h))) (princ (strcat "\nThe Volume of the excavation is: " (rtos v 2 3) " m3")) (setvar 'cmdecho oe) (princ) ) The result is in m3 Edited January 19 by Nikon Quote
Isaac26a Posted January 19 Posted January 19 My mistake, should have seen the right formula first, now is fixed, you were right the first time, just multiply for 0.000001 or divide by 1000000 1 Quote
Nikon Posted January 19 Author Posted January 19 (edited) Please advise how to add the insertion of the result to the drawing, current text, text height 250 I'm trying, but I don't know how to point to the result of V... (princ (strcat "\nresult V))??? How to write in the code copying the result to the buffer, then paste it into the drawing. (if (setq p (getpoint "\nSpecify a point to insert text: ")) (entmake (list '(0 . "TEXT") '(100 . "AcDbText") (cons 10 (trans p 1 0)) (cons 40 250) (cons 1 (rtos l)) ) ) (princ (strcat "\nresult V)) ) ) ) (princ) ) Edited January 19 by Nikon Quote
Isaac26a Posted January 19 Posted January 19 I guess what you are trying to do is this: (if (setq p (getpoint "\nSpecify a point to insert the text: ")) (entmake (list '(0 . "TEXT") '(100 . "AcDbText") (cons 10 (trans p 1 0)) (cons 40 250) (cons 1 (rtos v 2 3)) (cons 50 (angle '(0 0) (getvar 'ucsxdir))) ) ) (princ (strcat "\nThe result is: " (rtos V 2 3) " m3")) ) Which makes either put a text with the result (just the number of the volume) or put it on the command line, or if you want to put it clear: (cons 1 (strcat "Volume = " (rtos v 2 3) " m3")) To be clear, this should be: 5 hours ago, Nikon said: (princ (strcat "\nresult V))??? (princ (strcat "\nresult" (rtos V 2 3))) Close the quotes " " and convert the real to string 1 Quote
Nikon Posted January 19 Author Posted January 19 (edited) @Isaac26a Thank you very much! I am combining 2 codes, it is great for my task... Have a nice day ;;; Volume of a truncated piramid square based, author Isaac26a, 19.01.2024 ;;; https://www.cadtutor.net/forum/topic/79210-the-volume-of-the-foundation-ditch-through-lisp/ (defun C:W2d1( / h oe pl1 pl2 s1 s2 v) (vl-load-com) (setq oe (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq pl1 (car (entsel "\nSpecify the polyline PL1:"))) (setq s1 (vla-get-area (vlax-ename->vla-object pl1))) (setq pl2 (car (entsel "\nSpecify the polyline PL2:"))) (setq s2 (vla-get-area (vlax-ename->vla-object pl2))) (setq h (getreal "\nEnter the height (h) of the excavation: ")) (setq v (* (/ (+ s1 s2 (sqrt (* s1 s2))) (* 3 1000000)) h)) (princ (strcat "\nThe Volume of the excavation is: " (rtos v 2 2) " m3")) (setvar 'cmdecho oe) (if (setq p (getpoint "\nSpecify a point to insert the text: ")) (entmake (list '(0 . "TEXT") '(100 . "AcDbText") (cons 10 (trans p 1 0)) (cons 40 250) (cons 1 (rtos v 2 3)) (cons 50 (angle '(0 0) (getvar 'ucsxdir))) ) ) (princ (strcat "\nThe result is: " (rtos V 2 3) " m3")) ) (princ) ) This lisp is suitable for such proper foundation pits Edited January 19 by Nikon Quote
BIGAL Posted January 20 Posted January 20 (edited) Just a quick comment re 1/3 use (/ 1 3.0) forces 0.333333 (/ 1 3) may not returns 0, or (/ 1. 3.) and so on. if you want real answers v's Integers make sure you add a "." to your numbers. Edited January 20 by BIGAL 1 Quote
Nikon Posted January 20 Author Posted January 20 (edited) On 20.01.2024 at 05:20, BIGAL said: Just a quick comment re 1/3 use (/ 1 3.0) forces 0.333333 (/ 1 3) may not returns 0, or (/ 1. 3.) and so on. if you want real answers v's Integers make sure you add a "." to your numbers. I probably misunderstand how to add "." (setq v (* (+ s1 s2 (sqrt (* s1 s2))) (* "0.333333" 0.000001 h))) ; error: invalid argument type: numberp: "0.333333 Edited February 2 by Nikon Quote
Isaac26a Posted January 20 Posted January 20 (edited) I think what BigAl suggested was this (setq v (* (/ (+ s1 s2 (sqrt (* s1 s2))) (* 3. 1000000)) h)) As you see the 3 was changed to 3. or could be 3.0 so you prevent this number can be considered as an integer instead of a real I added the undo and also the initget to prevent h to be 0 or negative or just nil (by hitting enter) ;;; Volume of a truncated piramid square based, author Isaac26a, 19.01.2024 ;;; https://www.cadtutor.net/forum/topic/79210-the-volume-of-the-foundation-ditch-through-lisp/ (defun C:W2d1( / dw h oe pl1 pl2 s1 s2 v) (vl-load-com) (vla-startundomark (setq dw (vla-get-activedocument (vlax-get-acad-object)))) (setq oe (getvar 'cmdecho)) (setvar 'cmdecho 0) (setq pl1 (car (entsel "\nSpecify the polyline PL1:"))) (setq s1 (vla-get-area (vlax-ename->vla-object pl1))) (setq pl2 (car (entsel "\nSpecify the polyline PL2:"))) (setq s2 (vla-get-area (vlax-ename->vla-object pl2))) (initget 7) (setq h (getreal "\nEnter the height (h) of the excavation: ")) (setq v (* (/ (+ s1 s2 (sqrt (* s1 s2))) (* 3. 1000000)) h)) (princ (strcat "\nThe Volume of the excavation is: " (rtos v 2 2) " m3")) (if (setq p (getpoint "\nSpecify a point to insert the text: ")) (entmake (list '(0 . "TEXT") '(100 . "AcDbText") (cons 10 (trans p 1 0)) (cons 40 250) (cons 1 (rtos v 2 3)) (cons 50 (angle '(0 0) (getvar 'ucsxdir))) ) ) (princ (strcat "\nThe result is: " (rtos V 2 3) " m3")) ) (setvar 'cmdecho oe) (vla-endundomark dw) (princ) ) 8 hours ago, Nikon said: (setq v (* (+ s1 s2 (sqrt (* s1 s2))) (* "0.333333" 0.000001 h))) Here when you do "0.333" you are making the number become a string so it will become an error And as far as I know there is no (recip ) function well at least in autocad Edited January 20 by Isaac26a 1 Quote
Nikon Posted January 20 Author Posted January 20 (edited) On 20.01.2024 at 18:40, Isaac26a said: I added the undo and also the initget to prevent h to be 0 or negative or just nil (by hitting enter) @Isaac26a Thanks for the updated code and explanations! Edited February 2 by Nikon 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.