Page 5 of 10
Re: Macro to compute center of mass
Posted: Thu Mar 07, 2019 10:23 pm
by PrzemoF
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!
Re: Macro to compute center of mass
Posted: Thu Mar 14, 2019 9:50 pm
by schupin
I just add a new button to automatically change the color of shapes depending on the density indicated :
- colorify_1.png (161.6 KiB) Viewed 4830 times
It might help on big model to identify materials.
(maybe it already exists on the BIM workbench, I didn't look at it...)
Re: Macro to compute center of mass
Posted: Fri Mar 15, 2019 10:10 am
by Syres
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)
Re: Macro to compute center of mass
Posted: Fri Mar 15, 2019 8:46 pm
by schupin
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.
Re: Macro to compute center of mass
Posted: Wed May 15, 2019 7:50 pm
by schupin
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 (61.23 KiB) Viewed 4572 times
I also continue the test through the question 6 and 7 using A2plus :
- Question7.png (151.88 KiB) Viewed 4572 times
I'm pretty pleased to see that FreeCAD tools are dealing perfectly with this "standard" SW exercice:)
Re: Macro to compute center of mass
Posted: Tue May 21, 2019 6:38 am
by hds
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 (126.3 KiB) Viewed 4464 times
Center of mass with dicretes solids:
- CenterOfMassCorrect.png (148.12 KiB) Viewed 4464 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 (145.31 KiB) Viewed 4464 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)
Re: Macro to compute center of mass
Posted: Tue May 21, 2019 7:10 am
by UR_
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 (60.67 KiB) Viewed 4456 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)
Re: Macro to compute center of mass
Posted: Tue May 21, 2019 11:26 am
by hds
Around line 300 this patch seems to work. But i'am not 100% certain. May be a professional could have a closer look at it.
Code: Select all
#2: an array is selected
if hasattr(sel[sol], 'ArrayType'):
if sel[sol].ArrayType == 'polar' and sel[sol].NumberPolar > 0:
# self.centerofmasses[sol] = sel[sol].Center
self.centerofmasses[sol] = FreeCAD.Vector(0,0,0)
for hds_sol in sel[sol].Shape.Solids:
self.centerofmasses[sol] += hds_sol.CenterOfMass
#print(hds_sol.CenterOfMass)
self.centerofmasses[sol] /= sel[sol].Shape.Solids.__len__()
else:
- COMpatched.png (152.58 KiB) Viewed 4419 times
Re: Macro to compute center of mass
Posted: Tue May 21, 2019 1:28 pm
by hds
just found that for multiple arrays or clones thereof there needs to be an additional patch around line 276:
Code: Select all
# Find the center of mass depending of the type of object.
if hasattr(objs[sol], "CenterOfMass"):
self.centerofmasses[sol] = objs[sol].CenterOfMass
elif hasattr(objs[sol], "Solids"):
# self.centerofmasses[sol] = objs[sol].Solids[0].CenterOfMass
self.centerofmasses[sol] = FreeCAD.Vector(0,0,0)
for hds_sol in objs[sol].Solids:
self.centerofmasses[sol] += hds_sol.CenterOfMass
self.centerofmasses[sol] /= objs[sol].Solids.__len__()
#estimate cdg of a mesh
elif hasattr(objs[sol],"Points"):
- MultipleArraysClones.png (124.46 KiB) Viewed 4398 times
Re: Macro to compute center of mass
Posted: Tue May 21, 2019 8:45 pm
by schupin
Thanks a lot for your corrections HDS !
I hope it will help your boat to float
I'll investigate on your graphic bug : I'm on ubuntu (kde), the Freecad-Daily works well.
Code: Select all
OS: Ubuntu 19.04 (KDE/plasma)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Python version: 3.7.3
Qt version: 5.12.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: French/France (fr_FR)
Seems you have an older version of Qt than me (but younger than UR_).
I'll take a deeper look.