Asm4: BOM functionality prototyping

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
alex_55
Posts: 63
Joined: Mon May 11, 2020 1:50 am

Asm4: BOM functionality prototyping

Post by alex_55 »

In another thread a few months ago, Zolko suggested that BOM creation functionality would be a good place to do some hacking on the Asm4 workbench. I've had some time to prototype an implementation, and I'd like feedback/suggestions for further features.

Here's what I have so far:
Assembly4 currently has a GUI command to assign metadata to parts using properties, that get stored under the 'PartInfo' group. The command is only partially implemented, so I did some work it to make it more usable

Image

note that in the above screenshot, only one of the properties is able to be deleted. I've added a new property to the 'Parameters' group of the Model object, that enforces some required Metadata fields.

Image

this list of field can be blanked out to give the user complete free-form control over the metadata that is added to parts.
Now, on to the actual BOM creation bit

I put the code in a seperate file (makeBomSheetCmd.py) for now, as it seemed like a better choice than appending to the existing makeBomCmd.py, which functions very differently to my code.

As the name implies, this command creates a standard FreeCAD spreadsheet. Here's an example of what it produces:
Image

Note the rightmost column, misc. info. The best part about this prototype is that it builds the spreadsheet based on the metadata that is actually available in the parts of the assembly, as opposed to just filling in a predetermined set of fields

Code: Select all

    # properties that have assigned values for most of the parts (we set an 
    # arbitrary minimum of 50% for now) will get their own column in the
    # spreadsheet. properties that are only assigned to a few of the parts get
    # compressed into a single column at the end
    # at least X% of parts must have a property for it to get its own BOM column
    minDataCommonality = 0.5 
    keydump = [i for sl in list(map(lambda x: x.keys(),datablock)) for i in sl]
    keysCount = collections.Counter(keydump)
    commonKeys = []
    for key,ct in keysCount.items():
      if ct/len(PartsCount) >= minDataCommonality:
        commonKeys.append(key)
    commonKeys.sort(key=sortf)
    sheetdata.append(commonKeys+["Misc. Info"])
    for pdct in datablock:
      row = [""]*len(sheetdata[1])
      misc = ""
      for key,val in pdct.items():
        if key  not in commonKeys:
          misc += f"{key}: {val}, "
        else:
          for i,x in enumerate(commonKeys):
            if key == x:
              row[i] = val # this whole block is hacky ATM. fix it!
      row[-1] = misc
      
Fields that exist in a set ratio of parts get their own column, while fields that are only set in a few parts get compacted into one cell. This way, you don't have to worry about your spreadsheet becoming many columns wide if you assign some specific fields to only a couple parts.

Some more notes:
  • The spreadsheet is automatically placed in a 'Metadata' group, which works like the 'Parts' group that parts of the Asm4 model are placed in by default. For now, I just wanted a more organized feeling place to put the spreadsheet.
  • My fork of the repo also has a prototype of a command that auto-generates a techdraw drawing of the entire assembly. I'm sort of thinking ahead to a point where we have the tools to generate multiple 'metadata' things about a model, such as dwgs, BOM, materials cut-lists, etc.
  • further functionality to generate a fasteners list is already planned. Should be just a simplified subset of the already developed BOM code
At this point, I am looking for general feedback and ideas as to what community members would like to see in Asm4 BOM functionality. If you have suggestions or examples of nicely formatted BOM sheets I can take style inspiration from, send a reply. You can test out the code if you like, though it's still rough around the edges:
https://github.com/alexneufeld/FreeCAD_ ... evelopment
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Asm4: BOM functionality prototyping

Post by Zolko »

alex_55 wrote: Sun Jan 24, 2021 6:17 am At this point, I am looking for general feedback and ideas as to what community members would like to see in Asm4 BOM functionality.
This is great news, I'll check it out ASAP.

Although I must admit that I don't work with BoMs so much, therefore other people's opinion might be more valuable
try the Assembly4 workbench for FreCAD — tutorials here and here
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Asm4: BOM functionality prototyping

Post by Kunda1 »

Haven't tested it but this i great news!
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
hermanvh
Posts: 9
Joined: Tue Jan 05, 2021 9:35 pm

Re: Asm4: BOM functionality prototyping

Post by hermanvh »

I like the BOM addition to A4 WB and would like to test it, do I need to install all files or just a few of them?

I am also looking for a Cutlist where the maximum sizes (lenght, height and width) per part are listed and how many parts of that size.
The sizes need to be sorted (biggest size 1st, etc.).
And sorted per material type, say ply wood, oak etc.

