-
Notifications
You must be signed in to change notification settings - Fork 0
/
EB_Auxiliaries.py
163 lines (138 loc) · 6.19 KB
/
EB_Auxiliaries.py
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from PySide import QtCore, QtGui
import os
import sys
import FreeCADGui
import FreeCAD
#------------------------------------------------------------------------------
def testWithoutEB():
# Test workbench without Ingeneering Base installations
if FreeCAD.testWithOutEB:
return True
else:
return False
# return False
# ------Pathes of Files
# workbenchFolder = os.path.dirname(os.path.realpath(__file__))
# workbenchFolder = FreeCAD.__path__[3] + "\!EBase"
#------------------------------------------------------------------------------
def workbenchFolderPath():
return os.path.dirname(os.path.realpath(__file__))
#------------------------------------------------------------------------------
def fontFilePath():
return workbenchFolderPath() + "\\VBScripts\\arial.ttf"
#------------------------------------------------------------------------------
def scriptGetEBShapePath():
return workbenchFolderPath() + "\\VBScripts\\GetDeviceEB.vbs"
#------------------------------------------------------------------------------
def textEBShapeExportedPath():
return workbenchFolderPath() + "\\VBScripts\\ExportedDeviceEB.txt"
#------------------------------------------------------------------------------
def vbsScriptsPath():
return workbenchFolderPath() + "\\VBScripts"
#------------------------------------------------------------------------------
def scriptSelectShapeInEBPath():
return workbenchFolderPath() + "\\VBScripts\\SelectDeviceInEB.vbs"
#------------------------------------------------------------------------------
def scriptDeletePYCfilesPath():
return workbenchFolderPath() + "\\DeletePYCfiles.vbs"
#------------------------------------------------------------------------------
def IpSettingsPath():
return workbenchFolderPath() + "\\VBScripts\\IpSettings.txt"
#------------------------------------------------------------------------------
def autoItExePath():
return workbenchFolderPath() + "\\VBScripts\\AutoIt3.exe"
#------------------------------------------------------------------------------
def scriptHotKeysPath():
return workbenchFolderPath() + "\\VBScripts\\SendCommandToFreeCAD.au3"
#------------------------------------------------------------------------------
def TerminalBlocksPath():
return workbenchFolderPath() + "\\StepFiles\\" + "TerminalBlocks"
#------------------------------------------------------------------------------
def CableGlandsPath():
return workbenchFolderPath() + "\\StepFiles\\" + "CableGlands"
#------------------------------------------------------------------------------
def RunCommand(fileName):
'''Run in console py-files in folder Commands'''
import FreeCADGui
filePath = workbenchFolderPath() + "\\Commands\\" + fileName
filePath = filePath.replace('\\', '/')
if sys.version_info.major < 3:
command = 'execfile("' + filePath + '")'
else:
# exec(compile(open(file).read(), file, 'exec'))
command = 'exec(compile(open("' + filePath + '", encoding="utf-8").read(),"' + filePath + '", "exec"))'
FreeCADGui.doCommand(command)
#------------------------------------------------------------------------------
def MsgDialog(msg):
# Create a simple dialog QMessageBox
# The first argument indicates the icon used: one of QtGui.QMessageBox.{NoIcon, Information, Warning, Critical, Question}
diag = QtGui.QMessageBox(QtGui.QMessageBox.Warning, "Attention!", msg)
diag.setWindowModality(QtCore.Qt.ApplicationModal)
diag.exec_()
#------------------------------------------------------------------------------
def GetSelectionWithSubObjects():
selList = []
"""recursive function"""
def GetSubelements(groupObj):
children = groupObj.OutList
for c in children:
if not (c.isDerivedFrom('App::DocumentObjectGroup') or c.isDerivedFrom('App::Part')):
selList.append(c)
else:
GetSubelements(c)
"""end recursive function"""
if len(FreeCADGui.Selection.getSelection()) != 0:
selObjects = FreeCADGui.Selection.getSelection()
for o in selObjects:
if not (o.isDerivedFrom('App::DocumentObjectGroup') or o.isDerivedFrom('App::Part')):
selList.append(o)
else:
GetSubelements(o)
return selList
#------------------------------------------------------------------------------
def GetChildrenFromObject(parentObject):
selList = []
"""recursive function"""
def GetSubelements(groupObj):
children = groupObj.OutList
for c in children:
if not (c.isDerivedFrom('App::DocumentObjectGroup') or c.isDerivedFrom('App::Part')):
selList.append(c)
else:
GetSubelements(c)
"""end recursive function"""
if not (parentObject.isDerivedFrom('App::DocumentObjectGroup') or parentObject.isDerivedFrom('App::Part')):
selList.append(parentObject)
else:
GetSubelements(parentObject)
return selList
#------------------------------------------------------------------------------
class SelectionGate(object):
'''To set selection filter - Face, Edge, Vertex
g = SelectionGate("Face")
FreeCADGui.Selection.addSelectionGate(g)
To delete selection filter
FreeCADGui.Selection.removeSelectionGate()'''
def __init__(self, selectFilter):
self.toSelect = selectFilter
def allow(self, doc, obj, sub):
if not obj.isDerivedFrom("Part::Feature"):
return False
if str(sub).startswith(self.toSelect):
return True
return False
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
def DeleteObjectbyLabel(obj):
try:
FreeCAD.getDocument(str(FreeCAD.activeDocument().Name)).removeObject(obj.Label)
except:
pass
#------------------------------------------------------------------------------
def a_clear_console():
'''clearing previous messages in Python console and Report view'''
mw = FreeCADGui.getMainWindow()
c = mw.findChild(QtGui.QPlainTextEdit, "Python console")
c.clear()
r = mw.findChild(QtGui.QTextEdit, "Report view")
r.clear()