Macro SketchUnmap

Context
This macro has been written mainly to circumvent Topological Naming Issue that can break a model when a sketch has been directly or indirectly attached to a face or any other topological item. To prevent breakage, macro shall be applied when the model is still right. It can't "repair" a broken model. If you just break your model, undo the last change(s) back to a good situation, apply the macro to the unstable sketch(es) then redo the previous operation.

Usage
Functionally, the macro will remove the current mapping of the sketch on which it is applied, then apply to it an absolute placement so it is immune to mapping support change.

To do so, the macro will basically propose 3 options (if your sketch isn't in a PartDesign Body, only first option is available and will be applied automatically) :
 * "Raw" mode => the sketch placement is made absolute in the body referential, nothing more
 * "DP@Face mode" => a datum plane is created where the mapping face is, then the sketch is attached to it respecting its attachment offset
 * "DP@Sketch" mode => a datum place is created where the sketch is (including attachment offset), then the sketch is attached to its origin

To use the macro, just select the target sketch (eg. in the tree view) then run the macro. That's it !

Installation
At the moment, the macro isn't available from the addon manager => PR submitted : https://github.com/FreeCAD/FreeCAD-macros/pull/48 So you have to copy the below code and paste it in FreeCAD macro editor.

For more detailed explanations, see the How to install macros page.

Details
For better understanding, below is an example : Let's suppose a simple cube whose top (yellow) face has been drafted. A cylinder is created with a padded circle whose sketch has been mapped (Flat face) to the drafted face and offset to match needs (Attachment offset) :



Now for some reason, you need to revert the pull direction of the draft (of course without the cylinder to move). Here is what basically happen :



The treeview shows an error, the 3D view isn't updated, and the circle sketch is floating in the middle of nowhere...

Now comes the job of the macro (that you need to run before changing the reference face, when the sketch is still at its right place). Select the sketch and run it. If your sketch is in a body, a message box will ask to choose among the 3 different options (if your sketch is out of a body, it will automatically apply the 1st one) : Which in term of picture gives the following :
 * "Raw" mode
 * "DP@Face mode"
 * "DP@Sketch" mode



Script
Icon for the ToolBar

Macro_SketchUnmap.FCMacro

Limitations

 * Only process one sketch at a time
 * Only work on sketch objects

Forum discussion
For any feedback (bug, feature request, comments, ...), please use this forum thread : https://forum.freecadweb.org/viewtopic.php?f=22&t=36078