def Activated(self): # Grab our code editor so we can interact with it cqCodePane = Shared.getActiveCodePane() # If there is no script to check, ignore this command if cqCodePane is None: FreeCAD.Console.PrintMessage("There is no script to validate.") return # Clear the old render before re-rendering Shared.clearActiveDocument() scriptText = cqCodePane.toPlainText().encode('utf-8') if ("show_object(" not in scriptText and "# show_object(" in scriptText and "#show_boject(" in scriptText) or ("debug(" not in scriptText and "# debug(" in scriptText and "#debug(" in scriptText): FreeCAD.Console.PrintError("Script did not call show_object or debug, no output available. Script must be CQGI compliant to get build output, variable editing and validation.\r\n") return # A repreentation of the CQ script with all the metadata attached cqModel = cqgi.parse(scriptText) # Allows us to present parameters to users later that they can alter parameters = cqModel.metadata.parameters Shared.populateParameterEditor(parameters)
def Activated(self): # Grab our code editor so we can interact with it cqCodePane = Shared.getActiveCodePane() # If there is no script to check, ignore this command if cqCodePane is None: FreeCAD.Console.PrintMessage("There is no script to validate.") return # Clear the old render before re-rendering Shared.clearActiveDocument() scriptText = cqCodePane.toPlainText().encode('utf-8') if (b"show_object(" not in scriptText) and (b"debug(" not in scriptText): FreeCAD.Console.PrintError("Script did not call show_object or debug, no output available. Script must be CQGI compliant to get build output, variable editing and validation.\r\n") return # A repreentation of the CQ script with all the metadata attached cqModel = cqgi.parse(scriptText) # Allows us to present parameters to users later that they can alter parameters = cqModel.metadata.parameters Shared.populateParameterEditor(parameters)
def Activated(self): # 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() # Set some environment variables that may help the user os.environ["MYSCRIPT_FULL_PATH"] = cqCodePane.file.path os.environ["MYSCRIPT_DIR"] = os.path.dirname( os.path.abspath(cqCodePane.file.path)) # We import this way because using execfile() causes non-standard script execution in some situations imp.load_source('temp_module', tempFile.name) msg = QtGui.QApplication.translate("cqCodeWidget", "Executed ", None, QtGui.QApplication.UnicodeUTF8) FreeCAD.Console.PrintMessage(msg + cqCodePane.file.path + "\r\n")
def Activated(self): # Grab our code editor so we can interact with it cqCodePane = Shared.getActiveCodePane() # Clear the old render before re-rendering Shared.clearActiveDocument() scriptText = cqCodePane.toPlainText().encode('utf-8') # Check to see if we are executig a CQGI compliant script if ("show_object(" in scriptText and "# show_object(" not in scriptText and "#show_boject(" not in scriptText) or ("debug(" in scriptText and "# debug(" not in scriptText and "#debug(" not in scriptText): FreeCAD.Console.PrintMessage("Executing CQGI-compliant script.\r\n") # A repreentation of the CQ script with all the metadata attached cqModel = cqgi.parse(scriptText) # Allows us to present parameters to users later that they can alter parameters = cqModel.metadata.parameters build_parameters = {} # Collect the build parameters from the Parameters Editor view, if they exist mw = FreeCADGui.getMainWindow() # Tracks whether or not we have already added the variables editor isPresent = False # If the widget is open, we need to close it dockWidgets = mw.findChildren(QtGui.QDockWidget) for widget in dockWidgets: if widget.objectName() == "cqVarsEditor": # Toggle the visibility of the widget if not widget.visibleRegion().isEmpty(): # Find all of the controls that will have parameter values in them valueControls = mw.findChildren(QtGui.QLineEdit) for valueControl in valueControls: objectName = valueControl.objectName() # We only want text fields that will have parameter values in them if objectName != None and objectName != '' and objectName.find('pcontrol_') >= 0: # Associate the value in the text field with the variable name in the script build_parameters[objectName.replace('pcontrol_', '')] = valueControl.text() build_result = cqModel.build(build_parameters=build_parameters) if Settings.report_execute_time: FreeCAD.Console.PrintMessage("Script executed in " + str(build_result.buildTime) + " seconds\r\n") # Make sure that the build was successful if build_result.success: # Display all the results that the user requested for result in build_result.results: # Apply options to the show function if any were provided if result.options and result.options["rgba"]: show(result.shape, result.options["rgba"]) else: show(result.shape) for debugObj in build_result.debugObjects: # Mark this as a debug object debugObj.shape.val().label = "Debug" + str(random()) # Apply options to the show function if any were provided if debugObj.options and debugObj.options["rgba"]: show(debugObj.shape, debugObj.options["rgba"]) else: show(debugObj.shape, (255, 0, 0, 0.80)) else: FreeCAD.Console.PrintError("Error executing CQGI-compliant script. " + str(build_result.exception) + "\r\n") else: # Save our code to a tempfile and render it tempFile = tempfile.NamedTemporaryFile(delete=False) tempFile.write(scriptText) tempFile.close() # Set some environment variables that may help the user os.environ["MYSCRIPT_FULL_PATH"] = cqCodePane.file.path os.environ["MYSCRIPT_DIR"] = os.path.dirname(os.path.abspath(cqCodePane.file.path)) # We import this way because using execfile() causes non-standard script execution in some situations with revert_sys_modules(): imp.load_source('temp_module', tempFile.name) msg = QtGui.QApplication.translate( "cqCodeWidget", "Executed ", None) FreeCAD.Console.PrintMessage(msg + cqCodePane.file.path + "\r\n")
def Activated(self): # Grab our code editor so we can interact with it cqCodePane = Shared.getActiveCodePane() # Clear the old render before re-rendering Shared.clearActiveDocument() scriptText = cqCodePane.toPlainText().encode('utf-8') # Check to see if we are executig a CQGI compliant script if b"show_object(" in scriptText or b"debug(" in scriptText: FreeCAD.Console.PrintMessage("Executing CQGI-compliant script.\r\n") # A repreentation of the CQ script with all the metadata attached cqModel = cqgi.parse(scriptText) # Allows us to present parameters to users later that they can alter parameters = cqModel.metadata.parameters build_parameters = {} # Collect the build parameters from the Parameters Editor view, if they exist mw = FreeCADGui.getMainWindow() # Tracks whether or not we have already added the variables editor isPresent = False # If the widget is open, we need to close it dockWidgets = mw.findChildren(QtGui.QDockWidget) for widget in dockWidgets: if widget.objectName() == "cqVarsEditor": # Toggle the visibility of the widget if not widget.visibleRegion().isEmpty(): # Find all of the controls that will have parameter values in them valueControls = mw.findChildren(QtGui.QLineEdit) for valueControl in valueControls: objectName = valueControl.objectName() # We only want text fields that will have parameter values in them if objectName != None and objectName != '' and objectName.find('pcontrol_') >= 0: # Associate the value in the text field with the variable name in the script build_parameters[objectName.replace('pcontrol_', '')] = valueControl.text() build_result = cqModel.build(build_parameters=build_parameters) # if Settings.report_execute_time: # FreeCAD.Console.PrintMessage("Script executed in " + str(build_result.buildTime) + " seconds\r\n") # Make sure that the build was successful if build_result.success: # Display all the results that the user requested for result in build_result.results: # Apply options to the show function if any were provided if result.options and result.options["rgba"]: show(result.shape, result.options["rgba"]) else: show(result.shape) for debugObj in build_result.debugObjects: # Mark this as a debug object debugObj.shape.val().label = "Debug" + str(random()) # Apply options to the show function if any were provided if debugObj.options and debugObj.options["rgba"]: show(debugObj.shape, debugObj.options["rgba"]) else: show(debugObj.shape, (255, 0, 0, 0.80)) else: FreeCAD.Console.PrintError("Error executing CQGI-compliant script. " + str(build_result.exception) + "\r\n") else: # Save our code to a tempfile and render it tempFile = tempfile.NamedTemporaryFile(delete=False) tempFile.write(scriptText) tempFile.close() # Set some environment variables that may help the user os.environ["MYSCRIPT_FULL_PATH"] = cqCodePane.get_path() os.environ["MYSCRIPT_DIR"] = os.path.dirname(os.path.abspath(cqCodePane.get_path())) # We import this way because using execfile() causes non-standard script execution in some situations with revert_sys_modules(): imp.load_source('__cq_freecad_module__', tempFile.name) msg = QtGui.QApplication.translate( "cqCodeWidget", "Executed ", None) FreeCAD.Console.PrintMessage(msg + cqCodePane.get_path() + "\r\n")