TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Fuccaro on May 27, 2005, 06:17:42 AM

Title: Volume of a 3D solid
Post by: Fuccaro 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!
Title: Volume of a 3D solid
Post by: MP 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)

)
Title: Volume of a 3D solid
Post by: Jürg Menzi on May 27, 2005, 07:51:13 AM
Hi

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

Cheers
Title: Volume of a 3D solid
Post by: CADaver 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)
)
Title: only autolisp
Post by: DEVITG 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


[0.0000 1.0000 0.0000]
                      K: 0.1667 along [0.0000 0.0000 1.0000]
[/list:u]
Title: Volume of a 3D solid
Post by: Fuccaro 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!
Title: Volume of a 3D solid
Post by: Jürg Menzi 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