Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
ppemawm
Veteran
Posts: 1240
Joined: Fri May 17, 2013 3:54 pm
Location: New York NY USA

Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by ppemawm »

It is frequently required that you must assemble multiple copies of the same body in an Assembly4 Model such as fasteners in a flange bolt circle or spokes in a wheel. The following example taken from a project currently in process shows how you can use Draft Arrays > Polar > Link Arrays for this purpose.

Comments in the image captions below explain how this is done:

The wheel example I am using is extracted from an assembly model currently in process.  It is a US Civil War era repeating gun patented by R. J. Gatling in 1862, most of which is shown in this image.<br /><br />The Assembly4 assembly concept is ingeniously simple.  The local coordinate system constraints of each linked body, part, or sub-assembly are attached at their appropriate contact point to lock all degrees of freedom.  <br /><br /> If any the assembly needs to translate or rotate then the necessary degrees of freedom can be simply unlocked with Assembly4 Variables and Expressions in the Attachment Offset properties.  If carefully assembled with the default LCS in each Assembly4 Body the dreaded TPM can be completely avoided.<br /><br />Any moving bodies LCS's can also be attached to a master control sketch to use the Sketcher solver to simulate intricate motion with the Assembly4 Animator with the caveat that the sketch can sometimes break and interrupt the LCS attachments.
The wheel example I am using is extracted from an assembly model currently in process. It is a US Civil War era repeating gun patented by R. J. Gatling in 1862, most of which is shown in this image.

The Assembly4 assembly concept is ingeniously simple. The local coordinate system constraints of each linked body, part, or sub-assembly are attached at their appropriate contact point to lock all degrees of freedom.

If any the assembly needs to translate or rotate then the necessary degrees of freedom can be simply unlocked with Assembly4 Variables and Expressions in the Attachment Offset properties. If carefully assembled with the default LCS in each Assembly4 Body the dreaded TPM can be completely avoided.

Any moving bodies LCS's can also be attached to a master control sketch to use the Sketcher solver to simulate intricate motion with the Assembly4 Animator with the caveat that the sketch can sometimes break and interrupt the LCS attachments.
Capture6.JPG (274.98 KiB) Viewed 2122 times
This is the wheel sub-assembly that requires multiple copies of bodies as shown in this Assembly4 model.  Arrays are used for the spokes, fasteners, rim segments, and retaining bridges between the segments.<br /><br />Note that in the Tree View on the right side of the screen all of the PartDesign bodies required for the assembly are saved in the Assembly4 Parts folder for convenience in sharing the file.  Or, each body could be saved in its own separate file for ease of reuse.
This is the wheel sub-assembly that requires multiple copies of bodies as shown in this Assembly4 model. Arrays are used for the spokes, fasteners, rim segments, and retaining bridges between the segments.

Note that in the Tree View on the right side of the screen all of the PartDesign bodies required for the assembly are saved in the Assembly4 Parts folder for convenience in sharing the file. Or, each body could be saved in its own separate file for ease of reuse.
Capture7.JPG (232.02 KiB) Viewed 2122 times
This image is of a typical array requirement in an assembly.  Here a spoke is attached to its hub LCS.  The default LCS and the first Body sketch of the spoke are at the same global origin as the hub.  That avoids any awkward offsets when assembling.<br /><br />There are left and right hand spokes due to the bolt hole.<br /><br />One way to add multiple bodies is to assemble multiple links and tediously rotate them individually to their location with attachment offsets.  Or you can do the same more easily with the Link Element Count as highlighted in the Property View of the spoke in the above image but with the same tedious requirement for the individual attachment offsets.
This image is of a typical array requirement in an assembly. Here a spoke is attached to its hub LCS. The default LCS and the first Body sketch of the spoke are at the same global origin as the hub. That avoids any awkward offsets when assembling.

There are left and right hand spokes due to the bolt hole.