The cut list will be exported to cut list optimizer e.g. for sawing wood panels.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Asm4: BOM functionality prototyping

Post by Kunda1 »

@alex_55 do you mind rebasing?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
alex_55
Posts: 63
Joined: Mon May 11, 2020 1:50 am

Re: Asm4: BOM functionality prototyping

Post by alex_55 »

Kunda1 wrote: Mon Feb 15, 2021 8:52 pm
@alex_55 do you mind rebasing?
I rebased to new branch with a name that indicates its function. commited some more code as well. I want to get the UI for InfoPartCmd running nicer, but will hopefully have a pull request ready within the week.

Fasteners BOM is working:
Image
hermanvh wrote: Mon Feb 15, 2021 7:11 pm I like the BOM addition to A4 WB and would like to test it, do I need to install all files or just a few of them?

I am also looking for a Cutlist where the maximum sizes (lenght, height and width) per part are listed and how many parts of that size.
The sizes need to be sorted (biggest size 1st, etc.).
And sorted per material type, say ply wood, oak etc.

The cut list will be exported to cut list optimizer e.g. for sawing wood panels.
I think I can get some of the functionality you described working: We could pull, for example, the length of a cut part into that part's PartInfo using an expression, something like "=Pad.Length", where Pad is a partDesign feature of the part in question. The BOM maker already counts duplicate parts. If you want to test out what I have done so far, dowload this branch https://github.com/alexneufeld/FreeCAD_ ... preadsheet to the Mod directory of your FreeCAD install. Detailed instructions in the 'Manual Install' section of this wiki page: https://wiki.freecadweb.org/How_to_inst ... orkbenches
User avatar
Zolko
Veteran
Posts: 2213
Joined: Mon Dec 17, 2018 10:02 am

Re: Asm4: BOM functionality prototyping

Post by Zolko »

alex_55 wrote: Tue Feb 16, 2021 5:42 am
Kunda1 wrote: Mon Feb 15, 2021 8:52 pm @alex_55 do you mind rebasing?
I rebased to new branch with a name that indicates its function. commited some more code as well. I want to get the UI for InfoPartCmd running nicer, but will hopefully have a pull request ready within the week.
I have computer problems right now, I can't test very much. Therefore, if you make a PR to the Asm4 development branch I'll merge it as-is. This BOM functionality has been requested many times, it would be really great to have it. Thank-you
try the Assembly4 workbench for FreCAD — tutorials here and here
hermanvh
Posts: 9
Joined: Tue Jan 05, 2021 9:35 pm

Re: Asm4: BOM functionality prototyping

Post by hermanvh »

Alex,

I installed the modified workbench and below is what I found.
The edit part produced an error and I did check what went wrong, see 3rd screen.
The BOM worked after I commented out 2 statements at the end, see attachment of makePartsBOMsheetCmd.py and 2nd screen.
The BOM does not add the same parts to one row with the right quantity yet.
I modified the BOM sheet to produce a 1st version of a Cut list, see 1st screen, works fine with the same restrictions as the BOM.

Hope this helps.
Attachments
makeCutSheetCmd.py
(6.54 KiB) Downloaded 59 times
makeBomSheetCmd.py
(9.15 KiB) Downloaded 52 times
2021-02-16 20_01_36-Window.png
2021-02-16 20_01_36-Window.png (135.97 KiB) Viewed 2920 times
2021-02-16 20_01_18-Window.png
2021-02-16 20_01_18-Window.png (93.96 KiB) Viewed 2920 times
2021-02-16 20_03_40-Window.png
2021-02-16 20_03_40-Window.png (118.17 KiB) Viewed 2920 times
hermanvh
Posts: 9
Joined: Tue Jan 05, 2021 9:35 pm

Re: Asm4: BOM functionality prototyping

Post by hermanvh »

Alex,

Just found out that infoPart did not work because I used an existing A4 model, where the RequiredPartMetaData doen not exist.
It would be nice when the software can handle that case.

Herman
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Asm4: BOM functionality prototyping

Post by Kunda1 »

hermanvh wrote: Wed Feb 17, 2021 4:56 pm Alex,

Just found out that infoPart did not work because I used an existing A4 model, where the RequiredPartMetaData doen not exist.
It would be nice when the software can handle that case.

Herman
Unless someone responds here, open a ticket on https://github.com/Zolko-123/FreeCAD_Assembly4/issues
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
Post Reply