Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Getting the volume of a solid programatically

8 REPLIES 8
Reply
Message 1 of 9
Anonymous
672 Views, 8 Replies

Getting the volume of a solid programatically

Hi,

I need to be able to get the volume of a solid for mass calculations
using AutoLISP.

I can't use the normal (entget (car(entsel))) as this just produces
garbage. I want the volume because when I list the solid it calculates
the mass based on a bulk density of 1.0 (basically useless).

I'm using 2006

Any tips?

Thanks.

--

Regards,

Ian A. White, CPEng.

| /| / WAI Engineering
| /_| / Sydney 2000
|/ |/ Australia

www.wai.com.au

mailto:ianwhite@wai.com.au

callto://waiwhite on Skype
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: Anonymous

Hi Ian
Here is one from my oldies that written for A2000
Hope it will works in your version too
Create layer on each type of a material with different colors
Auxiliary function reads a layer and chooses density
You need to put the values in function testofdens
instead of dummy values I have put
(I.e. instead of 7.8, 5.6, 2.4 8.61, 6.8)
Certainly you will have other names of layers
Replace in those seats where I have put a sign; | ***** |;
How many types of a material are so much layers.
Convert mass properties accordingly your current units

;_________local function_____________

(defun testofdens (solid / density)
(setq density
(cond
;|*****|;((= (vla-get-layer solid) "Nickel") 7.8)
((= (vla-get-layer solid) "Brass") 5.6)
((= (vla-get-layer solid) "Plastic") 2.4)
((= (vla-get-layer solid) "Cooper") 8.61)
((= (vla-get-layer solid) "Steel") 6.8);|*****|;
(T nil))))

;_______main part_________________

