Macro to compute center of mass

Show off your FreeCAD projects here!
User avatar
PrzemoF
Posts: 2491
Joined: Fri Jul 25, 2014 4:52 pm
Contact:

Re: Macro to compute center of mass

Postby PrzemoF » Thu Mar 07, 2019 10:23 pm

I changed version of FreeCAD & updated your macro - now works. It was not finding any materials - only custom & default were available, but no calcs were performed. Thanks!
schupin
Posts: 258
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Thu Mar 14, 2019 9:50 pm

I just add a new button to automatically change the color of shapes depending on the density indicated :

colorify_1.png
colorify_1.png (161.6 KiB) Viewed 395 times

It might help on big model to identify materials.
(maybe it already exists on the BIM workbench, I didn't look at it...)
Syres
Posts: 204
Joined: Thu Aug 09, 2018 11:14 am

Re: Macro to compute center of mass

Postby Syres » Fri Mar 15, 2019 10:10 am

Thanks for the update and the colours should prove helpful. Just for info I had to change line 27 to:

Code: Select all

__Icon__ = 'https://www.freecadweb.org/wiki/images/4/41/Macro_CenterOfMass.png'
in order to stop this error :

Code: Select all

<unknown exception traceback><class 'SyntaxError'>: ("(unicode error) 'utf-8' codec can't decode byte 0xb3 in position 27: invalid start byte", ('E:/Data/FreeCAD/Macro/CenterOfMass.FCMacro', 126, 4, None))
I'm guessing there's a non-English character in there causing the error.

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16079 (Git)
Build type: Release
Branch: master
Hash: 6363c90a20b296ab69d7b52230009928199d90df
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
schupin
Posts: 258
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Fri Mar 15, 2019 8:46 pm

Thanks for the feedback, I'm always struggling with unicode issues...

I've to check some other things, it seems that it doesn't download icon files while using the addon manager.
schupin
Posts: 258
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Wed May 15, 2019 7:50 pm

I looked at the video here : https://www.youtube.com/watch?v=nKZuiw2DVZ8 and tried to do the same exercice using the center of mass macro.

It worked pretty well :
Question5.png
Question5.png (61.23 KiB) Viewed 137 times

I also continue the test through the question 6 and 7 using A2plus :
Question7.png
Question7.png (151.88 KiB) Viewed 137 times

I'm pretty pleased to see that FreeCAD tools are dealing perfectly with this "standard" SW exercice:)
User avatar
hds
Posts: 85
Joined: Tue Feb 14, 2017 8:23 am

Re: Macro to compute center of mass

Postby hds » Tue May 21, 2019 6:38 am

Thanks for this macro and i'am using it currently to get the COM of my VIIC. Two issues i did find though but maybe it is just me beeing to much oldschool and not OO compatible ...

1) There might be a bug within the polar array calculation. The macro does not step through the solids in the array but it occurs to me that it takes the center of rotation as the center of mass which is not necessarily coincident.

Center of mass when calculated on array:
CenterOfMassWrong.png
CenterOfMassWrong.png (126.3 KiB) Viewed 29 times

Center of mass with dicretes solids:
CenterOfMassCorrect.png
CenterOfMassCorrect.png (148.12 KiB) Viewed 29 times


2) With FC 0.19 at least on my screen the height of the output lines and buttons collapses to be barely visible. I changed the calculation of the COM Popup to be in % of screen height and introduced a few global variables including the output height. Not sure if this is elegant or whatever.

CenterOfMassCollapsed.png
CenterOfMassCollapsed.png (145.31 KiB) Viewed 29 times

OS: Ubuntu 18.04.2 LTS (XFCE/xubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Python version: 3.6.7
Qt version: 5.9.5
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)
Attachments
CenterOfMass.FCMacro
(36.07 KiB) Not downloaded yet
UR_
Posts: 776
Joined: Tue Jan 03, 2017 8:42 pm

Re: Macro to compute center of mass

Postby UR_ » Tue May 21, 2019 7:10 am

hds wrote:
Tue May 21, 2019 6:38 am
... height of the output lines and buttons collapses to be barely visible...
Seems to be a Ubuntu "feature" :)

Annotation 2019-05-21 090429.png
Annotation 2019-05-21 090429.png (60.67 KiB) Viewed 21 times

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.16810 (Git)
Build type: Release
Branch: master
Hash: fc37053210d2abc058c6e14b06d7b8e28aeee8ea
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Germany (de_DE)