From 36726d534454b8d4735786ced4a994eb35ca90db Mon Sep 17 00:00:00 2001 From: Jeremy Mack Wright Date: Sat, 15 Apr 2017 14:48:22 -0400 Subject: [PATCH] Fixed a bug where Helpers.show could not be called more than once, and one that kept macros from being used instead of script editor tabs. --- CadQuery/Gui/Command.py | 3 +++ CadQuery/Helpers.py | 32 +++++++++++++++----------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CadQuery/Gui/Command.py b/CadQuery/Gui/Command.py index d0ef171..fd47ea3 100644 --- a/CadQuery/Gui/Command.py +++ b/CadQuery/Gui/Command.py @@ -119,6 +119,9 @@ class CadQueryExecuteScript: # Grab our code editor so we can interact with it cqCodePane = Shared.getActiveCodePane() + # Clear the old render before re-rendering + Shared.clearActiveDocument() + # Save our code to a tempfile and render it tempFile = tempfile.NamedTemporaryFile(delete=False) tempFile.write(cqCodePane.toPlainText().encode('utf-8')) diff --git a/CadQuery/Helpers.py b/CadQuery/Helpers.py index bc8490b..f396035 100644 --- a/CadQuery/Helpers.py +++ b/CadQuery/Helpers.py @@ -15,26 +15,24 @@ def show(cqObject, rgba=(204, 204, 204, 0.0)): # Grab our code editor so we can interact with it cqCodePane = Shared.getActiveCodePane() - # Clear the old render before re-rendering - Shared.clearActiveDocument() + if cqCodePane != None: + # Save our code to a tempfile and render it + tempFile = tempfile.NamedTemporaryFile(delete=False) + tempFile.write(cqCodePane.toPlainText().encode('utf-8')) + tempFile.close() - # Save our code to a tempfile and render it - tempFile = tempfile.NamedTemporaryFile(delete=False) - tempFile.write(cqCodePane.toPlainText().encode('utf-8')) - tempFile.close() + docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0] - docname = os.path.splitext(os.path.basename(cqCodePane.file.path))[0] + # Make sure we replace any troublesome characters + for ch in ['&', '#', '.', '-', '$', '%', ',', ' ']: + if ch in docname: + docname = docname.replace(ch, "") - # Make sure we replace any troublesome characters - for ch in ['&', '#', '.', '-', '$', '%', ',', ' ']: - if ch in docname: - docname = docname.replace(ch, "") - - # If the matching 3D view has been closed, we need to open a new one - try: - FreeCAD.getDocument(docname) - except: - FreeCAD.newDocument(docname) + # If the matching 3D view has been closed, we need to open a new one + try: + FreeCAD.getDocument(docname) + except: + FreeCAD.newDocument(docname) ad = FreeCAD.activeDocument()