FreeCAD-macros
64 строки · 2.9 Кб
1# This macro aims to make it easy to create an accurate cutlist when you are going to fabricate something made out of rectangles and round bar.
2# For example, if you're welding together a gate from commercial mild steel, you are probably using square tubing, round bar and / or angle iron.
3# For all of these you can use Part WB's *Box* and *Cylinder* types.
4# Having done so, this macro will create a comma-separated set of values that make up your cutlist. The collumns are as follows:
5# Timestamp: Just throw this away
6# Label: The label you gave the part. Perhaps use this to indicate the role of the part in your design.
7# Label2: The secondary label you gave the part. Perhaps use this to indicate the profile ("roundbar", "squaretube" etc)
8# Dim1: For round bar, this is the diameter. For box shapes, this is one dimension of the profile size.
9# Dim2: For round bar, this is blank. For box shapes this is the other dimension of the profile size.
10# Length: How long this piece is.
11
12__Name__ = 'Fabrication Cutlist Maker'
13__Comment__ = 'For designs made of Part WB Box and Cylinder primitives, creates a CSV cutlist.'
14__Author__ = 'Johan Pretorius'
15__Date__ = '2024-08-28'
16__Version__ = '2024.8.10'
17__License__ = 'AAL'
18__Web__ = 'https://github.com/FreeCAD/FreeCAD-macros'
19__Wiki__ = ''
20__Icon__ = 'FabricationCutlist.png'
21__Xpm__ = ''
22__Help__ = 'Make your design out of "Box" and "Cylinder" primitives in Part WB. Then run the macro to get a cutlist in the Report View.'
23__Status__ = 'Stable'
24__Requires__ = 'https://github.com/FreeCAD/FreeCAD-macros/issues/'
25__Communication__ = ''
26__Files__ = ''
27
28import FreeCAD as app
29
30doc = app.activeDocument()
31if doc:
32objects = doc.Objects
33warnings = []
34
35app.Console.PrintMessage('------- CSV Cutlist Begins -------\n')
36
37for obj in objects:
38label = obj.Label
39label2 = obj.Label2
40
41if (obj.TypeId == 'Part::Cylinder') and label2:
42diameter = obj.Radius.Value * 2
43length = obj.Height.Value
44app.Console.PrintMessage(
45f', {label}, {label2}, {diameter}, , {length}\n')
46elif obj.TypeId == 'Part::Cylinder':
47warnings.append(
48f'"{label}" not used, it is a Part::Cylinder object but has no Label2\n')
49elif (obj.TypeId == 'Part::Box') and label2:
50size = [obj.Length.Value, obj.Width.Value, obj.Height.Value]
51size.sort()
52app.Console.PrintMessage(
53f', {label}, {label2}, {size[0]}, {size[1]}, {size[2]}\n')
54elif obj.TypeId == 'Part::Box':
55warnings.append(
56f'"{label}" not used, it is a Part::Box object but has no Label2\n')
57else:
58warnings.append(
59f'"{label}" not used, only considering Box and Cylinder objects\n')
60
61app.Console.PrintMessage('======= CSV Cutlist Completed =======\n')
62
63for w in warnings:
64app.Console.PrintWarning(w)
65