(defun C:mav3 ()
(setq oldeh (getvar "CMDECHO"))
(setq oldos (getvar "OSMODE"))
(setvar "CMDECHO" 0)
(setvar "OSMODE" 0)
(command "_.undo" "_g")
(vl-load-com)
(setq adoc
(vla-get-activedocument
(vlax-get-acad-object))
fldr (vlax-variant-value
(vla-getvariable adoc "DWGPREFIX")))
(setq vrem (rtos (getvar "CDATE") 2))
(setq tail (strcat (substr vrem 7 2) "_" (substr vrem 10 4)))
(setq data_name (strcat fldr "Volume_" tail ".txt"))
;|*****|;(setq lay_lst '("Nickel"
"Brass"
"Plastic"
"Cooper"
"Steel"));|*****|;
(setq selset nil vol_lst nil com_volume nil sol_lst nil)
(setq selset (ssget) num (sslength selset) i -1)
(repeat num
(setq i (1+ i))
(if (and (wcmatch (vla-get-objectname
(setq vsol (vlax-ename->vla-object
(ssname selset i)))) "AcDb3dSolid")
(member (vla-get-layer vsol) lay_lst))
(progn
(setq sol_lst (append sol_lst (list vsol)))
(setq vol_lst (append vol_lst
(list (vla-get-volume
vsol)))))))
(setq mas_lst (mapcar (function (lambda (x y)
(/ (* (testofdens x) y) 1000.))) sol_lst vol_lst))
(setq com_volume (/ (apply '+ vol_lst) 1000.))
(setq com_mass (apply '+ mas_lst))
(setq com_lst (mapcar 'list vol_lst mas_lst))

(princ (strcat "\n*** Total volume: " (rtos com_volume) " cubic centimeters"))
(princ (strcat "\n*** Total mass: " (rtos com_mass) " gramm"))
(setq fname (open data_name "w"))
(foreach i com_lst
(prin1 (strcat "Volume: " (rtos (car i) 2 2) " cubic centimeters"
"; " "Mass: " (rtos (cadr i) 2 2) " gramm") fname)
(write-char 10 fname))
(prin1 "___________________________________________" fname)
(write-char 10 fname)
(prin1 (strcat "Total volume: " (rtos com_volume 2 2) " cubic centimeters") fname)
(write-char 10 fname)
(prin1 (strcat "Total mass: " (rtos com_mass 2 2) " gramm") fname)
(close fname)
(command "_.undo" "_e")
(setvar "CMDECHO" oldeh)
(setvar "OSMODE" oldos)
(princ)
)
(C:mav3)
(princ)
;______________________________________;

~'J'~
Message 3 of 9
Anonymous
in reply to: Anonymous

Something like this, in it's simplest form.

(vla-get-volume (vlax-ename->vla-object (car (entsel))))


--
Autodesk Discussion Group Facilitator


"Ian A. White" wrote in message
news:5749521@discussion.autodesk.com...

> I need to be able to get the volume of a solid for mass calculations
> using AutoLISP.
Message 4 of 9
devitg
in reply to: Anonymous

It is the true volume , just multiply it by the material specific weight.

This not a useless unit , if the volume is water , it will give you the weight.
Message 5 of 9
Anonymous
in reply to: Anonymous

On Mon, 15 Oct 2007 09:25:06 +0000, Fatty <> wrote:

>Hi Ian
>Here is one from my oldies that written for A2000
>Hope it will works in your version too
>Create layer on each type of a material with different colors
>Auxiliary function reads a layer and chooses density
>You need to put the values in function testofdens
>instead of dummy values I have put
>(I.e. instead of 7.8, 5.6, 2.4 8.61, 6.8)
>Certainly you will have other names of layers
>Replace in those seats where I have put a sign; | ***** |;
>How many types of a material are so much layers.
>Convert mass properties accordingly your current units

Thanks for that.

For me, it is generally just one material - steel (structures) or
aluminium (windows and curtain walling) so I don't have them on
separate layers. I also have to provide full cutting lists with each
individual element listed and an estimated mass for it.

What prompted this was a rather messy job where I was fed incorrect
information on the total job mass. I quoted a $/tonne figure, but it
turns out that the fabricator is claiming that the actual tonneage is
around 30% less than the figure I have worked out. Of course their
transport and galvanising records clearly show this 30% discrepancy.
With some 400 assemblies and each assembly comprising something like 6
or more individual items, I almost wore the spots off my calculator.

I will have a look through things and see what I can use. It is a pity
that AutoCAD does not let you simply nominate what the default
material bulk density is - at least I have not been able to find it.

Thanks again.

--

Regards,

Ian A. White, CPEng.

| /| / WAI Engineering
| /_| / Sydney 2000
|/ |/ Australia

www.wai.com.au

mailto:ianwhite@wai.com.au

callto://waiwhite on Skype
Message 6 of 9
Anonymous
in reply to: Anonymous

On Mon, 15 Oct 2007 13:54:58 +0000, Jason Piercey
wrote:

>Something like this, in it's simplest form.
>
>(vla-get-volume (vlax-ename->vla-object (car (entsel))))

Thanks.

--

Regards,

Ian A. White, CPEng.

| /| / WAI Engineering
| /_| / Sydney 2000
|/ |/ Australia

www.wai.com.au

mailto:ianwhite@wai.com.au

callto://waiwhite on Skype
Message 7 of 9
Anonymous
in reply to: Anonymous

Hi,

No. It will give you a volume which can be multiplied by the specific
gravity to get a mass.

For most practical purposes the SG of pure water is 1, but it varies quite
significantly with temperature.

And weight for a given mass varies with the gravity at the location.

--

Laurie Comerford
CADApps
www.cadapps.com.au
www.civil3Dtools.com

wrote in message news:5750394@discussion.autodesk.com...
It is the true volume , just multiply it by the material specific weight.

This not a useless unit , if the volume is water , it will give you the
weight.
Message 8 of 9
Anonymous
in reply to: Anonymous

On Mon, 15 Oct 2007 22:31:37 +0000, devitg <> wrote:

>It is the true volume , just multiply it by the material specific weight.
>
> This not a useless unit , if the volume is water , it will give you the weight.

When I said useless I did not mean it was incorrect. It is correct,
just that when you have to do this on 1600 odd components on a job, it
becomes time consuming and prone to errors.

--

Regards,

Ian A. White, CPEng.

| /| / WAI Engineering
| /_| / Sydney 2000
|/ |/ Australia

www.wai.com.au

mailto:ianwhite@wai.com.au

callto://waiwhite on Skype
Message 9 of 9
devitg
in reply to: Anonymous

If so , you can put each group in a unique layer , or add each component a xdata to know what material it is made .
Or any other mean to get a correspondence between part and material.
As far as I know , there is no way ACAD would know what material is each one.
After it it can be made a LISP to get the mass of each one.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost