FreeCAD Macros to create plane from one face using as support the XY

Info about new community or project announcements, implemented features, classes, modules or APIs. Might get technical!
PLEASE DO NOT POST HELP REQUESTS OR OTHER DISCUSSIONS HERE!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
sebasg84
Posts: 13
Joined: Thu Jun 10, 2021 2:12 pm

FreeCAD Macros to create plane from one face using as support the XY

Post by sebasg84 »

Hello everyone, in the telegram group "FreeCAD en español" arose the need for the following macros. I share with you in case any of you find it useful.

Two macros for PartDesign are presented.

The first one creates a datum plane from a face, using as support the XY plane corresponding to the body of the selected face. In this way there is no dependency on the face, and therefore the problem of topological naming is avoided.

The second macro, allows to update the position of the plane, in case the position of the face has changed, by selecting the plane and the face.

phpBB [video]



https://github.com/sebasg84/planeFromFace
galou_breizh
Posts: 436
Joined: Wed Sep 15, 2010 9:38 am

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by galou_breizh »

sebasg84 wrote: Fri Nov 19, 2021 7:47 pm
Nice macros. Would you agree to put them on the official repository (and accept that others may modify your code)? Please send a pull request if yes.

Thanks,
Gaël
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by drmacro »

sebasg84 wrote: Fri Nov 19, 2021 7:47 pm Hello everyone, in the telegram group "FreeCAD en español" arose the need for the following macros. I share with you in case any of you find it useful.

Two macros for PartDesign are presented.

The first one creates a datum plane from a face, using as support the XY plane corresponding to the body of the selected face. In this way there is no dependency on the face, and therefore the problem of topological naming is avoided.

The second macro, allows to update the position of the plane, in case the position of the face has changed, by selecting the plane and the face.


https://github.com/sebasg84/planeFromFace
Nice. Does it have the option to create just a sketch? Since all I typically need is a sketch and it can be positioned the same as a Datum plane. :?:

Edit: I modded it to make just a sketch. 8-)
And, yes, I did it quick and dirty. :mrgreen:
Attachments
sketchFromFace.py
(1.59 KiB) Downloaded 81 times
Last edited by drmacro on Sun Nov 21, 2021 7:16 pm, edited 1 time in total.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
sebasg84
Posts: 13
Joined: Thu Jun 10, 2021 2:12 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by sebasg84 »

galou_breizh wrote: Sat Nov 20, 2021 12:30 pm
sebasg84 wrote: Fri Nov 19, 2021 7:47 pm
Nice macros. Would you agree to put them on the official repository (and accept that others may modify your code)? Please send a pull request if yes.

Thanks,
Gaël
Of course I would like to share them in the official repository. But first, I want to make some arrangements. For example, currently the plane is located at the center of mass of the face, but if the shape of the face changes, then the center of mass also, and the plane would move. I already thought about the solution. As soon as I do, I upload it, and make the pull request.

Thanks,
Sebastian
sebasg84
Posts: 13
Joined: Thu Jun 10, 2021 2:12 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by sebasg84 »

drmacro wrote: Sun Nov 21, 2021 6:53 pm Nice. Does it have the option to create just a sketch? Since all I typically need is a sketch and it can be positioned the same as a Datum plane. :?:

Edit: I modded it to make just a sketch. 8-)
And, yes, I did it quick and dirty. :mrgreen:
I did this too, but I still haven't upload the macro to github. Then I compare your solution with mine, and get the best of both.
I share my macro that create a sketch over the plane in case you want to see it.

Thanks,

Sebastian
Attachments
sketchPlaneFromFace.py
(3.66 KiB) Downloaded 85 times
Last edited by sebasg84 on Sun Nov 21, 2021 7:33 pm, edited 1 time in total.
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by drmacro »

sebasg84 wrote: Sun Nov 21, 2021 7:20 pm
drmacro wrote: Sun Nov 21, 2021 6:53 pm Nice. Does it have the option to create just a sketch? Since all I typically need is a sketch and it can be positioned the same as a Datum plane. :?:

Edit: I modded it to make just a sketch. 8-)
And, yes, I did it quick and dirty. :mrgreen:
I did this too, but I still haven't upload the macro to github. Then I compare your solution with mine, and get the best of both.

Thanks,

Sebastian
I did it really quick. I just changed the type of object it creates to sketch. at this point my version now has variable names that would make the reader (of the code) think it was a datum, when it is in reality a sketch. I'd clean up the names for any sort of release code. :oops:
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
sebasg84
Posts: 13
Joined: Thu Jun 10, 2021 2:12 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by sebasg84 »

drmacro wrote: Sun Nov 21, 2021 7:25 pm I did it really quick. I just changed the type of object it creates to sketch. at this point my version now has variable names that would make the reader (of the code) think it was a datum, when it is in reality a sketch. I'd clean up the names for any sort of release code. :oops:
Edit the previous message, and attach the macro that creates sketch in case you want to try it. The macros need some fixes, which in a short time I will have them ready and upload to github.
drmacro
Veteran
Posts: 8982
Joined: Sun Mar 02, 2014 4:35 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by drmacro »

sebasg84 wrote: Sun Nov 21, 2021 7:36 pm ...
Edit the previous message, and attach the macro that creates sketch in case you want to try it. The macros need some fixes, which in a short time I will have them ready and upload to github.
You misunderstand me. I don't want a datum plane.

In most cases I consider datum planes redundant, so my version creates a sketch, and only a sketch. ;)
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
sebasg84
Posts: 13
Joined: Thu Jun 10, 2021 2:12 pm

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by sebasg84 »

drmacro wrote: Sun Nov 21, 2021 7:46 pm
You misunderstand me. I don't want a datum plane.

In most cases I consider datum planes redundant, so my version creates a sketch, and only a sketch. ;)
I did it, before you ask. And yes, you changed the datumplane to sketch, modifying the line:
datumPlane = body.newObject('PartDesign::Plane','DatumPlane')
for
datumPlane = body.newObject('Sketcher::SketchObject','Sketch')

datumplane may not be necessary. In the group I mentioned, they asked about doing it this way.

You can also add:
Gui.ActiveDocument.setEdit(body,0,datumPlane.Name+".")
If you want the skectch to enter directly into edit.
LHC
Posts: 321
Joined: Thu Sep 17, 2020 4:21 pm
Location: Canadian Coffee Shop

Re: FreeCAD Macros to create plane from one face using as support the XY

Post by LHC »

Hi - this thread is a bit old and I'm wondering if this macro(s) are stable and ready to be used by average users - like me :D
Post Reply