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

Create & export parts list

Postby Roland » Wed Sep 09, 2015 2:55 pm

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
Posts: 9475
Joined: Mon Dec 12, 2011 4:45 pm

Re: Create & export parts list

Postby triplus » Thu Sep 10, 2015 11:40 pm

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: 291
Joined: Fri Aug 21, 2015 2:20 pm

Re: Create & export parts list

Postby Roland » Fri Sep 11, 2015 7:53 am

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
Posts: 3475
Joined: Wed May 16, 2012 2:13 pm

Re: Create & export parts list

Postby mario52 » Fri Sep 11, 2015 8:21 am

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, Dialog creation. My macros on Gist.github.
J.Martinsson
Posts: 5
Joined: Sun Nov 10, 2013 10:48 am

Re: Create & export parts list

Postby J.Martinsson » Fri Sep 11, 2015 9:56 am

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

Re: Create & export parts list

Postby triplus » Fri Sep 11, 2015 11:05 pm

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
Posts: 3475
Joined: Wed May 16, 2012 2:13 pm

Re: Create & export parts list

Postby mario52 » Sat Sep 12, 2015 9:03 am

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, Dialog creation. My macros on Gist.github.
User avatar
Roland
Posts: 291
Joined: Fri Aug 21, 2015 2:20 pm

Re: Create & export parts list

Postby Roland » Sat Sep 12, 2015 12:50 pm

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

Re: Create & export parts list

Postby mario52 » Sat Sep 12, 2015 5:01 pm

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, Dialog creation. My macros on Gist.github.
mdk
Posts: 2
Joined: Tue Sep 01, 2020 12:02 pm

Re: Create & export parts list

Postby mdk » Sat Sep 05, 2020 8:29 am

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")])))