def ListDemos(): import os import ksu_locator dirs = [] # List all of the example files in an order that makes sense module_base_path = ksu_locator.module_path() demo_dir_path = os.path.join(module_base_path, 'demo') dirs = os.listdir(demo_dir_path) dirs.sort() return dirs
def Activated(self): FreeCAD.Console.PrintWarning('opening ' + self.exFile + "\r\n") import os, sys # So we can open the "Open File" dialog mw = FreeCADGui.getMainWindow() # Start off defaulting to the Examples directory ksu_base_path = ksu_locator.module_path() exs_dir_path = os.path.join(ksu_base_path, 'demo') abs_ksu_path = ksu_locator.abs_module_path() # Append this script's directory to sys.path sys.path.append(os.path.dirname(exs_dir_path)) # We've created a library that FreeCAD can use as well to open CQ files fnameDemo = (os.path.join(exs_dir_path, self.exFile)) demo_model = 'dpak-to252.step' stepfname = (os.path.join(exs_dir_path, 'shapes', demo_model)) ext = os.path.splitext(os.path.basename(fnameDemo))[1] nme = os.path.splitext(os.path.basename(fnameDemo))[0] FC_majorV = int(FreeCAD.Version()[0]) FC_minorV = int(FreeCAD.Version()[1]) if ext.lower() == ".pdf": import subprocess, sys if sys.platform == "linux" or sys.platform == "linux2": # linux subprocess.call(["xdg-open", fnameDemo]) if sys.platform == "darwin": # osx cmd_open = 'open ' + fnameDemo os.system(cmd_open) #win, osx else: # win subprocess.Popen([fnameDemo], shell=True) elif ext.lower() == ".kicad_pcb" or ext.lower() == ".kicad_mod": #FreeCAD.Console.PrintMessage(abs_ksu_path + "\r\n") #FreeCAD.Console.PrintMessage(stepfname + "\r\n") #FreeCAD.Console.PrintMessage(exs_dir_path + "\r\n") import kicadStepUptools # reload( kicadStepUptools ) if reload_Gui: reload_lib(kicadStepUptools) from kicadStepUptools import open, create_axis #onLoadBoard, onLoadFootprint if ext.lower() == ".kicad_mod": dname = (demo_model).split('.')[0].replace('-', '_') doc = FreeCAD.newDocument(dname) dname = doc.Name #print dname FreeCAD.setActiveDocument(dname) FreeCAD.ActiveDocument = FreeCAD.getDocument(dname) FreeCADGui.ActiveDocument = FreeCADGui.getDocument(dname) #doc=FreeCAD.newDocument((demo_model).split('.')[0].replace('-','_')) #FreeCAD.setActiveDocument(doc) import ImportGui ImportGui.insert(stepfname, doc.Name) FreeCADGui.activeDocument().activeView().viewAxonometric() open(fnameDemo) if FreeCAD.ActiveDocument.getObject("axis") is None: create_axis() else: open(fnameDemo) #docL=FreeCAD.ActiveDocument.Label elif ext.lower() == ".fcstd": if FC_majorV == 0 and FC_minorV < 17: fnameDemo = fnameDemo.rstrip(ext) + '-fc16' + ext FreeCAD.Console.PrintWarning('opening ' + fnameDemo + "\r\n") FreeCAD.open(fnameDemo) FreeCADGui.activeDocument().activeView().viewAxonometric() elif ext.lower() == ".step": if FC_majorV == 0 and FC_minorV < 17: fnameDemo = fnameDemo.rstrip(ext) + '-fc16' + ext FreeCAD.Console.PrintWarning('opening ' + fnameDemo + "\r\n") import ImportGui ImportGui.open(fnameDemo) FreeCADGui.activeDocument().activeView().viewAxonometric() FreeCADGui.SendMsgToActiveView("ViewFit")