[FR] macro to remap sketch to different reference

Need help, or want to share a macro? Post here!
Posts: 776
Joined: Tue Jan 03, 2017 8:42 pm

Re: [FR] macro to remap sketch to different reference

Postby UR_ » Mon May 06, 2019 4:49 pm

The global variable FreeCAD.old_placement should be cleared after usage, otherwise its content can be used more than one time, without triggering except: block.
So an old value becomes the new placement in case you forget starting PlacementGet first. :(
Posts: 558
Joined: Wed Nov 21, 2018 1:13 pm

Re: [FR] macro to remap sketch to different reference

Postby kisolre » Mon May 06, 2019 5:54 pm

UR_ wrote:
Mon May 06, 2019 4:49 pm
The global variable FreeCAD.old_placement...
I though about that but decided not to do it (it is a "del FreeCAD.old_placement", right?) since I might want to place more things there. If the new placement is wrong it is easy to spot and a simple undo works.
Here I used it to transfer placement of a sketch attached to face (the square) to the sketch in another body(the hexagon) which could be used to design matching bodies:
Placement to different body.JPG
Placement to different body.JPG (89.09 KiB) Viewed 94 times
Of cource we have datumplanes for that :)
Posts: 840
Joined: Fri Nov 09, 2018 5:38 pm

Re: [FR] macro to remap sketch to different reference

Postby openBrain » Fri May 17, 2019 10:50 pm

kisolre wrote:
Thu May 02, 2019 4:42 pm
The sketch should not change its location at all. That is the whole point.
I'm a bit late on the fight, but as I promised, below is my proposal of macro (attached to this post).

First a simple example to ease further explanations (not an excellent example IMHO, but didn't found better one.. :lol: ).

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)
unmap_ex1.png (27.94 KiB) Viewed 55 times

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 :
unmap_ex2.png (11.96 KiB) Viewed 55 times
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 3 different options (if your sketch is out of a body, it will automatically apply the 1st one).
A copy of the macro header :

Code: Select all

# * "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
And a picture for better understanding (right side view after macro running + draft reverted) :
unmap_macro.png (46.19 KiB) Viewed 55 times

Hope that helps. A next step could be to deal with multiple sketch selection, or whatever you think about. All feedbacks welcome. ;)
(4.1 KiB) Downloaded 2 times
User avatar
Posts: 1078
Joined: Mon Jul 10, 2017 12:36 pm
Location: Hof Germany

Re: [FR] macro to remap sketch to different reference

Postby HarryGeier » Sat May 18, 2019 5:41 am

Looks promising.
I will try it asap
Kaum macht man´s richtig , gehts´s
My Video Tutorials on Youtube: https://www.youtube.com/channel/UCoe3B ... p8Q/videos
My FreeCAD Stuff on Hidrive: https://my.hidrive.com/share/qr3l1yddy6#$/