FreeCAD
64 строки · 3.6 Кб
1# ***************************************************************************
2# * Copyright (c) 2014 Juergen Riegel <FreeCAD@juergen-riegel.net> *
3# * *
4# * This program is free software; you can redistribute it and/or modify *
5# * it under the terms of the GNU Lesser General Public License (LGPL) *
6# * as published by the Free Software Foundation; either version 2 of *
7# * the License, or (at your option) any later version. *
8# * for detail see the LICENCE text file. *
9# * *
10# * This program is distributed in the hope that it will be useful, *
11# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13# * GNU Library General Public License for more details. *
14# * *
15# * You should have received a copy of the GNU Library General Public *
16# * License along with this program; if not, write to the Free Software *
17# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
18# * USA *
19# * *
20# ***************************************************************************
21
22import FreeCAD, FreeCADGui, Sketcher, Part
23
24
25__title__ = "Hexagon profile lib"
26__author__ = "Juergen Riegel"
27__url__ = "https://www.freecad.org"
28
29App = FreeCAD
30Gui = FreeCADGui
31
32
33def makeHexagonSimple(sketchName=None):
34if not sketchName:
35sketch = App.ActiveDocument.addObject("Sketcher::SketchObject", "Hexagon")
36else:
37sketch = App.ActiveDocument.getObject(sketchName)
38
39geoList = []
40geoList.append(Part.LineSegment(App.Vector(-20.00, 34.64, 0), App.Vector(20.00, 34.64, 0)))
41geoList.append(Part.LineSegment(App.Vector(20.00, 34.64, 0), App.Vector(47.082363, 0.00, 0)))
42geoList.append(Part.LineSegment(App.Vector(40.00, 0.00, 0), App.Vector(20.00, -34.64, 0)))
43geoList.append(Part.LineSegment(App.Vector(20.00, -34.64, 0), App.Vector(-20.00, -34.64, 0)))
44geoList.append(Part.LineSegment(App.Vector(-20.00, -34.64, 0), App.Vector(-40.00, 0.00, 0)))
45geoList.append(Part.LineSegment(App.Vector(-40.00, 0.00, 0), App.Vector(-20.00, 34.64, 0)))
46(l1, l2, l3, l4, l5, l6) = sketch.addGeometry(geoList)
47
48conList = []
49conList.append(Sketcher.Constraint("Coincident", l1, 2, l2, 1))
50conList.append(Sketcher.Constraint("Coincident", l2, 2, l3, 1))
51conList.append(Sketcher.Constraint("Coincident", l3, 2, l4, 1))
52conList.append(Sketcher.Constraint("Coincident", l4, 2, l5, 1))
53conList.append(Sketcher.Constraint("Coincident", l5, 2, l6, 1))
54conList.append(Sketcher.Constraint("Coincident", l6, 2, l1, 1))
55conList.append(Sketcher.Constraint("Equal", l1, l2))
56conList.append(Sketcher.Constraint("Equal", l2, l3))
57conList.append(Sketcher.Constraint("Equal", l3, l4))
58conList.append(Sketcher.Constraint("Equal", l4, l5))
59conList.append(Sketcher.Constraint("Equal", l5, l6))
60conList.append(Sketcher.Constraint("Angle", l1, 2, l2, 1, App.Units.Quantity("120.000000 deg")))
61conList.append(Sketcher.Constraint("Angle", l3, 2, l4, 1, App.Units.Quantity("120.000000 deg")))
62conList.append(Sketcher.Constraint("Angle", l5, 2, l6, 1, App.Units.Quantity("120.000000 deg")))
63sketch.addConstraint(conList)
64return
65