FreeCAD-macros
/
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
25import FreeCAD, FreeCADGui, Part, PartGui, math
26from FreeCAD import Base
27from PySide import QtGui, QtCore
28from math import cos, radians
29App = FreeCAD
30Gui = FreeCADGui
31
32class p():
33
34
35def priSm(self):
36
37try:
38dbf = float(self.d1.text())
39nos = int(self.d2.text())
40hth = float(self.d3.text())
41aR = dbf / 2
42op1 = 180/float(nos)
43coS = cos(math.radians(op1))
44cR = aR / coS
45prism=App.ActiveDocument.addObject("Part::Prism","Prism")
46prism.Polygon=nos
47prism.Circumradius=cR
48prism.Height=hth
49prism.Placement=Base.Placement(Base.Vector(0.00,0.00,0.00),Base.Rotation(0.00,0.00,0.00,1.00))
50prism.Label='Prism'
51App.ActiveDocument.recompute()
52Gui.SendMsgToActiveView("ViewFit")
53except:
54FreeCAD.Console.PrintError("Unable to complete task")
55
56self.close()
57
58def close(self):
59self.dialog.hide()
60
61
62#
63# Make dialog box and get input for distance between flats, number of sides, and height
64#
65
66def __init__(self):
67self.dialog = None
68
69self.dialog = QtGui.QDialog()
70self.dialog.resize(280,110)
71
72self.dialog.setWindowTitle("Apothem Based Prism")
73la = QtGui.QVBoxLayout(self.dialog)
74
75iN1 = QtGui.QLabel("Distance Between Flats")
76la.addWidget(iN1)
77self.d1 = QtGui.QLineEdit()
78la.addWidget(self.d1)
79
80iN2 = QtGui.QLabel("Number Of Sides (Best results - use even numbers)")
81la.addWidget(iN2)
82self.d2 = QtGui.QLineEdit()
83la.addWidget(self.d2)
84
85iN3 = QtGui.QLabel("Prism Height")
86la.addWidget(iN3)
87self.d3 = QtGui.QLineEdit()
88la.addWidget(self.d3)
89
90okbox = QtGui.QDialogButtonBox(self.dialog)
91okbox.setOrientation(QtCore.Qt.Horizontal)
92okbox.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok)
93la.addWidget(okbox)
94QtCore.QObject.connect(okbox, QtCore.SIGNAL("accepted()"), self.priSm)
95QtCore.QObject.connect(okbox, QtCore.SIGNAL("rejected()"), self.close)
96QtCore.QMetaObject.connectSlotsByName(self.dialog)
97self.dialog.show()
98self.dialog.exec_()
99
100
101p()
102