Create & export parts list

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
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Create & export parts list

Post by Roland »

I found a Parts List inside the Assembly 2 WB. (I assume that is the only functional Assembly WB so far).

The Parts List tool of the Assembly 2 WB projects such a list on a drawing.
Now I need to export that list to a spreadsheet for further elaborations.

I accessed the XML codes by unzipping the FStd files, but unfortunately could not find the Parts List as a coherent block of text.

Could somebody advise me an effective procedure for this task?

Thanks :!:

Roland
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.4671 (Git)
Branch: releases/FreeCAD-0-15
Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Create & export parts list

Post by triplus »

Roland wrote:I found a Parts List inside the Assembly 2 WB. (I assume that is the only functional Assembly WB so far).

The Parts List tool of the Assembly 2 WB projects such a list on a drawing.
Now I need to export that list to a spreadsheet for further elaborations.

I accessed the XML codes by unzipping the FStd files, but unfortunately could not find the Parts List as a coherent block of text.

Could somebody advise me an effective procedure for this task?

Thanks :!:

Roland
OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.15.4671 (Git)
Branch: releases/FreeCAD-0-15
Hash: 244b3aef360841646cbfe80a1b225c8b39c8380c
Python version: 2.7.8
Qt version: 4.8.6
Coin version: 4.0.0a
OCC version: 6.8.0.oce-0.17
You will find the information stored in SVG files. Therefore you would need to code SVG parser/extractor of the data you are after or you could make feature request on Assembly2 module issue tracker to provide CSV BOM export capabilities.

For fun i made macro that reads labels of selected objects and puts them in the spreadsheet. Spreadsheet WB has CSV export capabilities.

Code: Select all

obj = FreeCADGui.Selection.getSelection()

bom = App.activeDocument().addObject('Spreadsheet::Sheet','BOM')
cell = 0
for x in obj:
    cell = cell + 1
    bom.set("A" + str(cell), x.Label)

App.ActiveDocument.recompute()
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Re: Create & export parts list

Post by Roland »

Dear Triplus.

Thanks for advice. Yr macro works also at my system. It could be a start, because from there I can make spreadsheet count parts and create a list.

Stupid question perhaps: You wrote: "BOM export capabilities". What is BOM? I also tried your macro using BAM in stead of BOM, and works perfect :!:
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Create & export parts list

Post by mario52 »

hi
try this macro Macro_FCInfo
Save alls info of object selected in a file in CSV format
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
J.Martinsson
Posts: 5
Joined: Sun Nov 10, 2013 10:48 am

Re: Create & export parts list

Post by J.Martinsson »

BOM, in this case means Bill Of Materials.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Create & export parts list

Post by triplus »

Roland wrote:Dear Triplus.

Thanks for advice. Yr macro works also at my system. It could be a start, because from there I can make spreadsheet count parts and create a list.

Stupid question perhaps: You wrote: "BOM export capabilities". What is BOM? I also tried your macro using BAM in stead of BOM, and works perfect :!:
Yes as @J.Martinsson explained but you can give the spreadsheet any name.
mario52 wrote:hi
try this macro Macro_FCInfo
Save alls info of object selected in a file in CSV format
mario
Nice macro.
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Create & export parts list

Post by mario52 »

hi
triplus wrote:Nice macro.
thanks if I have time I will extend PDF
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
User avatar
Roland
Posts: 333
Joined: Fri Aug 21, 2015 2:20 pm

Re: Create & export parts list

Post by Roland »

Nice macro, Mario,
Not making a parts list of an assembly though.
Never mi
Greetz
mario52
Veteran
Posts: 4673
Joined: Wed May 16, 2012 2:13 pm

Re: Create & export parts list

Post by mario52 »

hi
no this macro works with one selected object
but you can create a Compound save the data file and delete the Compound to return to normal
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
mdk
Posts: 2
Joined: Tue Sep 01, 2020 12:02 pm

Re: Create & export parts list

Post by mdk »

Working with wood I had to export a part list (to later build a cut list), so I needed label, width, length, height, this is doable in the Python console using:

Code: Select all

print("\n".join("{}: {} × {} × {}".format(o.Label, o.Height, o.Length, o.Width) for o in App.ActiveDocument.Objects if all([hasattr(o, attr) for attr in ("Height", "Width", "Length", "Label")])))
Post Reply