Page 1 of 10

Macro to compute center of mass

Posted: Sun Oct 28, 2018 2:51 pm
by schupin
Hi all,

I just created my first macro for FreeCAD !

It's a small macro to compute the weight of multiple solids and the center of mass of the "assembly".

You have to select one or multiple solids and then you launch the macro.
You'll have a window listing the solids. You can put the density of your material or choose in a huge list of predefined materials (I took the values here)
If you know your densities in another unit system, I used FreeCAD convert system to propose differents units.
exportedFile.png
exportedFile.png (22.11 KiB) Viewed 16444 times

You can also display where is the center of mass :
Interface.png
Interface.png (131.85 KiB) Viewed 16444 times

You can save the computed information in a csv file :
exportedFile.png
exportedFile.png (22.11 KiB) Viewed 16444 times
A import button allows you to quickly loaded saved densities (even if it's not a .csv file with the macro, as soon as there is a column named "Density" it will be loaded.)

If anyone want to test or have any suggestion to improve it, here is the file :

Files are here : https://github.com/chupins/FreeCAD-macr ... nformation

PS : the design is from here : planosconciri


Icon pack :
CenterOfMass_iconPack.zip
(16.3 KiB) Downloaded 904 times

Re: Macro to compute center of mass

Posted: Mon Oct 29, 2018 1:54 pm
by thschrader
Nice tool!
It is easy to generate a material list.
Can you extend the macro for rebars (=arch-structure object)?
rebars.FCStd
(200.21 KiB) Downloaded 215 times
steelframe.JPG
steelframe.JPG (189.71 KiB) Viewed 16325 times
material_list.JPG
material_list.JPG (127.04 KiB) Viewed 16325 times
rebar.JPG
rebar.JPG (227.5 KiB) Viewed 16325 times

Re: Macro to compute center of mass

Posted: Mon Oct 29, 2018 6:51 pm
by bernd
why not choose the material out of the FreeCAD materials. They have density too.

Re: Macro to compute center of mass

Posted: Mon Oct 29, 2018 7:43 pm
by schupin
thschrader wrote: Mon Oct 29, 2018 1:54 pm Nice tool!
It is easy to generate a material list.
Can you extend the macro for rebars (=arch-structure object)?
I'll look at it. I'never work with arch, but it might be possible
bernd wrote: Mon Oct 29, 2018 6:51 pm why not choose the material out of the FreeCAD materials. They have density too.
It's my first macro and i didn't dive deeply into freecad API.
It was easier to start with this dictionnary. I guess i will easily change it to freecad's material list.
I'll try it soon

Re: Macro to compute center of mass

Posted: Sat Nov 03, 2018 10:35 pm
by triplus
schupin wrote: Sun Oct 28, 2018 2:51 pm Hi all,

I just created my first macro for FreeCAD !
Congratulations and thanks for sharing.

Re: Macro to compute center of mass

Posted: Fri Nov 09, 2018 10:16 pm
by schupin
thschrader wrote: Mon Oct 29, 2018 1:54 pm Can you extend the macro for rebars (=arch-structure object)?
That's done !
I also add some lines to make it work with arrays (and arrays of rebars).
If you know some other structures of this kind, let me know !
(I also have to add the pathArray support)

bernd wrote: Mon Oct 29, 2018 6:51 pm why not choose the material out of the FreeCAD materials. They have density too.
I now use FreeCAD's material list and editor.
I'm not fully convinced since there is not a lot materials within the freeCAD installation files (except if you work with any kind of steel :lol:).
But it's definitely better when you have already made a database.

I also change the button to icons to save place in the interface.
Here is the new version and the icons
centomass_update.png
centomass_update.png (159.5 KiB) Viewed 15886 times
CentOMassesIcons.zip
(67.01 KiB) Downloaded 214 times
CentOMasses.FCMacro
(27.9 KiB) Downloaded 238 times

Re: Macro to compute center of mass

Posted: Sat Nov 10, 2018 6:40 am
by galou_breizh
It looks like a great macro. Can I put it on the official macro repositories (i.e. do you accept that other people can modify your macro)? What license do you want? I suggest the same as FreeCAD itself.

Thanks,
Gaël

Re: Macro to compute center of mass

Posted: Sat Nov 10, 2018 8:16 am
by schupin
galou_breizh wrote: Sat Nov 10, 2018 6:40 am It looks like a great macro. Can I put it on the official macro repositories (i.e. do you accept that other people can modify your macro)? What license do you want? I suggest the same as FreeCAD itself.
I'll be glad you add it in the official repo !

The same licence as FreeCAD is ok for me, but I'm not sure the icons I took are compatible with this licence ? (I took them from freepik) It's on CC 3.0 licence.

Re: Macro to compute center of mass

Posted: Sat Nov 10, 2018 12:26 pm
by thschrader
Hi schupin,
macro and export to csv works for rebars.
But there is something wrong with the values (970 gramms total for the stirrups?)
Can you have a look at this? Thanks.
rebar_test.FCStd
(278.26 KiB) Downloaded 178 times
I am running on
OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15072 (Git)
Build type: Release
Branch: master
Hash: e517c00d9b3da3d1dbe5d5b0159ac5fa95790a8f
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: German/Germany (de_DE)
rebars_csv.JPG
rebars_csv.JPG (52.86 KiB) Viewed 15819 times
mass_rebars.JPG
mass_rebars.JPG (24.57 KiB) Viewed 15819 times
screen.JPG
screen.JPG (154.6 KiB) Viewed 15819 times

Re: Macro to compute center of mass

Posted: Sat Nov 10, 2018 2:06 pm
by schupin
thschrader wrote: Sat Nov 10, 2018 12:26 pm Hi schupin,
macro and export to csv works for rebars.
But there is something wrong with the values (970 gramms total for the stirrups?)
Can you have a look at this? Thanks.
You're right, It took the volume of only one element of the rebar.
It's corrected !
For your file it gives that :
centoMassRebars.PNG
centoMassRebars.PNG (15.32 KiB) Viewed 15810 times

I also corrected the units in the export data sheet (everything was in mm in the previous version)
CentOMasses.FCMacro
(29.13 KiB) Downloaded 264 times