How do I copy a feature?

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!
Post Reply
judge
Posts: 10
Joined: Fri Jan 21, 2022 4:17 am

How do I copy a feature?

Post by judge »

I would like to copy a feature within a body. Specifically, I have a threaded hole that I would like to copy several times and then adjust the tolerances on each of the copies - so the copy shouldn't affect the original. I have tried copy+paste, but the results of the paste don't appear in the original body.

Manually duplicating each hole, by creating another sketch and then creating a hole from that and manually re-entering all the hole parameters is tedious.

OS: macOS 10.16
Word size of FreeCAD: 64-bit
Version: 0.20.27078 (Git)
Build type: Release
Python version: 3.9.9
Qt version: 5.12.9
Coin version: 4.0.0
OCC version: 7.5.3
Locale: C/Default (C)
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: How do I copy a feature?

Post by chrisb »

I was not successful with my various tries to do this (copy feature+sketch, move into body, copy whole body+move feature+sketch,...) so I doubt that this is possible without help of Python.

Anyway, it would make a reasonable feature request to use a feature as a template!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
chrisb
Veteran
Posts: 53933
Joined: Tue Mar 17, 2015 9:14 am

Re: How do I copy a feature?

Post by chrisb »

I finally found a way, but it is a bit tricky:
- Select feature+Sketch and copy just these two
- paste; this places both outside of the body.
- drag the sketch into the body
(dragging the feature doesn't work, it creates a basefeature)
- select the body
- edit its group property, use the button occurring at the right

(- you are not finished yet, now you have either the previous or the last feature)
- select the new feature
- in the context menu of the property panel select Show All
- change the BaseFeature to the desired predecessor using the three dots button appearing at the right
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
drmacro
Veteran
Posts: 8870
Joined: Sun Mar 02, 2014 4:35 pm

Re: How do I copy a feature?

Post by drmacro »

I'm going to ping @TheMarkster, because I think the Part Design wrapper that he invented can do this, but, I'm not familiar enough with it to instruct how. 8-)
TheMarkster wrote: ping


https://wiki.freecadweb.org/Macro_PDWrapper

https://github.com/mwganson/pdwrapper
Star Trek II: The Wrath of Khan: Spock: "...His pattern indicates two-dimensional thinking."
Grub
Posts: 303
Joined: Sun Nov 15, 2020 7:28 pm

Re: How do I copy a feature?

Post by Grub »

With last version of Fastener WB you can add "threaded rod" (only with threaded rod not with other screws...) with custom parameters :
Capture d’écran (99).png
Capture d’écran (99).png (173.65 KiB) Viewed 569 times

You can use this threads with boolean operations in Part Design for create holes.

(I had to uninstall and reinstall fasteners WB to get the latest version which includes this feature.)
Attachments
Capture d’écran (98).png
Capture d’écran (98).png (11.49 KiB) Viewed 569 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: How do I copy a feature?

Post by TheMarkster »

drmacro wrote: Sat Jan 22, 2022 4:43 pm I'm going to ping @TheMarkster, because I think the Part Design wrapper that he invented can do this, but, I'm not familiar enough with it to instruct how. 8-)
I don't think PDWrapper is the tool for this task, at least not as I understand it. OP wants several duplicates of a Hole and to be able to modify the properties of each duplicate individually, but to have all the original Hole's properties in each as a starting point.

You could make all the holes, each from a separate sketch (or each from a green subshapebinder, each linking to a different circle from the same sketch), and then use some python scripting to copy the properties from the first Hole to all the others.

Code: Select all

orig = App.ActiveDocument.getObject("Hole")
dups = [obj for obj in App.ActiveDocument.Objects if "Hole" in obj.Name and obj != orig]
for prop in orig.PropertiesList:
    if prop == "Profile" or prop == "BaseFeature" or prop == "Shape" or prop == "AddSubShape" or prop == "ExpressionEngine":
        continue
    for dup in dups:
        try:
            setattr(dup,prop,getattr(orig,prop))
        except:
            App.Console.PrintError(f"Error setting {prop}, trying as expression...\n")
            dup.setExpression(prop,orig.Name+"."+prop)
Snip macro screenshot-6a06bb.png
Snip macro screenshot-6a06bb.png (73.75 KiB) Viewed 544 times
Attachments
holes_before.FCStd
(59.65 KiB) Downloaded 9 times
holes_after.FCStd
(53.43 KiB) Downloaded 11 times
Post Reply