Parametric, non regular pattern

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
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Parametric, non regular pattern

Post by xryl669 »

Hi,

I've trying to build a object that's like this:

Code: Select all

[ ]
[ ][ ][ ]
It's made of a given number of blocks [ ] that are repeated following a non regular pattern.

I've set up a spreadsheet to define the number of rows & columns (in the example above it's 2 rows, 3 colums).
In the spreadsheet, the user can define if a block is present or not by entering a 1 in the block matrix (so it looks like this:

Code: Select all

Pin pattern below	Column 1	Column 2	Column 3	Column 4	Column 5	Column 6	
Row 1			                                      1					
Row 2	                1	       1	       1					
Row 3								
Row 4								
I'm able to create a regular pattern (using the multi pattern tool) of rows * columns, but I can't iterate the spreadsheet with FreeCAD's tools.
I'm able to compute the used number of blocks (using sum() function) so I can compute a position shift if I pre-iterate the block count but there is no "if" function in the spreadsheet (nor "for") so looping is not really easy.

How can I create the initial shape ?
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric, non regular pattern

Post by edwilliams16 »

If I understand you correctly, Lattice2 workbench with linear arrays driven by a spreadsheet will do what you want:
Screen Shot 2022-05-23 at 8.21.54 AM.png
Screen Shot 2022-05-23 at 8.21.54 AM.png (36.63 KiB) Viewed 1305 times
Screen Shot 2022-05-23 at 8.43.08 AM.png
Screen Shot 2022-05-23 at 8.43.08 AM.png (11.57 KiB) Viewed 1305 times
Attachments
spreadarray.FCStd
(12.82 KiB) Downloaded 13 times
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric, non regular pattern

Post by edwilliams16 »

I was curious to see if creating a selected array of placements was easily scripted. It was:

Code: Select all

import lattice2LinearArray
import lattice2Executer
import lattice2JoinArrays

def make2DPlacementArray(logicalArray, valRow, valCol):
    '''make2DPlacementArray(logicalArray, valRow, valCol)
       generate a 2D array of Placements
       row (x) spacing is valRow
       column (y)  spacing is valCol
       logicalArray is a list of rowLists
       each rowList is a list of Booleans, True where a placement is desired
       the rowLists can have different lengths
    '''
    colDisplacement = 0;
    g = lattice2JoinArrays.makeJoinArrays(name='SelectedArray')
    g.Links = []
    g.MarkerSize = valRow/4
    for row in logicalArray:
        if any(row):
            f = lattice2LinearArray.makeLinearArray(name='LinearArray')
            f. ValuesSource = u"Values Property"
            vals = [str( i * valRow) for i, col in enumerate(row) if col]
            f.Values = vals
            f.Placement.Base.y = colDisplacement
            f.MarkerSize = valRow/4
            f.Visibility = False
            lattice2Executer.executeFeature(f)
            g.Links = g.Links + [f]
        colDisplacement  -= valCol
    lattice2Executer.executeFeature(g)

                
logicalArray = [[True],  [True, True, True], [False], [True, False, True]]
valRow=10
valCol = 10
make2DPlacementArray(logicalArray, valRow, valCol)
creates:
Screen Shot 2022-05-23 at 4.19.13 PM.png
Screen Shot 2022-05-23 at 4.19.13 PM.png (19.47 KiB) Viewed 1238 times
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Re: Parametric, non regular pattern

Post by xryl669 »

Thanks!
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Re: Parametric, non regular pattern

Post by xryl669 »

In fact, when only using the GUI, it's not working that well.
Let's say you have such configuration:

Code: Select all

[ ]  [ ]
   [ ]
[ ]  [ ] 
Then, unless I'm missing something, it's not possible to draw the first line (or column) since there's an empty cell in the middle of the matrix.
It's not possible to reference an empty cell in FreeCAD's spreadsheet (it gives an error instead of returning an empty cell), so as soon as the spreadsheet contains a "hole", you can't specify the pattern anymore.
Typically, the lattice2 array function also expect a distance in the spreadsheet, but we can't make a distance from a (1/empty) matrix, since if I set =E2 * B4, and E2 is empty, it'll break the spreadsheet (and then the array function).
The array function only support unitless numbers (but it's not possible to remove a unit from a cell once it has one).
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric, non regular pattern

Post by edwilliams16 »

xryl669 wrote: Tue May 24, 2022 4:33 pm
The obvious solution is not good enough?
Screen Shot 2022-05-24 at 7.26.14 AM.png
Screen Shot 2022-05-24 at 7.26.14 AM.png (11.28 KiB) Viewed 1056 times
Screen Shot 2022-05-24 at 7.24.23 AM.png
Screen Shot 2022-05-24 at 7.24.23 AM.png (9.95 KiB) Viewed 1056 times
Messier is to use a marker value for the blanks and use the Lattice2|Array Filter to get rid of them:
Screen Shot 2022-05-24 at 7.51.08 AM.png
Screen Shot 2022-05-24 at 7.51.08 AM.png (12.82 KiB) Viewed 1056 times
I didn't follow your issue about units. EDIT You can make a length in mm dimensionless by dividing by 1 mm, if that helps.
Attachments
spreadarray2.FCStd
(20.52 KiB) Downloaded 13 times
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Re: Parametric, non regular pattern

Post by xryl669 »

Thanks!

With your advises, I've made a parametric connector maker based on customizable pin patterns. Hope it'll be useful for DIY community!
edwilliams16
Veteran
Posts: 3106
Joined: Thu Sep 24, 2020 10:31 pm
Location: Hawaii
Contact:

Re: Parametric, non regular pattern

Post by edwilliams16 »

Looks useful. I never seem to have the right connector on hand.
BTW, no need to zip the FCStd file - it is already a zip archive.
xryl669
Posts: 32
Joined: Fri Jul 31, 2020 1:19 pm

Re: Parametric, non regular pattern

Post by xryl669 »

I know. But the blog engine I'm using doesn't like the FCStd extension. :roll:
Post Reply