Assigning sketches to standard planes, macro

Need help, or want to share a macro? Post here!
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Assigning sketches to standard planes, macro

Postby freedman » Wed Nov 18, 2020 6:50 pm

TheMarkster wrote this in a post and it got me fired up to generate a macro:
https://forum.freecadweb.org/viewtopic. ... 88#p444030

See the last post.
Last edited by freedman on Fri Nov 20, 2020 3:17 pm, edited 2 times in total.
kisolre
Posts: 2372
Joined: Wed Nov 21, 2018 1:13 pm

Re: Assigning sketches to standard planes, macro

Postby kisolre » Wed Nov 18, 2020 7:12 pm

Could you add possibility too remap to selected objects CS? Like add a datum plane and remap several linked sketches to it for easy common manipulation?
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Assigning sketches to standard planes, macro

Postby freedman » Wed Nov 18, 2020 7:53 pm

See last post.
Last edited by freedman on Fri Nov 20, 2020 3:18 pm, edited 1 time in total.
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Assigning sketches to standard planes, macro

Postby freedman » Thu Nov 19, 2020 5:27 pm

Here you go. There isn't a lot of error handing so select appropriate stuff because it will remap to almost anything :). The button "???" will fill in with the reference selected, a new Plane/Datum/LCS can be selected anytime. Now that we have a target for mapping we move to the lower section and select a sketch, then click on the "Map to support" button. The map to support process can be repeated, pick a sketch click the button.

Maybe not the best interface, I didn't have much time. :)


I should also reiterate that this macro will remap sketches to standard planes/datum planes/LCS while preserving the sketch location. If this looks like something we could use in the Help section to allow folks to fix their (face attached models) I can add error handling.

Edit: I noticed that after the new mapping a recompute should be done. I will leave that out of the macro at this point.
Attachments
User_map_to_v1.FCMacro
(4.29 KiB) Downloaded 10 times
Map_pic.JPG
Map_pic.JPG (15.39 KiB) Viewed 370 times
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Assigning sketches to standard planes, macro

Postby freedman » Sat Nov 21, 2020 6:25 am

I plan to add recompute to the macro, I have had some FreeCAD crashes, this thing is a bit dangerous without a recompute I think. You can also imagine as I do that mapping a sketch to new place could have some serious issues if not done in a correct way and finished completely.

If anyone has thoughts about features that could make this more useful as a test bed for anti-TNP modeling. Is there some sort of next step?
Some thoughts I had:

1) I could add an auto assign to sketch button that would automatically assign a sketch to a plane when exiting Sketcher.

2)A thought, could everything just be assigned to the XY_Plane. If I create a model and pad, then pocket a few features the model doesn't care if I map everything to the XY_plane, the Pad/pocket holds the correct offsets, granted they can be very complex in the properties, but not in the Pad/Pocket task combo view windows

3) When the remapping occurs could the map-to face location be saved and compared later for changes.

Thanks
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Assigning sketches to standard planes, macro

Postby freedman » Sat Nov 21, 2020 5:03 pm

I updated the macro, now V2. I added a recompute after every map assignment and made the XY plane a default selection. I think this is much more stable to use.
Attachments
map_v2.png
map_v2.png (36.98 KiB) Viewed 162 times
User_map_to_V2.FCMacro
(4.53 KiB) Downloaded 7 times
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Assigning sketches to standard planes, macro

Postby freedman » Sat Nov 21, 2020 9:23 pm

Had an upgrade idea: Added another button that allows direct mapping. You can select and map a Sketch/Plane/Datum/LCS direct to some other Plane/Datum/LCS. Have fun mapping.
Attachments
User_map_to_V3.FCMacro
(5.82 KiB) Downloaded 7 times
map_3.JPG
map_3.JPG (21.03 KiB) Viewed 127 times
edi
Posts: 113
Joined: Fri Jan 17, 2020 1:32 pm

Re: Assigning sketches to standard planes, macro

Postby edi » Mon Nov 23, 2020 3:36 pm

Could you please give a workflow how to use the script.
I did the following:
- create a sketch and a datum plane
- start the script
- select the sketch
- click the XY-Plane button
- select the plane
- click the upper Map to support button

Returned are the messages:
1372.47 <App> Document.cpp(3151): The graph must be a DAG.
1372.52 <App> Document.cpp(3504): Unbenannt#Sketch still touched after recompute
freedman
Posts: 1692
Joined: Thu Mar 22, 2018 3:02 am
Location: Washington State, USA

Re: Assigning sketches to standard planes, macro

Postby freedman » Mon Nov 23, 2020 4:20 pm

Returned are the messages:
1372.47 <App> Document.cpp(3151): The graph must be a DAG.
1372.52 <App> Document.cpp(3504): Unbenannt#Sketch still touched after recompute
Oh ya! You can mess up a model so very quickly using this. I should write in bold. Development only on every page. To use this you really need to have a good handle on FreeCAD basic structure.

Step #1, is the target Plane/Datum/LCS, I wrote it this way so the user knows that those are the only things that should be selected. You select the reference in the tree and click the button, you will see the button text populate. Let's say it states XY_plane.

Step #2,
Select a sketch and click Map to support, your now finished with one mappping. If you go look at the sketch support you will see XY_Plane.

After this you you can do more by repeating step #2 but you also need to decided on what the goal is. If you mapping everything to the XY_Plane then you don't need to do step #1 again.