Macro to compute center of mass

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

Re: Macro to compute center of mass

Post by schupin »

sante76 wrote: Fri Apr 24, 2020 1:33 pm I've no knowledge about Qt libraries. Really I don't know if they are installed with the FreeCad or they was there before... So I'll not supriserd if the problem starts there...
I guess you're right and the issue could be the Qt/python versions.
Theses libraries are delivered with FreeCAD but depending on the version you're using it's not the same.
With my version, i'm using Python 3.8.2 and Qt 5.12.5 and yours is using Python 3.6.6 and Qt 5.6.2.

Honestly, I don't really see what can have changed between those versions and I never had the courage to test the macro on "all" possible configurations.

By the way, you can comment the line 22 in the macro by adding a # character at the beginning (this line is useless since your version of python is 3.x.x).
(I always had a lot of issues with the encoding. It was made to handle special characters like "é, è, à, ç ..." but it seems that's not working so good...)

You can also try to install a newer version (here the pre-version are as good as the release : https://github.com/FreeCAD/FreeCAD/rele ... g/0.19_pre)
sante76
Posts: 3
Joined: Thu Apr 23, 2020 5:15 pm

Re: Macro to compute center of mass

Post by sante76 »

schupin wrote: Fri Apr 24, 2020 2:44 pm Honestly, I don't really see what can have changed between those versions and I never had the courage to test the macro on "all" possible configurations.
Finally, it works! :D Problem was the FreeCad version, with its libraries and Python too...

If I can, I would like to report you a trouble about the report on spreadsheets I've found: it's about measurement units. I've verified results of the macro are good because I'd same calculations on my own on a mine FreeCad job with internal spreadsheet... cell by cell :cry:

I launch the macron on a simple model and it works very well. Then I've exported the cvs file and imported, again, it on FreeCad: I need this datas on another FreeCad work, essentially an assembly of small parts like the one's I've tested.

I've found your macro exports values of volume in m^3 and density in kg/m^3. However, the internal spreadsheet of FreeCad work in mm^3, so I think the macro should do the same because of it's very simple to change measurement units just selecting a group of cells from GUI and change them, but only if underground datas are in mm, kg and other internal FreeCad measurement units. Otherwise, it need to transform values from report, cell by cell before... I do this because, since I work on small parts of model airplanes, I work in mm like FreeCad!
Look at follow image: it's a report from your great macro, when I've highlighted the only line I've modified.

Image

I've change volume value this way:

Code: Select all

(=2.496e-06 * pow(10; 9)
and I've changed the density value this other:

Code: Select all

=160 * pow(10; -9)
Then, how you can see, using internal GUI, changing measurement units in coherent. I think, reanding some post from this same discussion, probably the right way is to create an option in macro GUI giving the ability of select "metric units" (like with density) so all people will be happy :lol:


Another question: if I would to help you or the FreeCad (I don't know) giving data about density of some materials most used by air modellers, how can I do it?

Regards :D
Sante.
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Post by schupin »

sante76 wrote: Sat Apr 25, 2020 7:44 am Finally, it works! :D Problem was the FreeCad version, with its libraries and Python too...
Nice news, happy it works :)

For your units problems, there is a dropdown menu on the macro window that let you choose the unit of the density.
Units used to save (and reload after) will be the one selected in this menu. I guess that if you choose g/mm3 for the density unit, the results will be more convenient at your working scale.
(but of course the densities will be 10E6 smaller)
Annotation 2020-04-25 153032.png
Annotation 2020-04-25 153032.png (21.43 KiB) Viewed 6281 times
sante76 wrote: Sat Apr 25, 2020 7:44 am Another question: if I would to help you or the FreeCad (I don't know) giving data about density of some materials most used by air modellers, how can I do it?
You can find discussion about material on this part of the forum : https://forum.freecadweb.org/viewforum.php?f=38
I've never be involved in FreeCAD developpement but I think there is a lot to do to have a complete material database.
hrhassan
Posts: 75
Joined: Mon May 25, 2020 3:25 am

Re: Macro to compute center of mass

Post by hrhassan »

schupin wrote: Sun Oct 28, 2018 2:51 pm 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.

Interface.png


You can also display where is the center of mass :

Interface_ShowCdG.png


You can save the computed information in a csv file :

exportedFile.png

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
Hello, is there a way to display a pointer at the center of mass? Thank you
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Macro to compute center of mass

Post by chrisb »

Please quote only the relevant portions of previous posts and see https://forum.freecadweb.org/viewtopic. ... 08#p413508.
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
cadcam
Posts: 273
Joined: Thu Apr 02, 2020 10:39 am

Re: Macro to compute center of mass

Post by cadcam »

Dear schupin,

Just discovered this macro, really nice!

I was wondering if it was still under development and if yes might you consided adding moments of inertia, with adjustable arrows that allow the user to see the relative magnitudes?

Thanks for the macro as it is.
schupin
Posts: 476
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Post by schupin »

cadcam wrote: Mon Jul 06, 2020 8:26 pm Dear schupin,

Just discovered this macro, really nice!

I was wondering if it was still under development and if yes might you consided adding moments of inertia, with adjustable arrows that allow the user to see the relative magnitudes?

Thanks for the macro as it is.
Hi,

I can give it a try some day. But it will not be simple because you have to define a axe to compute moments of inertia.
It's not difficult to compute but I have to think of the best way to implement it.

I put this in my todo list (and I will add a point object as chrisb mentionned before)
SyProLei
Posts: 12
Joined: Tue Feb 15, 2022 9:43 am
Contact:

Re: Macro to compute center of mass

Post by SyProLei »

Dear community, dear schupin,

we are part of a research project concerning lightweight design methodology willing to update and improve this nice tool.
Is there anything ongoing with that?
I did some polishing to get used to QT framework. But as I encountered issues, I started digging deep into the code. Refactoring helped me a lot to understand and to prepare for new features, in addition to those posted in this thread.
So the question arises if it is desired to post small updates or to propose the changes all at once in a whole new version?
We are part of the technology transfer program for lightweight engineering funded by German Federal Ministry for Economic Affairs and Climate Action.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Macro to compute center of mass

Post by Kunda1 »

@SyProLei That's awesome! Welcome!

Unfortunately this thread became inactive ~2 years ago. Also it's in the User Showcase subforum and we [refer for questions/discussions not to happen too much in this subforum. Feel free to start a new forum thread in the Python Scripting & Macros subforum (then x-post a link to it in this thread so people can follow the discussion)
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
thschrader
Veteran
Posts: 3129
Joined: Sat May 20, 2017 12:06 pm
Location: Germany

Re: Macro to compute center of mass

Post by thschrader »

Maybe there are some cents for FreeCAD... :lol:
"Bewilligte Summe" = financial support

https://www.enargus.de/pub/bscw.cgi/?op ... id=2015107
syprolei.JPG
syprolei.JPG (24.79 KiB) Viewed 5057 times
Post Reply