[TD] Extended utility tools

This commit is contained in:
edi271
2023-12-05 11:04:20 +01:00
committed by WandererFan
parent d75e7fbcf3
commit 7f17eaaec9
2 changed files with 57 additions and 0 deletions

View File

@@ -21,6 +21,10 @@
"""Provides utility functions for TD Tools."""
import FreeCAD as App
import FreeCADGui as Gui
from PySide.QtCore import QT_TRANSLATE_NOOP
from PySide import QtGui
from PySide.QtGui import QMessageBox
def havePage():
objs = App.ActiveDocument.Objects
@@ -36,3 +40,54 @@ def haveView():
return True
return False
def displayMessage(title,message):
'''
displayMessage('Title','Messagetext')
'''
msgBox = QtGui.QMessageBox()
msgBox.setText(message)
msgBox.setWindowTitle(title)
msgBox.exec_()
def getSelView():
'''
view = getSelView()
Return selected view, otherwise return False
'''
if not Gui.Selection.getSelection():
displayMessage('TechDraw_Utils','No view selected')
else:
view = Gui.Selection.getSelection()[0]
return view
def getSelVertexes(nVertex=1):
'''
vertexes = getSelVertexes(nVertex)
nVertex ... min. number of selected vertexes
Return a list of selected vertexes if at least nVertex vertexes are selected, otherwise return False
'''
if getSelView():
view = getSelView()
else:
return False
if not Gui.Selection.getSelectionEx():
displayMessage('TechDraw_Utils',
QT_TRANSLATE_NOOP('TechDraw_Utils','No vertex selected'))
return False
objectList = Gui.Selection.getSelectionEx()[0].SubElementNames
vertexes = []
for objectString in objectList:
if objectString[0:6] == 'Vertex':
vertexes.append(view.getVertexBySelection(objectString))
if (len(vertexes) < nVertex):
displayMessage('TechDraw_Utils',
QT_TRANSLATE_NOOP('TechDraw_Utils','Select at least ')+
str(nVertex)+
QT_TRANSLATE_NOOP('TechDraw_Utils',' vertexes'))
return False
else:
return vertexes