Preserving global position of Parts during export

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
iari
Posts: 42
Joined: Mon Nov 18, 2013 8:52 pm

Preserving global position of Parts during export

Post by iari »

Hi,
I often receive STEP or FCStd files from collegues containing Parts inside Body objects. If I export a single Part, its position with respect to the global reference system is not preserved. As an example, in the attached file, export separately the two Parts, then load them: they will be far apart. Their relative position is not preserved. Is there a way to export a Part preserving its global position?

Thanks!

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16110 (Git)
Build type: Release
Branch: (HEAD detached at upstream/releases/FreeCAD-0-18)
Hash: f7dccfaa909e5b9da26bf50c4a22ccca9bb10c40
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: Italian/Italy (it_IT)
Attachments
Example.FCStd
(18.1 KiB) Downloaded 65 times
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Preserving global position of Parts during export

Post by openBrain »

Hi,

This happens because of the "Body2" part container. Actually this container lives in an "unfinished" implementation. Especially when its placement is changed, it creates a new origin root that is then used by children as their own origin.
When you export, the origin shift created by the part container isn't took into account.

A simple workaround is to not change placement of part container. In your example, "Body002" should be set to position 0,0,0 with a 0° rotation, then "Solid005" should be moved to its position with its own placement property. ;)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Preserving global position of Parts during export

Post by openBrain »

Notice that if you're pretty comfortable with Python, this is fixed with 2 code lines (in your example) :

Code: Select all

>>> Gui.ActiveDocument.Part__Feature009.Object.Placement = Gui.ActiveDocument.Part__Feature009.Object.getGlobalPlacement()
>>> Gui.ActiveDocument.R1823_ConLenteCondensatrice.Object.Placement = App.Placement(App.Vector(0,0,0),App.Rotation(0,0,0))
If you're facing that often, that could be easily solved with a macro. ;)
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Preserving global position of Parts during export

Post by openBrain »

Finally attached an alpha release macro that you can run on needed documents.
It will basically reset all part containers to the global origin while preserving objects absolute placements. ;)
Should solve your problems at exporting.
Attachments
Absolufy.FCMacro
(1.46 KiB) Downloaded 284 times
iari
Posts: 42
Joined: Mon Nov 18, 2013 8:52 pm

Re: Preserving global position of Parts during export

Post by iari »

Oh, thank you!
Especially to openBrain for the macro! :D
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: Preserving global position of Parts during export

Post by easyw-fc »

@iari,
if you had followed the links, you would have found
https://www.freecadweb.org/wiki/Macro_DeepCopy installable with FC Addons Manager
iari
Posts: 42
Joined: Mon Nov 18, 2013 8:52 pm

Re: Preserving global position of Parts during export

Post by iari »

Thank you, easyw-fc, for signaling also the DeepCopy macro.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Preserving global position of Parts during export

Post by openBrain »

easyw-fc wrote: Thu Jun 06, 2019 9:05 pm @iari,
if you had followed the links, you would have found
https://www.freecadweb.org/wiki/Macro_DeepCopy installable with FC Addons Manager
But DeepCopy loses hierarchy, which isn't always suitable. ;)
User avatar
easyw-fc
Veteran
Posts: 3633
Joined: Thu Jul 09, 2015 9:34 am

Re: Preserving global position of Parts during export

Post by easyw-fc »

openBrain wrote: Fri Jun 07, 2019 11:44 am But DeepCopy loses hierarchy, which isn't always suitable. ;)
yes, but the OP needs are as per single part placement:
iari wrote: Thu Jun 06, 2019 5:36 pm If I export a single Part, its position with respect to the global reference system is not preserved. As an example, in the attached file, export separately the two Parts, then load them: they will be far apart.
FreeCAD doesn't fail to export the full hierarchy placement.
Post Reply