One way to add multiple bodies is to assemble multiple links and tediously rotate them individually to their location with attachment offsets. Or you can do the same more easily with the Link Element Count as highlighted in the Property View of the spoke in the above image but with the same tedious requirement for the individual attachment offsets.
Capture8.JPG (220.16 KiB) Viewed 2122 times
A preferred method is to use the Draft Polar Link Array as shown in this image.  All you need to do is to specify the number of body links and its polar axis.<br /><br />Note that I have customized the Assembly4 toolbar to include the Draft Arrays, Part Mirror, and a macro to toggle transparency (see lefthand side of the main toolbar).  They are quite useful since these are frequently required during assembly.<br /><br />Note also that the Assembly4 toolbar includes a handy Body Mirror that can be used for an assembly Part link and there is an icon for a polar array which is apparently inactive at this time AFAIK.
A preferred method is to use the Draft Polar Link Array as shown in this image. All you need to do is to specify the number of body links and its polar axis.

Note that I have customized the Assembly4 toolbar to include the Draft Arrays, Part Mirror, and a macro to toggle transparency (see lefthand side of the main toolbar). They are quite useful since these are frequently required during assembly.

Note also that the Assembly4 toolbar includes a handy Body Mirror that can be used for an assembly Part link and there is an icon for a polar array which is apparently inactive at this time AFAIK.
Capture9.JPG (215.8 KiB) Viewed 2122 times
If need be, a Part Mirror can also be used in a polar array as this image shows.  However, when the mirror is applied it is kicked out of the Model but can be simply dragged back into it with an out-of-scope warning.<br /><br />In this example, I chose to mirror the fasteners about the same datum plane used to create the bridge body holes then apply the polar array.  The fastener is attached to the Bridge body added Hole Axis which is attached to the sketch circle edge which created the hole feature.  If the bridge hole is moved in the sketch, so do the fasteners to maintain the parametrics.
If need be, a Part Mirror can also be used in a polar array as this image shows. However, when the mirror is applied it is kicked out of the Model but can be simply dragged back into it with an out-of-scope warning.

In this example, I chose to mirror the fasteners about the same datum plane used to create the bridge body holes then apply the polar array. The fastener is attached to the Bridge body added Hole Axis which is attached to the sketch circle edge which created the hole feature. If the bridge hole is moved in the sketch, so do the fasteners to maintain the parametrics.
Capture10.JPG (287.84 KiB) Viewed 2122 times
.
Comments or questions are certainly welcome. A Dropbox file (1.15 Mb) is available on request for anyone wanting to more closely review the modelling and assembly details.

Code: Select all

OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.30143 (Git)
Build type: Release
Branch: master
Hash: a72bf218f9917df37e811d7e73a36333282028f5
Python 3.10.5, Qt 5.15.4, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.2
Locale: English/United States (en_US)
Installed mods: 
  * Assembly4 0.12.3
  * fasteners 0.4.1
  * fcgear 1.0.0
"It is a poor workman who blames his tools..." ;)
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by Zolko »

ppemawm wrote: Thu Sep 08, 2022 5:09 pm Draft Arrays > Polar > Link Arrays
the arrays icon in the toolbar is an array I made because I didn't like how the Draft_Array works. Not one of my best choices.

But, interestingly, based on that failed idea, "Jolbas" is proposing a new type of array: ExpressionArray. The idea behind this is to create a bunch of links to the same object, and to calculate the positions of each object by the ExpressionEngine in the Placement property of each instance. This is what polar or linear arrays do, but it's hard-coded in python. Here it should be coded in "user-space". This should allow regular arrays (circular, linear, spiral ...) but also more exotic ones, based on the user's proficiency in expressions.
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
ppemawm
Veteran
Posts: 1240
Joined: Fri May 17, 2013 3:54 pm
Location: New York NY USA

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by ppemawm »

Zolko wrote: Tue Sep 13, 2022 12:36 pm "Jolbas" is proposing a new type of array: ExpressionArray.
Ah, yes. That will be a welcome addition.
Thanks.
"It is a poor workman who blames his tools..." ;)
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by Jolbas »

Yes. I needed a linear array where every other part was rotated clockwise respectively counter clockwise. And also the amount of parts and spacing was dependent of the length. It was a simple truss with a length variable. And I realized this wasn't possible with a normal linear array. In this stage of the development the Array has properties ElementPlacement and ElementIndex and during recalculate the ElementIndex is increased for each element and the result of ElementPlacement is copied to the element.
The plan is to have a tool for making convenient presets for circular and linear arrays but already with the base implementation it is not very hard to write an expression that create such patterns.

