Reusable Features in Part Design

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!
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: Reusable Features in Part Design

Post by drmacro »

I have used a configuration table for things like 20x20 extrusions.

In the document with the config table, I select a given config (typically predefined lengths), make a simple copy for configuration.

Then from the assembly I link to the simple copies. True, the copies aren't parametric, but, for standard/pre-defined lengths for standard shapes (20x20, I-beam, angle, etc.) parametric is not absolutely necessary.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
User avatar
papyblaise
Veteran
Posts: 7872
Joined: Thu Jun 13, 2019 4:28 pm
Location: France

Re: Reusable Features in Part Design

Post by papyblaise »

have you thought about looking in Fastener, there are I believe several thousand screws and nuts ready made
SarenT
Posts: 50
Joined: Sat Jan 12, 2019 2:30 pm

Re: Reusable Features in Part Design

Post by SarenT »

thomas-neemann wrote: Wed May 31, 2023 11:09 am there is no macro or function for this. you create normal geometries that can be used as cutting tools (boolean cut) and save them in a central location with meaningful names
Ah, I see.
drmacro wrote: Wed May 31, 2023 11:31 am Then from the assembly I link to the simple copies. True, the copies aren't parametric, but, for standard/pre-defined lengths for standard shapes (20x20, I-beam, angle, etc.) parametric is not absolutely necessary.
Indeed, but I need a more generalized solution with many parametric additions. My intentions are defining microfluidic "features" and reuse them according a plan.
papyblaise wrote: Wed May 31, 2023 11:37 am have you thought about looking in Fastener, there are I believe several thousand screws and nuts ready made
Yes, but I used the hex nut and bolt example, because it is more relatable. I often design features for my 3D print parts, which I need to reuse without patterns. I find it exhausting to redo the operations again and again. It gets worse with microfluidics, as there are many features, which need to be repeated/reused.
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: Reusable Features in Part Design

Post by drmacro »

SarenT wrote: Wed May 31, 2023 11:45 am ...

Indeed, but I need a more generalized solution with many parametric additions. My intentions are defining microfluidic "features" and reuse them according a plan.

...
If each feature is predefined, then the dimensions are not parametric. What I described is essentially building a library of reusable components.

What I describe does not allow each instance of each component to be randomly adjusted. If that is your desire, then existing techniques may not meet your needs.
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
SarenT
Posts: 50
Joined: Sat Jan 12, 2019 2:30 pm

Re: Reusable Features in Part Design

Post by SarenT »

If there is enough consensus that this feature is missing but would be useful, this would be a feature request.

The way I imagine it that the part origin would be by default the point in space to align/place. Users should be able do reach these custom features in the Part and PartDesign workbench under a menu and insert parameters in the property view (and tasks). The features should also be aligned at either datums (e.g. origin of the custom feature aligned at the datum point). Another option to place them could be to use a dummy sketch to place a single point to place and orient the custom feature (since sketches also have a base plane). This is somewhat similar to lofts/pipes in the sense that referencing a sketch and a feature, one can perform such grouped parametric actions.

I would like to hear your opinions before submitting a feature request. I guess, it can even be implemeted via subshapebinder.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Reusable Features in Part Design

Post by onekk »

SarenT wrote: Wed May 31, 2023 10:34 am ...
I have used as example a sketch to make two identical brackets using scripting:

Code: Select all

    sk2 = body.newObject('Sketcher::SketchObject')
    sk2.Label = f'{bd_nm}_BKT_sk'
    sk2.MapMode = 'FlatFace'
    sk2.Support = (get_body_plane(body, 'XZ_Plane'), [''])

....
    ssb1 = body.newObject('PartDesign::SubShapeBinder')
    ssb1.Label = f'{bd_nm}_BKT_bind1'
    ssb1.Support = sk2
    ssb1.setExpression('.Placement.Base.z', f'{pa2.Name}.Length')
    ssb1.setExpression('.Placement.Base.y', f'{sk1.Name}.Constraints.xlen * -0.5')
  
  ...

    # Pad to proper thickness
    pa3 = body.newObject('PartDesign::Pad')
    pa3.Label = f'{bd_nm}_BKT_r'
    pa3.Profile = ssb1
  ...
    body.Tip = pa3

    ssb2 = body.newObject('PartDesign::SubShapeBinder')
    ssb2.Label = f'{bd_nm}_BKT_bind2'
    ssb2.Support = sk2
    ssb2.setExpression('.Placement.Base.z', f'{pa2.Name}.Length')
    ssb2.setExpression('.Placement.Base.y', f'{sk1.Name}.Constraints.xlen * 0.5')
 ...
    pa4 = body.newObject('PartDesign::Pad')
    pa4.Label = f'{bd_nm}_BKT_l'
    pa4.Profile = ssb2
 ...
    body.Tip = pa4
