# Extract mass properties from 3D bodies in lisp and use them in calculation whitin the program

## Recommended Posts

Dear Members!

Problem part I

• I now turn to you with the question of how to extract certain data from the "_massprop" command and assign it to a variable immediately.

I am working on an automation task where a cable cross section has to be pulled out on a given 3D polilyne path. I need to extract the volume of the resulting 3D solid to calculate the volume of the displaced top.

Problem part II

• Similarly, I should extract the length of the extracted 3D tube from the property table. This data is available if I extract the cross section with the _extrude / path command.

I have to assign the extracted data to a variable within the lisp program to perform a mathematical operation on it. As follows:

• (setq V (volume data from the _massprop command))
• (setq Vm (/ V (1000 ^ 3)); converting the mm3 to m3

Problem part III

• I would like to write the obtained result in a table in the model space.
Column 1: "Volume of ground displaced by the pipeline"
Colum 2: "The result of the calculation (which will be the value of a variable Vm)"

Here is my code for calculation the cross section of the cable and to extrude it. The polyline must to be placet at '(0 0 0)

All help comes in handy:

```(defun c:kabel(/ K_A K_AKEM K_DKE K_DKEM K_H K_L K_PT0 K_PT1 K_PT2 K_PT3 K_PT4 K_PT5 K_RKE K_RKEM K_RTOT K_SS1 K_V PIR)

(setq K_Dke (getreal "Adja meg a kábel ér külső átmérőjét:")); Give me the diameter of the subcable
(setq K_Akem (getreal "Adja meg a kábel ér magjának keresztmetszet területét (mm2)-ben) :")); Give me the copper cross section area
(setq K_L (getreal "Adja meg a beillesztett polilyne teljes hossszát m-ben:")); Give me the length of the cable route

(setq pir 3.141592654)
(setq K_Dkem (sqrt (/ (* K_Akem 4) pir))); The copper diameter

(setq K_Rke (/ K_Dke 2))
(setq K_Rkem (/ K_Dkem 2))

(setq K_pt0 '(0 0 0)) ; The low right cable part (you have 3 of them)
(setq K_pt1 (polar K_pt0 (* pi 0.666666666666) K_Dke )); The center position of the upper cable part
(setq K_pt2 (polar K_pt0 pi K_Dke)); The center of the third cable part ( part 3 of 3)

(setq K_h (* K_Dke (sin (/ pi 3))))

(setq K_pt3 (polar K_pt2 0 (/ K_Dke 2)))
(setq K_pt4 (polar K_pt3 (/ pi 2) (* K_h 0.333333333333)));The outer circle center point calculated from 3 cabel parts which are 120 degree from each other, like a mercedes logo

(setq K_Rtot (+ K_Rke (* K_h 0.666666666666666))); Radius of the cable pipe
(setq K_pt5 (polar K_pt4 (/ pi 2) K_Rtot))

(command "_circle" K_pt4 K_Rtot "")

(setq K_ss1 (ssget "_L"))

(command "_extrude" "_Mode" "_solid" K_ss1 "" "_path" '(0 0 -0.1) "")

(setq K_A (* (* (/ K_Rtot 1000) (/ K_Rtot 1000)) pir))

(setq K_V (* K_A K_L))

(alert (strcat "The volume of the cable=" (rtos K_V) "m3"))

(princ)

)```

##### Share on other sites

You can write massprop to a file then read it again to get values returned by massprop. Volume in Bricscad is 2nd line.

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

##### Share on other sites
1 hour ago, BIGAL said:

You can write massprop to a file then read it again to get values returned by massprop. Volume in Bricscad is 2nd line.

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

Dear BIGAL!

Thank you for your replay, but in manual I know for that option...

I'm interested in how to extract that number automatically in AUTOLISP like this:

```(commad "massprop" "")

(setq Vname ~as string~  (here goes the code to read the desired parameter name))

(setq V (here goes the code to read the parameter value)

;and

(setq L (here goes the code to read the length of the polilyne  from the properties table) ;By property table I mean (Ctrl+1)```

##### Share on other sites

Should have looked using dumpit.lsp Volume is a property.

So your home work is Vla-get-theproperty vlaobject

```; shorthand version of dumpit.lsp
(vlax-dump-object (vlax-ename->vla-object (car  (entsel "Pick obj"))))```

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.