Examples of expressions:

This is what I first used for the truss parts, populating all four sides with diagonals:

Code: Select all

create(<<placement>>; create(<<Vector>>; 0; 0; 50 + Variables.st_height * (floor(ElementIndex / 4) + 0.5)); create(<<rotation>>; 90 * ElementIndex; Variables.st_angle * ((ElementIndex + floor(ElementIndex / 4)) % 2 == 1 ? 1 : -1); 0))
Skärmavbild 2022-09-16 kl. 13.03.07.png
Skärmavbild 2022-09-16 kl. 13.03.07.png (124.87 KiB) Viewed 1861 times
Linear along axis:

Code: Select all

Axis_1.Placement * create(<<placement>>; create(<<vector>>; 50; 0; 0) * ElementIndex; create(<<rotation>>; 0; 0; 0)) * SourceObject.Placement
Skärmavbild 2022-09-16 kl. 13.18.25.png
Skärmavbild 2022-09-16 kl. 13.18.25.png (62.53 KiB) Viewed 1861 times
Polar around axis:

Code: Select all

Axis_1.Placement * create(<<placement>>; create(<<Vector>>; 0; 0; 0); create(<<rotation>>; 360 / ElementCount * ElementIndex; 0; 0)) * .SourceObject.Placement
Skärmavbild 2022-09-16 kl. 13.24.35.png
Skärmavbild 2022-09-16 kl. 13.24.35.png (56.92 KiB) Viewed 1861 times
Spherical pattern:

Code: Select all

create(<<placement>>; create(<<vector>>; 0; 0; 0); create(<<rotation>>; 100 * ElementIndex; 0; asin(2 * ElementIndex / (ElementCount - 1) - 1))) * .SourceObject.Placement
Skärmavbild 2022-09-15 kl. 12.04.51.png
Skärmavbild 2022-09-15 kl. 12.04.51.png (210.05 KiB) Viewed 1861 times
Instead of writing the attachment object in the beginning of the expression it's possible to use the builtin attachment functionality. I can find a separate tool for attachment that works on anything in the Part WB
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by Jolbas »

Played futher with the Expression Array and come up with this cubic pattern expression in the ElementPlacement:

Code: Select all

create(<<placement>>; create(<<vector>>;0;0;0); create(<<rotation>>; create(<<vector>>; -1; 1; 0); floor(ElementIndex % 6 / 3) * 180) * create(<<rotation>>; create(<<vector>>; 1; 1; 1); (2 + ElementIndex) * 120) * create(<<rotation>>; 0; 0; 90 * floor(ElementIndex % 6 / 3)) * create(<<rotation>>; 0; 0; 360 * floor(ElementIndex / 6) / ceil(ElementCount / 6))) * .SourceObject.Placement
While not changing this expression and just playing with ElementCount and placement of the source object I could create all these patterns:

The faces of a cube:
XA cube faces.png
XA cube faces.png (31.44 KiB) Viewed 1770 times
The edges of a cube
XA cube edges.png
XA cube edges.png (52.46 KiB) Viewed 1770 times
The corners of a tetrahedron
XA tetra.png
XA tetra.png (140.99 KiB) Viewed 1770 times
The edges of a rhombicuboctahedron:
XA rhombicuboctahedron edges.png
XA rhombicuboctahedron edges.png (156.92 KiB) Viewed 1770 times
And polar patterns on all sides of a cube:
XA polar on cube.png
XA polar on cube.png (56.43 KiB) Viewed 1770 times
This expression isn't very easy to read and a way to simplify is to use the possibility to add custom properties to the Array and do parts of the calculation there. Its not possible to go through a Spreadsheet because that is treated as an cyclic referense.
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by Jolbas »

I would like some input on how you think of the workflow around the array. @Zolko @ppemawm and others. I think it should be like this:

1. Select a source object.
2. Click an Array button. Polar, Linear, Limitless
3. The array object i created and the task panel opens for attachment of the array object.
4. Select attachment settings and close.
5. Edit array parameters depending of array type.
User avatar
ppemawm
Veteran
Posts: 1240
Joined: Fri May 17, 2013 3:54 pm
Location: New York NY USA

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by ppemawm »

