Macro to compute center of mass

Show off your FreeCAD projects here!
schupin
Posts: 211
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Sat Nov 17, 2018 12:39 pm

UR_ wrote:
Sat Nov 17, 2018 12:25 pm
I had to do something like this, to get it to work

CenterOfMassUR.FCMacro

EDIT: Perhaps for reference: https://forum.freecadweb.org/viewtopic. ... 62#p267686
Thanks for your "fix".
I'll see how I can make it work everywhere (will certainly do the same thing as you)
UR_
Posts: 734
Joined: Tue Jan 03, 2017 8:42 pm

Re: Macro to compute center of mass

Postby UR_ » Sat Nov 17, 2018 12:55 pm

mario52 wrote:
Tue Nov 13, 2018 3:49 pm
done i create the wiki page Macro_CenterOfMass
wiki page says under Script section
Script

icon file download and paste in the same directory of the macro
But this didn't work for me
Instead i had to use this layout

│ CenterOfMass.FCMacro

├───CenterOfMass
│ com.png
│ compute.png
│ import.png
│ material.png
│ save.png

└───__pycache__
schupin
Posts: 211
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Sat Nov 17, 2018 2:08 pm

You're right.

The location of the icons moved when it arrives on github.
I'll correct the wiki.

Also, in your version the macro looks for the cdg.png file (not the com.png). It have been modified but not pulled yet.
schupin
Posts: 211
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Fri Nov 23, 2018 7:40 pm

I add the support of meshes.

Now, you can select meshes and/or parts (from part design or part WB) and it will give you the total weight and center of mass.
balanceMeshes.png
balanceMeshes.png (74.8 KiB) Viewed 389 times
I also did some bug corrections and change a little the layout management.

Updates are available through the addon manager
triplus
Posts: 7947
Joined: Mon Dec 12, 2011 4:45 pm

Re: Macro to compute center of mass

Postby triplus » Fri Nov 23, 2018 8:21 pm

Nice!
kisolre
Posts: 56
Joined: Wed Nov 21, 2018 1:13 pm

Re: Macro to compute center of mass

Postby kisolre » Sun Jan 20, 2019 10:58 am

I found this macro and tried to use it but I get

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Wivern/AppData/Roaming/FreeCAD/Macro/CenterOfMass.FCMacro", line 47, in <module>
    reload(sys)
<class 'NameError'>: name 'reload' is not defined
So I did some digging and found that in Python3 there is a change where "reload" is located. I imported importlib, changed reload to importlib.reload bur now the sys module is broken.

Code: Select all

Traceback (most recent call last):
  File "C:/Users/Wivern/AppData/Roaming/FreeCAD/Macro/CenterOfMass.FCMacro", line 49, in <module>
    sys.setdefaultencoding('utf8')
<class 'AttributeError'>: module 'sys' has no attribute 'setdefaultencoding'


Should I just use the regular version and not the Conda/Py3 builds if I use the macros? Is it generaly hard to make the macro work with Py2 and Py3?

OS: Windows 8.1
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.15639 (Git)
Build type: Release
Branch: master
Hash: 3f51e25b26ed19a2b17e218c8a0d438eb2e13b26
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Bulgarian/Bulgaria (bg_BG)
schupin
Posts: 211
Joined: Sun Jan 21, 2018 1:43 pm

Re: Macro to compute center of mass

Postby schupin » Mon Jan 21, 2019 6:39 am

kisolre wrote:
Sun Jan 20, 2019 10:58 am
Should I just use the regular version and not the Conda/Py3 builds if I use the macros? Is it generaly hard to make the macro work with Py2 and Py3?
I don't have tried it on the conda version yet. So I guess you're right pointing a compatibility problem.
If you can use the Py2 version, it should work...

I'll try to correct it work as soon as possible.