Brilliant - just what I need! Thanks a lot!
Now, first I got discouraged that it only works for Part and not Part Design (as I read the description).
But..., I found a workaround - it seems. Really simple.
I am although not sure how it works in practice since I have only tested it with a simple sketch as template and then using the new variant Link functionality.
So basic steps:
1. In a blank project create just a Part.
2. Go to Part Design and create a Body.
3. Create a Sketch and select some Plane.
4. Create an initial closed sketch using normal geometry (well just like you normally would).
5. Create e.g. a Pad on that sketch.
6. Hopefully everything looks nice and dandy.
7. Make sure to save the project!
8. Now open an existing blank Assembly file (or create one in another project!)
9. Copy its Variables container or whatever we should call it (it is of type App::PropertyContainer).
10. Back in the other project containing the Part activate that part (or go to Assembly 4 Workbench in case of doubt). Right click on Assembly and select "Toggle active part".
11. Paste the Variables container into the Part. If you are a bit unlucky it might end up the wrong place, but then simply drag it into the Part.
12. Create the variable in the part, by doing this:
a. Go to the Variables container by clicking on it.
b. Make sure its Data (sub) tab is selected in the "Property View".
c. Right click and select "Show all"
d. Right click and select "Add property".
e. Under "Group" enter "Variables".
f. Under "Name" enter the name you want to give your variable!
Whether you want to prefix the group name is up to you (I just left it so. So I have not tested it without.)
g. Click "OK".
h. Outside give the variable a default value you want it to have.
13. Open you previous sketch.
14. Add or change an existing constraint and enter a formula for that constraint. It would be called something like: Variables.Variables_"name of your variable"
15. Remember to create a LCS (local coordinate system) using Assembly 4 Workbench in the part!
16. Save the Part again.
17. Create or reuse an existing Assembly.
18. Use the new functionality/Icon where it says "... Create a variant link to a part ..." (that green and yellow Part like looking icon).
19. Insert the part one or several times and obviously set the linked parts (in the Assembly 4 workbench - "Move/Attach a Part in the assembly"/"Place linked part").
20. Click on one of the imported (virtual/variant linked) Parts (not its internal contents -
do not expand, because that would be the wrong place - read below).
21. In the Property View scroll all the way down till you get to the "Variant Variables" and change the value in the variable that has the name of your variable! Enjoy - but see the caveats and bug/consequence description below!
There are caveats:
* After changing the variable in the imported (variant linked) part then the part gets (e.g. resized), but you will have to save and close the assembly and open it again to get alignment at the specified attachment point right (e.g. to get parts centered to one another). (Not a big problem necessarily in a static assembly where you are not making many changes).
* Should any consider to dive into the part (open the variant linked virtual part) and modify its Variables "variable" then the value will not be saved (it is also the wrong way to handle it (since you need to do that directly on the virtual variant part), but you can modify its formula(!) and then the value or specific formula you may enter gets saved! Just remember it is an anti-pattern (it is the wrong place/way of doing it! Read above!)
But there seems to be a bug/consequence of my 'hack':
When the folders in /tmp/ called "FreeCADStartThumbnails" + "random characters" are deleted then at following startups in FreeCAD loading an assembly triggers this output (error is printed in red in the "Report view"):
Code: Select all
16:32:49 Exception opening file: /tmp/FreeCAD_Doc_3e6cdd91-522f-4709-9335-6d66db370d38_da39a3_10317 [File '/tmp/FreeCAD_Doc_3e6cdd91-522f-4709-9335-6d66db370d38_da39a3_10317' does not exist!]
16:32:49 Exception opening file: /tmp/FreeCAD_Doc_052373ee-e232-4725-bae8-be6d728472b7_da39a3_10317 [File '/tmp/FreeCAD_Doc_052373ee-e232-4725-bae8-be6d728472b7_da39a3_10317' does not exist!]
, which is true, but there are some other of these directories:
"FreeCAD_Doc_" + "random characters"
This seems to be the "Transient Dir" of the project (whatever that is used for).
Anyway the 'hack' still seems to work despite the bug/consequence of my 'hack'.
Enjoy!
Thanks Zolko for your work!
OS: Ubuntu 20.04.3 LTS (MATE/mate)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: 0d9536ed3e8c7f40197b5606e1b7873625e1d6fe
Python version: 3.8.10
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.2
Locale: Danish/Denmark (da_DK)