FreeCAD-macros

Форк
0
/
FabricationCutlist.FCMacro 
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

28
import FreeCAD as app
29

30
doc = app.activeDocument()
31
if doc:
32
    objects = doc.Objects
33
    warnings = []
34

35
    app.Console.PrintMessage('------- CSV Cutlist Begins -------\n')
36

37
    for obj in objects:
38
        label = obj.Label
39
        label2 = obj.Label2
40

41
        if (obj.TypeId == 'Part::Cylinder') and label2:
42
            diameter = obj.Radius.Value * 2
43
            length = obj.Height.Value
44
            app.Console.PrintMessage(
45
                    f', {label}, {label2}, {diameter}, , {length}\n')
46
        elif obj.TypeId == 'Part::Cylinder':
47
            warnings.append(
48
                    f'"{label}" not used, it is a Part::Cylinder object but has no Label2\n')
49
        elif (obj.TypeId == 'Part::Box') and label2:
50
            size = [obj.Length.Value, obj.Width.Value, obj.Height.Value]
51
            size.sort()
52
            app.Console.PrintMessage(
53
                    f', {label}, {label2}, {size[0]}, {size[1]}, {size[2]}\n')
54
        elif obj.TypeId == 'Part::Box':
55
            warnings.append(
56
                    f'"{label}" not used, it is a Part::Box object but has no Label2\n')
57
        else:
58
            warnings.append(
59
                    f'"{label}" not used, only considering Box and Cylinder objects\n')
60

61
    app.Console.PrintMessage('======= CSV Cutlist Completed =======\n')
62

63
    for w in warnings:
64
        app.Console.PrintWarning(w)
65

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.