Macro to compute center of mass

Show off your FreeCAD projects here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Macro to compute center of mass

Post by Kunda1 »

Wow, are there any screenshots of the features available ?
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
SyProLei
Posts: 12
Joined: Tue Feb 15, 2022 9:43 am
Contact:

Re: Macro to compute center of mass

Post by SyProLei »

Kunda1 wrote: Mon Aug 29, 2022 1:08 pm Wow, are there any screenshots of the features available ?
Screenshot-v0.6.png
Screenshot-v0.6.png (215.54 KiB) Viewed 7025 times
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 »

Image
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
SyProLei
Posts: 12
Joined: Tue Feb 15, 2022 9:43 am
Contact:

Re: Macro to compute center of mass

Post by SyProLei »

New Release: Version 0.7.0 is officially available.
Here is the changelog, apart from the internal code changes:
  • New: Searchbar for solids
  • New: Reworked import function to improve external bill of materials (BOM) import with better input tolerance. Caption "weight" has to be changed to "mass" if you want to import mass from an old file export of the macro.
  • New: Mass can be set zero to exclude solid from calculation and visualization
  • Fix: Behaviour of default value spin and "Apply to all"
  • Fix: Preserve original solids color when "New" button pressed
This should help you work with large assemblies. Unfortunately, long loading times persist with large assemblies of complex shapes because of
  1. the calculation time FreeCAD takes for each call of .Volume and .CenterOfGravity (.CenterOfMass in FreeCAD 0.19 respectively) and
  2. searching the valid shape for these calls from depending objects and getting its global placement in the assembly.
We are part of the technology transfer program for lightweight engineering funded by German Federal Ministry for Economic Affairs and Climate Action.
SyProLei
Posts: 12
Joined: Tue Feb 15, 2022 9:43 am
Contact:

Re: Macro to compute center of mass

Post by SyProLei »

@Kunda1
@yorik
Can you give me access to update the wiki page?
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: Macro to compute center of mass

Post by chrisb »

SyProLei wrote: Wed Aug 16, 2023 2:43 pm Can you give me access to update the wiki page?
viewtopic.php?t=6830
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
MeSat
Posts: 43
Joined: Fri Jul 10, 2015 4:43 am

Re: Macro to compute center of mass

Post by MeSat »

Hello,

I am trying this macro on a project and not sure if I missed something as I am having issues and I cannot find a location to enter the bug reports. I have gone through the Wiki and cannot find the answers.

I am using the appimage and there are no materials in the drop down list. I get an error message when I select the material icon.

Code: Select all

10:20:27  Traceback (most recent call last):
10:20:27    File "/home/robin/.local/share/FreeCAD/Macro/CenterOfMass.FCMacro", line 737, in on_pushButton_editMaterial
10:20:27      MaterialEditor.openEditor()
10:20:27    File "/tmp/.mount_FreeCApt8LLo/usr/Mod/Material/MaterialEditor.py", line 950, in openEditor
10:20:27      editor = MaterialEditor(obj, prop)
10:20:27    File "/tmp/.mount_FreeCApt8LLo/usr/Mod/Material/MaterialEditor.py", line 72, in __init__
10:20:27      self.widget = FreeCADGui.PySideUic.loadUi(filePath + "Resources" + os.sep + "ui" + os.sep + "materials-editor.ui")
10:20:27    File "<string>", line 4, in <module>
10:20:27  RuntimeError: Cannot open file
This may be related to how the macro is installed or do I have to create my own material list using the Material workbench?

On Linux, at least, the appimage runs in a different directory every time it is started. So, if the Addon manager installs files to be used later into this directory, they are lost when the appimage is closed. I have run into this with desktops in the past.

Second issue is I ran this code and for the centre of mass, I am getting negative numbers and the reference box is NOT around the model as per the image.
CofM image
CofM image
CofM_issue.jpg (57.4 KiB) Viewed 864 times
The mass calculated is very close to my calculations but my CoM is -766.9500669679464 -189.58632323493663 365.92027040536425

For reference the base of the image is 500mm X 500mm and the angle iron is 1830mm high.

There is nothing on the wiki to explain what these numbers are or where the zero reference is.
MeSat
Posts: 43
Joined: Fri Jul 10, 2015 4:43 am

Re: Macro to compute center of mass

Post by MeSat »

I did some tests. The issue is related to where the macro is reading the locations of the different solids. The project I am working on and the image I provided is assembled using Assembly 4. The various LCS's for joining of the items are not all referenced to the same point, depending on the original item.

Items are joined by different LCS's and then assembled. The macro doesn't take this into account in its present form.

I just did a test with two items. Drawn as one solid, the CofM was where it should have been. Drawn as two items and then assembled in Assembly 4, the bounding box is referenced to one of the items and CofM is indicated in that box and not even close to the true CofM. See my quickly created example.
CofM_bug_block.FCStd
CofM Assembly4 issue example
(41.94 KiB) Downloaded 11 times
MeSat
Posts: 43
Joined: Fri Jul 10, 2015 4:43 am

Re: Macro to compute center of mass

Post by MeSat »

I didn't see that there is a thread about GlobalPlacement. I believe that the issue I am having is related to that discussion.
SyProLei
Posts: 12
Joined: Tue Feb 15, 2022 9:43 am
Contact:

Re: Macro to compute center of mass

Post by SyProLei »

Thank you for providing your information about the errors you experienced with the macro.
A huge part of the macro deals with workarounds to unify different data structures and body formats. Unfortunately, at the moment the case of App::Link cannot be covered in most situations because of the topic you already stumbled across.
MeSat wrote: Thu Mar 07, 2024 5:41 pm I am using the appimage and there are no materials in the drop down list. I get an error message when I select the material icon.
It seems you are using a development version. The new material system as well as the default Assembly workbench are not yet included in the macro.
We are part of the technology transfer program for lightweight engineering funded by German Federal Ministry for Economic Affairs and Climate Action.
Post Reply