Macro to compute center of mass
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Re: Macro to compute center of mass
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
I just add a new button to automatically change the color of shapes depending on the density indicated :
It might help on big model to identify materials.
(maybe it already exists on the BIM workbench, I didn't look at it...)
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
Thanks for the update and the colours should prove helpful. Just for info I had to change line 27 to:
in order to stop this error :
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)
Code: Select all
__Icon__ = 'https://www.freecadweb.org/wiki/images/4/41/Macro_CenterOfMass.png'
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))
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
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.
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
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 :
I also continue the test through the question 6 and 7 using A2plus :
I'm pretty pleased to see that FreeCAD tools are dealing perfectly with this "standard" SW exercice:)
It worked pretty well :
I also continue the test through the question 6 and 7 using A2plus :
I'm pretty pleased to see that FreeCAD tools are dealing perfectly with this "standard" SW exercice:)
Re: Macro to compute center of mass
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:
Center of mass with dicretes solids:
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.
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)
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:
Center of mass with dicretes solids:
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.
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) Downloaded 119 times
Re: Macro to compute center of mass
Seems to be a Ubuntu "feature"
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
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:
- Attachments
-
- COMtest.FCStd
- (16.82 KiB) Downloaded 141 times
Re: Macro to compute center of mass
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"):
- Attachments
-
- AkkuTest.FCStd
- (21.73 KiB) Downloaded 100 times
Re: Macro to compute center of mass
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.
Seems you have an older version of Qt than me (but younger than UR_).
I'll take a deeper look.
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)
I'll take a deeper look.