-
Notifications
You must be signed in to change notification settings - Fork 0
/
HotwingProfile.FCMacro
104 lines (80 loc) · 2.89 KB
/
HotwingProfile.FCMacro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import FreeCAD,Draft
from PySide import QtCore, QtGui
import FreeCAD, Part
import importSVG
import PySide
from PySide import QtGui ,QtCore
import os
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(187, 178)
self.title = QtGui.QLabel(Dialog)
self.title.setGeometry(QtCore.QRect(10, 10, 271, 16))
self.title.setObjectName("title")
self.label_width = QtGui.QLabel(Dialog)
self.label_width.setGeometry(QtCore.QRect(10, 50, 57, 16))
self.label_width.setObjectName("label_width")
self.width = QtGui.QLineEdit(Dialog)
self.width.setGeometry(QtCore.QRect(60, 40, 111, 26))
self.width.setObjectName("width")
self.create = QtGui.QPushButton(Dialog)
self.create.setGeometry(QtCore.QRect(50, 140, 83, 26))
self.create.setObjectName("create")
self.retranslateUi(Dialog)
QtCore.QObject.connect(self.create,QtCore.SIGNAL("pressed()"),self.createPlane)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
Dialog.setWindowTitle("Dialog")
self.title.setText("Hotwing Profile")
self.label_width.setText("Width")
self.width.setText('500')
self.create.setText("Create!")
def createPlane(self):
try:
w = float(self.width.text())
except ValueError:
print("Error! Width value must be valid numbers!")
else:
doc = FreeCAD.ActiveDocument
objs_before = FreeCAD.ActiveDocument.Objects
importSVG.insert(self.filename, doc.Name)
objs_after = FreeCAD.ActiveDocument.Objects
objs = []
for obj in objs_after:
if obj not in objs_before:
objs.append(obj)
obj.Visibility = False
sketches = []
sketches.append(Draft.makeSketch(objs[0]))
sketches.append(Draft.makeSketch(objs[1]))
body = doc.addObject('PartDesign::Body','Body')
body_number = body.Name[4:]
body.addObjects(sketches)
XY = body.getObject('XY_Plane%s' % body_number)
dp = body.newObject('PartDesign::Plane','DatumPlane')
dp.Support = [(XY,'')]
dp.MapMode = 'FlatFace'
dp.AttachmentOffset = App.Placement(App.Vector(0.0000000000, 0.0000000000, w), App.Rotation(0.0000000000, 0.0000000000, 0.0000000000))
dp.MapReversed = False
dp.MapPathParameter = 0.000000
sketches[0].MapMode = "FlatFace"
sketches[0].Support = [(dp,'')]
sketches[1].MapMode = "FlatFace"
sketches[1].Support = [(XY,'')]
loft = body.newObject('PartDesign::AdditiveLoft','AdditiveLoft')
loft.Profile = sketches[0]
loft.Sections += [sketches[1]]
sketches[0].Visibility = False
sketches[1].Visibility = False
dp.Visibility = False
doc.recompute()
class plane():
def __init__(self, filename):
self.d = QtGui.QWidget()
self.ui = Ui_Dialog()
self.ui.setupUi(self.d)
self.ui.filename = filename
self.d.show()
OpenName, Filter = PySide.QtGui.QFileDialog.getOpenFileName(None, "Read a SVG file", os.path.expanduser("~/Downloads"), "*.svg")
p = plane(OpenName)