FreeCAD-macros

Форк
0
/
apothemBasedPrism.py 
101 строка · 2.8 Кб
1
# # # # # # # # # # #
2
#
3
# Apothem Based Prism
4
#
5
# This script will take the input of the distance between flats, (apothem, aka inradius),
6
# and the number of sidesfor a regular polygon along with a height and produce a
7
# correctly sized prism derived from the circumradius.
8
#
9
# # # # # # # # # # #
10

11
__Name__ = 'Apothem Based Prism'
12
__Comment__ = ''
13
__License__ = ''
14
__Web__ = 'http://www.freecadweb.org/wiki/Macro_Apothem_Based_Prism_GUI'
15
__Wiki__ = 'http://www.freecadweb.org/wiki/Macro_Apothem_Based_Prism_GUI'
16
__Icon__ = ''
17
__Help__ = ''
18
__Author__ = ''
19
__Version__ = ''
20
__Status__ = ''
21
__Requires__ = ''
22
__Files__ = ''
23

24

25
import FreeCAD, FreeCADGui, Part, PartGui, math
26
from FreeCAD import Base
27
from PySide import QtGui, QtCore
28
from math import cos, radians
29
App = FreeCAD
30
Gui = FreeCADGui
31

32
class p():
33

34

35
    def priSm(self):
36

37
        try:
38
            dbf = float(self.d1.text())
39
            nos = int(self.d2.text())
40
            hth = float(self.d3.text())
41
            aR = dbf / 2
42
            op1 = 180/float(nos)
43
            coS = cos(math.radians(op1))
44
            cR = aR / coS
45
            prism=App.ActiveDocument.addObject("Part::Prism","Prism")
46
            prism.Polygon=nos
47
            prism.Circumradius=cR
48
            prism.Height=hth
49
            prism.Placement=Base.Placement(Base.Vector(0.00,0.00,0.00),Base.Rotation(0.00,0.00,0.00,1.00))
50
            prism.Label='Prism'
51
            App.ActiveDocument.recompute()
52
            Gui.SendMsgToActiveView("ViewFit")
53
        except:
54
            FreeCAD.Console.PrintError("Unable to complete task")
55

56
            self.close()
57

58
    def close(self):
59
        self.dialog.hide()
60

61

62
#
63
# Make dialog box and get input for distance between flats, number of sides, and height
64
#
65

66
    def __init__(self):
67
        self.dialog = None
68

69
        self.dialog = QtGui.QDialog()
70
        self.dialog.resize(280,110)
71

72
        self.dialog.setWindowTitle("Apothem Based Prism")
73
        la = QtGui.QVBoxLayout(self.dialog)
74

75
        iN1 = QtGui.QLabel("Distance Between Flats")
76
        la.addWidget(iN1)
77
        self.d1 = QtGui.QLineEdit()
78
        la.addWidget(self.d1)
79

80
        iN2 = QtGui.QLabel("Number Of Sides (Best results - use even numbers)")
81
        la.addWidget(iN2)
82
        self.d2 = QtGui.QLineEdit()
83
        la.addWidget(self.d2)
84

85
        iN3 = QtGui.QLabel("Prism Height")
86
        la.addWidget(iN3)
87
        self.d3 = QtGui.QLineEdit()
88
        la.addWidget(self.d3)
89

90
        okbox = QtGui.QDialogButtonBox(self.dialog)
91
        okbox.setOrientation(QtCore.Qt.Horizontal)
92
        okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
93
        la.addWidget(okbox)
94
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.priSm)
95
        QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
96
        QtCore.QMetaObject.connectSlotsByName(self.dialog)
97
        self.dialog.show()
98
        self.dialog.exec_()
99

100

101
p()
102

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

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

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

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