Macro to compute center of mass

Show off your FreeCAD projects here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Macro to compute center of mass

Post 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 15486 times

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

You can save the computed information in a csv file :
exportedFile.png
exportedFile.png (22.11 KiB) Viewed 15486 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 892 times
Attachments
CenterOfMass_cionPack.zip
(16.3 KiB) Downloaded 173 times
Interface_ShowCdG.png
Interface_ShowCdG.png (263.11 KiB) Viewed 15486 times
Last edited by schupin on Thu May 23, 2019 6:59 am, edited 11 times in total.
thschrader
Veteran
Posts: 3122
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: Macro to compute center of mass

Post 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 203 times
steelframe.JPG
steelframe.JPG (189.71 KiB) Viewed 15367 times
material_list.JPG
material_list.JPG (127.04 KiB) Viewed 15367 times
rebar.JPG
rebar.JPG (227.5 KiB) Viewed 15367 times
User avatar
bernd
Veteran
Posts: 12849
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: Macro to compute center of mass

Post by bernd »

why not choose the material out of the FreeCAD materials. They have density too.
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Post 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
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Macro to compute center of mass

Post 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.
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Post 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 14928 times
CentOMassesIcons.zip
(67.01 KiB) Downloaded 191 times
CentOMasses.FCMacro
(27.9 KiB) Downloaded 224 times
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: Macro to compute center of mass

Post 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
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Post 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.
thschrader
Veteran
Posts: 3122
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: Macro to compute center of mass

Post 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 163 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 14861 times
mass_rebars.JPG
mass_rebars.JPG (24.57 KiB) Viewed 14861 times
screen.JPG
screen.JPG (154.6 KiB) Viewed 14861 times
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Post 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 14852 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 245 times
Post Reply