Author Topic: Volume of a 3D solid  (Read 4399 times)

0 Members and 1 Guest are viewing this topic.

Fuccaro

  • Guest
Volume of a 3D solid
« on: May 27, 2005, 06:17:42 AM »
I try to write a routine that returns the mass of a solid. It sounds simple. I know the density but how do I get the volume?
Please be gentle with me, I work in AutoLisp only.
Thank you!

MP

  • Seagull
  • Posts: 17750
  • Have thousands of dwgs to process? Contact me.
Volume of a 3D solid
« Reply #1 on: May 27, 2005, 07:26:01 AM »
Perhaps --

Code: [Select]
(defun c:SumVolume ( / getvolume volume ss i )

    (defun getvolume ( object / area )
        (vl-catch-all-apply
           '(lambda ()
                (setq volume
                    (vla-get-volume
                        object
                    )
                )
            )  
        )
        (if volume volume 0.0)
    )

    (if (setq volume 0.0 ss (ssget))
        (repeat (setq i (sslength ss))
            (setq volume
                (+ volume
                    (getvolume
                        (vlax-ename->vla-object
                            (ssname ss
                                (setq i (1- i))
                            )
                        )    
                    )
                )
            )
        )
    )
   
    (if volume volume 0.0)

)
Engineering Technologist • CAD Automation Practitioner
Automation ▸ Design ▸ Drafting ▸ Document Control ▸ Client
cadanalyst@gmail.comhttp://cadanalyst.slack.comhttp://linkedin.com/in/cadanalyst

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Volume of a 3D solid
« Reply #2 on: May 27, 2005, 07:51:13 AM »
Hi

Visit my homepage -> Free Stuff and search for 'VxGetMassProps'

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18

CADaver

  • Guest
Volume of a 3D solid
« Reply #3 on: May 27, 2005, 09:09:44 AM »
or maybe:
Code: [Select]
(defun c:solvol ()
  (setq a 0 volume 0
        ss (ssget '((0 . "3dsolid"))
            )
   )
  (if ss
    (progn
      (setq n (1- (sslength ss)))
      (while (>= n 0)
(setq solidobj (vlax-ename->vla-object (ssname ss n)))
       (if (= (vla-get-objectName solidobj) "AcDb3dSolid")
               (setq volume (vla-get-volume solidobj))
       )
        (setq a (+ a volume)
              n (1- n))
      ) ;;close while
     );;close progn
    (alert "\nNo Solids selected!")
) ;;close if
(princ (strcat "\nSolid volume  =  " (rtos a 2 6) "  Cu.In."))
(princ (strcat "\nSolid volume  =  " (rtos (/ a 1728.0) 2 4) "  Cu.Ft."))
(princ (strcat "\nSolid volume  =  " (rtos (/ a 46656.0) 2 2) "  Cu.Yd."))
(princ)
)

DEVITG

  • Bull Frog
  • Posts: 480
only autolisp
« Reply #4 on: May 27, 2005, 09:38:36 PM »
Seem to be Fucaro use autolisp , and no visualisp


Quote
Please be gentle with me, I work in AutoLisp only.


massprop will give you the volumen and mass

It ask you to save to a file , then you have to retrieve ti from such file

This is the result of massprop of a cube 1 unit side drawn at 0 0 0

Quote
Command: _massprop
Select objects: 1 found

Select objects:

 ----------------   SOLIDS    ----------------

Mass:                    1.0000
Volume:                  1.0000
Bounding box:         X: 0.0000  --  1.0000
                      Y: 0.0000  --  1.0000
                      Z: 0.0000  --  1.0000
Centroid:             X: 0.5000
                      Y: 0.5000
                      Z: 0.5000
Moments of inertia:   X: 0.6667
                      Y: 0.6667
                      Z: 0.6667
Products of inertia: XY: 0.2500
                     YZ: 0.2500
                     ZX: 0.2500
Radii of gyration:    X: 0.8165
                      Y: 0.8165
                      Z: 0.8165
Principal moments and X-Y-Z directions about centroid:
                      I: 0.1667 along [1.0000 0.0000 0.0000]
                      J: 0.1667 along [0.0000 1.0000 0.0000]
                      K: 0.1667 along [0.0000 0.0000 1.0000]
Press ENTER to continue:

Write analysis to a file? [Yes/No] <N>: y


This is what the such file contents


    ----------------   SOLIDS    ----------------

    Mass:                    1.0000
    Volume:                  1.0000
    Bounding box:         X: 0.0000  --  1.0000
                          Y: 0.0000  --  1.0000
                          Z: 0.0000  --  1.0000
    Centroid:             X: 0.5000
                          Y: 0.5000
                          Z: 0.5000
    Moments of inertia:   X: 0.6667  
                          Y: 0.6667  
                          Z: 0.6667  
    Products of inertia: XY: 0.2500  
                         YZ: 0.2500  
                         ZX: 0.2500  
    Radii of gyration:    X: 0.8165
                          Y: 0.8165
                          Z: 0.8165
    Principal moments and X-Y-Z directions about centroid:
                          I: 0.1667 along [1.0000 0.0000 0.0000]
                          J: 0.1667 along
[0.0000 1.0000 0.0000]
                      K: 0.1667 along [0.0000 0.0000 1.0000]
[/list:u]
Location @ Córdoba Argentina Using ACAD 2019  at Window 10

Fuccaro

  • Guest
Volume of a 3D solid
« Reply #5 on: May 30, 2005, 02:32:16 AM »
DEVITG
I should use the (command ...) function to save the properties into a file, open that file and search for the volume... It is a too long way.

MP
Your routine worked just perfect. I operated some minor changes. When I select a solid the text window will pop up showing me the mass for the materials I mostlu use: cooper, steel, aluminium.
AutoLisp and VL code can be mixed; lucky me :) !

CADaver
I will try your way too

Jürg Menzi
I could download the code but probable I will not be able to make changes.

thanks alot for all your replies!

Jürg Menzi

  • Swamp Rat
  • Posts: 599
  • Oberegg, Switzerland
Volume of a 3D solid
« Reply #6 on: May 30, 2005, 10:20:55 AM »
Ok, see:
http://www.theswamp.org/lilly_pond/juergmenzi/GetMassProps.lsp?nossi=1
You've to add the density formulas only.

Cheers
A computer's human touch is its unscrupulousness!
MENZI ENGINEERING GmbH
Current A2k16... A2k24 - Start R2.18