It is not difficult to see that the object is the same, but supplied to two "Sub ShapeBinder" and then used to make two different "pads", after having mode the subshapebinder in place modifying his Placement property using expression and "named constraints".

Obviously your mileage may vary, but a sketch could be reused many times in this way, the only difficult could be to find an appropriate expression for Placement.Base that is the scripting way to refer to the "translation vector" part of a Placement.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
SarenT
Posts: 50
Joined: Sat Jan 12, 2019 2:30 pm

Re: Reusable Features in Part Design

Post by SarenT »

onekk wrote: Wed May 31, 2023 4:28 pm
SarenT wrote: Wed May 31, 2023 10:34 am ...
I have used as example a sketch to make two identical brackets using scripting:

Code: Select all

    sk2 = body.newObject('Sketcher::SketchObject')
    sk2.Label = f'{bd_nm}_BKT_sk'
    sk2.MapMode = 'FlatFace'
    sk2.Support = (get_body_plane(body, 'XZ_Plane'), [''])

....
    ssb1 = body.newObject('PartDesign::SubShapeBinder')
    ssb1.Label = f'{bd_nm}_BKT_bind1'
    ssb1.Support = sk2
    ssb1.setExpression('.Placement.Base.z', f'{pa2.Name}.Length')
    ssb1.setExpression('.Placement.Base.y', f'{sk1.Name}.Constraints.xlen * -0.5')
  
  ...

    # Pad to proper thickness
    pa3 = body.newObject('PartDesign::Pad')
    pa3.Label = f'{bd_nm}_BKT_r'
    pa3.Profile = ssb1
  ...
    body.Tip = pa3

    ssb2 = body.newObject('PartDesign::SubShapeBinder')
    ssb2.Label = f'{bd_nm}_BKT_bind2'
    ssb2.Support = sk2
    ssb2.setExpression('.Placement.Base.z', f'{pa2.Name}.Length')
    ssb2.setExpression('.Placement.Base.y', f'{sk1.Name}.Constraints.xlen * 0.5')
 ...
    pa4 = body.newObject('PartDesign::Pad')
    pa4.Label = f'{bd_nm}_BKT_l'
    pa4.Profile = ssb2
 ...
    body.Tip = pa4
It is not difficult to see that the object is the same, but supplied to two "Sub ShapeBinder" and then used to make two different "pads", after having mode the subshapebinder in place modifying his Placement property using expression and "named constraints".

Obviously your mileage may vary, but a sketch could be reused many times in this way, the only difficult could be to find an appropriate expression for Placement.Base that is the scripting way to refer to the "translation vector" part of a Placement.
Can you share this file as an example? I haven't started with scripting yet. I would like to see how you implemented it. Since, the feature is missing, I am considering either OpenSCAD or FreeCAD Macros.
As for the placement, I would use a simple sketch with a line or point (as reference). Placing sketches are quite simple. They require a plane and need to be constrained in X/Y on that plane. Then it should be easy to place the origin of the complex geometry onto that reference point.
User avatar
onekk
Veteran
Posts: 6146
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Reusable Features in Part Design

Post by onekk »

SarenT wrote: Thu Jun 01, 2023 7:29 am ...
Sadly I can't share this script, it is for s fairly complex paid job so it is more thsn 2000 lines long and contain reserved drawings.

But probably doon I have time to make some other examples on "Python Scripting..." section of this forum, there are around some post of mine, so probably you could modify one of them and eventually ask for advice in "Python..." forum section.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
SarenT
Posts: 50
Joined: Sat Jan 12, 2019 2:30 pm

Re: Reusable Features in Part Design

Post by SarenT »

Hi there,
sorry for bumping up an old topic. I will then move on submitting a feature request for this and link this thread. Thanks for all the inputs.
Edit: I am not sure if the github page accepts feature requests.
edwilliams16
Veteran
Posts: 3112
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Reusable Features in Part Design

Post by edwilliams16 »

SarenT wrote: Thu Dec 14, 2023 4:05 pm
The Lattice2 workbench allows for repeating a PD Feature at an array of locations. https://github.com/DeepSOIC/Lattice2/wi ... n-Tutorial
Post Reply