Jolbas wrote: Mon Sep 19, 2022 3:25 pm I would like some input on how you think of the workflow around the array.
I could work with this. But, some questions/comments:

1. Is this specific to Assembly4 workbench?
2. From where do you select the object for the array? External files and the Part folder? A link already placed in the assembly?
3. Will the array object be a link?
4. In lieu of a spreadsheet can we use the Asssembly4 Variables in the Expressions?
5. Will the array object accommodate path link arrays? EDIT: Could it also accommodate mirrors?
6. The array expression is not intuitive except maybe for a programmer. I assume there will be a simple wiki to explain how to create one.

This has some amazing possibilities which takes us well beyond the awkward Draft arrays. Well done.
"It is a poor workman who blames his tools..." ;)
User avatar
Jolbas
Posts: 327
Joined: Sat Mar 26, 2022 7:48 am
Location: Sweden

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by Jolbas »

ppemawm wrote: Mon Sep 19, 2022 4:10 pm 1. Is this specific to Assembly4 workbench?
2. From where do you select the object for the array? External files and the Part folder? A link already placed in the assembly?
3. Will the array object be a link?
4. In lieu of a spreadsheet can we use the Asssembly4 Variables in the Expressions?
5. Will the array object accommodate path link arrays? EDIT: Could it also accommodate mirrors?
6. The array expression is not intuitive except maybe for a programmer. I assume there will be a simple wiki to explain how to create one.

1. I'm not sure. I used Zolkos array as a base for the code but maybe there is a more relevant workbench. It has to do with the workflow.
2. If it's going to be in Assembly 4, then it should maybe be a dialog to choose object from like Variant Link and Import Link.
3. No. You can replace it with a link I suppose.
4. You can certainly use variables and properties from other objects and spreadsheet in the expressions, but you cant calculate expressions where the ElementIndex from the Expression Array is used in any other place than in the Arrays internal properties.
5. There is no support for mirrors in the Placement property which the current implementation relies on. The only thing that I know you kan mirror is a App::Link using the scale property. With some more coding it could probably be added.
6. Yes, that is a good idea.
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by Zolko »

Jolbas wrote: Mon Sep 19, 2022 3:25 pm I would like some input on how you think of the workflow around the array. @Zolko @ppemawm and others. I think it should be like this:

1. Select a source object.
2. Click an Array button. Polar, Linear, Limitless
3. The array object i created and the task panel opens for attachment of the array object.
4. Select attachment settings and close.
5. Edit array parameters depending of array type.
I suggest:

1) select source object
2) this enables ExpressionArray, but not Linear and Circular array
3) optionally, select direction
4) this enables Linear and Circular arrays also
5) choose Linear, Circular or Expression array
6) no need for Task ui
7) edit array parameters directly in the property view
8) for the not-faint-of-heart write their own expression

I'm having a very busy week, I won't be able to update your code but I really would like to have it in there for the next release
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Using V0.21 Draft Link Arrays in Assembly4 V0.12.3

Post by onekk »

Jolbas wrote: Mon Sep 19, 2022 3:25 pm I would like some input on how you think of the workflow around the array. @Zolko @ppemawm and others. I think it should be like this:

1. Select a source object.
2. Click an Array button. Polar, Linear, Limitless
3. The array object i created and the task panel opens for attachment of the array object.
4. Select attachment settings and close.
5. Edit array parameters depending of array type.
Seems to be good.
Only to make some "brainstorming" about different way to make a "flexible tool"

I have in mind what is probably a too "involute" user case and not so applicable in reality.

To pass to the "expression" tool a list of "center point", "axes" and "angle".

Suppose that I have a part, like an arrow and i wat to orient it in a strange way, like distributing them on a sphere with some arrows some pointing upward and some other downward on a the sphere surface, (maybe passing his U.V coordinates).

I have a "center point" that determine the position in 3D space of the "reference point" of the object (Sorry, the terminology is not correct, but I'm used to script things, so GUI is not my "point of strength"), the axis will determine what is the "rotation axis" and the "angle" the position.

This way I could maybe model very complex object with the "overhead" of calculating only the data in my case the U,V coordinates of "center points" and passing the "upward" and "downward" angle the axis could be managed by the U,V position that being on the surface will follow his normal.

Hoping to have been decently clear.

Kind 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/
Post Reply