Move functions to UtilFunctions.py.

This commit is contained in:
Paddle
2023-09-04 18:31:29 +02:00
parent 5a2b2304f9
commit c0185ad95c
3 changed files with 61 additions and 26 deletions

View File

@@ -11,6 +11,7 @@ set(Assembly_Scripts
TestAssemblyWorkbench.py
Preferences.py
AssemblyImport.py
UtilsAssembly.py
)
if(BUILD_GUI)

View File

@@ -30,6 +30,7 @@ if App.GuiUp:
import FreeCADGui as Gui
from PySide import QtCore, QtGui, QtWidgets
import UtilsAssembly
# translate = App.Qt.translate
__title__ = "Assembly Command Insert Link"
@@ -37,29 +38,6 @@ __author__ = "Ondsel"
__url__ = "https://www.freecad.org"
def activeAssembly():
doc = Gui.ActiveDocument
if doc is None or doc.ActiveView is None:
return None
active_part = doc.ActiveView.getActiveObject("part")
if active_part is not None and active_part.Type == "Assembly":
return active_part
return None
def isDocTemporary(doc):
# Guard against older versions of FreeCad which don't have the Temporary attribute
try:
docTemporary = doc.Temporary
except AttributeError:
docTemporary = False
return docTemporary
class CommandInsertLink:
def __init__(self):
pass
@@ -80,10 +58,10 @@ class CommandInsertLink:
}
def IsActive(self):
return activeAssembly() is not None
return UtilsAssembly.activeAssembly() is not None
def Activated(self):
assembly = activeAssembly()
assembly = UtilsAssembly.activeAssembly()
if not assembly:
return
view = Gui.activeDocument().activeView()
@@ -139,7 +117,7 @@ class TaskAssemblyInsertLink(QtCore.QObject):
docList = App.listDocuments().values()
for doc in docList:
if isDocTemporary(doc):
if UtilsAssembly.isDocTemporary(doc):
continue
for obj in doc.findObjects("App::Part"):

View File

@@ -0,0 +1,56 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
# /****************************************************************************
# *
# Copyright (c) 2023 Ondsel <development@ondsel.com> *
# *
# This file is part of FreeCAD. *
# *
# FreeCAD is free software: you can redistribute it and/or modify it *
# under the terms of the GNU Lesser General Public License as *
# published by the Free Software Foundation, either version 2.1 of the *
# License, or (at your option) any later version. *
# *
# FreeCAD is distributed in the hope that it will be useful, but *
# WITHOUT ANY WARRANTY; without even the implied warranty of *
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
# Lesser General Public License for more details. *
# *
# You should have received a copy of the GNU Lesser General Public *
# License along with FreeCAD. If not, see *
# <https://www.gnu.org/licenses/>. *
# *
# ***************************************************************************/
import FreeCAD as App
if App.GuiUp:
import FreeCADGui as Gui
# translate = App.Qt.translate
__title__ = "Assembly utilitary functions"
__author__ = "Ondsel"
__url__ = "https://www.freecad.org"
def activeAssembly():
doc = Gui.ActiveDocument
if doc is None or doc.ActiveView is None:
return None
active_part = doc.ActiveView.getActiveObject("part")
if active_part is not None and active_part.Type == "Assembly":
return active_part
return None
def isDocTemporary(doc):
# Guard against older versions of FreeCad which don't have the Temporary attribute
try:
temp = doc.Temporary
except AttributeError:
temp = False
return temp