Removed the assumption that every script would have an accompanying 3D view.

This commit is contained in:
Jeremy Mack Wright 2016-10-20 00:43:59 -04:00
parent 3d3f640dae
commit 93e6c95de6
2 changed files with 39 additions and 16 deletions

View File

@ -120,25 +120,25 @@ class CadQueryExecuteScript:
cqCodePane = Shared.getActiveCodePane() cqCodePane = Shared.getActiveCodePane()
# Clear the old render before re-rendering # Clear the old render before re-rendering
Shared.clearActiveDocument() # Shared.clearActiveDocument()
# Save our code to a tempfile and render it # Save our code to a tempfile and render it
tempFile = tempfile.NamedTemporaryFile(delete=False) tempFile = tempfile.NamedTemporaryFile(delete=False)
tempFile.write(cqCodePane.toPlainText().encode('utf-8')) tempFile.write(cqCodePane.toPlainText().encode('utf-8'))
tempFile.close() 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 # # Make sure we replace any troublesome characters
for ch in ['&', '#', '.', '-', '$', '%', ',', ' ']: # for ch in ['&', '#', '.', '-', '$', '%', ',', ' ']:
if ch in docname: # if ch in docname:
docname = docname.replace(ch, "") # docname = docname.replace(ch, "")
#
# If the matching 3D view has been closed, we need to open a new one # # If the matching 3D view has been closed, we need to open a new one
try: # try:
FreeCAD.getDocument(docname) # FreeCAD.getDocument(docname)
except: # except:
FreeCAD.newDocument(docname) # FreeCAD.newDocument(docname)
# We import this way because using execfile() causes non-standard script execution in some situations # We import this way because using execfile() causes non-standard script execution in some situations
imp.load_source('temp_module', tempFile.name) imp.load_source('temp_module', tempFile.name)
@ -163,9 +163,6 @@ class CadQueryNewScript:
return True return True
def Activated(self): def Activated(self):
# We need to close any file that's already open in the editor window
CadQueryCloseScript().Activated()
module_base_path = module_locator.module_path() module_base_path = module_locator.module_path()
templ_dir_path = os.path.join(module_base_path, 'Templates') templ_dir_path = os.path.join(module_base_path, 'Templates')

View File

@ -3,6 +3,8 @@
def show(cqObject, rgba=(204, 204, 204, 0.0)): def show(cqObject, rgba=(204, 204, 204, 0.0)):
import FreeCAD import FreeCAD
from random import random from random import random
import os, tempfile
import Shared
#Convert our rgba values #Convert our rgba values
r = rgba[0] / 255.0 r = rgba[0] / 255.0
@ -10,6 +12,30 @@ def show(cqObject, rgba=(204, 204, 204, 0.0)):
b = rgba[2] / 255.0 b = rgba[2] / 255.0
a = int(rgba[3] * 100.0) a = int(rgba[3] * 100.0)
# 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'))
tempFile.close()
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, "")
# 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() ad = FreeCAD.activeDocument()
# If we've got a blank shape name, we have to create a random ID # If we've got a blank shape name, we have to create a random ID