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
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.
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:
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
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
https://github.com/alexneufeld/FreeCAD_ ... evelopment