def import_stpz(fn,fc,doc): # sayz(fn) ext = os.path.splitext(os.path.basename(fn))[1] fname=os.path.splitext(os.path.basename(fn))[0] basepath=os.path.split(fn)[0] filepath = os.path.join(basepath,fname + u'.stp') tempdir = tempfile.gettempdir() # get the current temporary directory tempfilepath = os.path.join(tempdir,fname + u'.stp') #with six.builtins.open(tempfilepath, 'wb') as f: #py3 with builtin.open(tempfilepath, 'wb') as f: #py3 f.write(fc) #ImportGui.insert(filepath) if doc is None: ImportGui.open(tempfilepath) else: ImportGui.open(tempfilepath,doc.Name) FreeCADGui.SendMsgToActiveView("ViewFit") try: os.remove(tempfilepath) except OSError: sayzerr("error on removing "+tempfilepath+" file") pass
def open(filename): sayz("stpZ version " + ___stpZversion___) with gz.open(filename, 'rb') as f: file_content = f.read() ext = os.path.splitext(os.path.basename(filename))[1] fname = os.path.splitext(os.path.basename(filename))[0] basepath = os.path.split(filename)[0] filepath = os.path.join(basepath, fname + u'.stp') tempdir = tempfile.gettempdir() # get the current temporary directory tempfilepath = os.path.join(tempdir, fname + u'.stp') with six.builtins.open(tempfilepath, 'wb') as f: #py3 f.write(file_content) #ImportGui.insert(filepath) ImportGui.open(tempfilepath) try: os.remove(tempfilepath) except OSError: sayzerr("error on removing " + tempfilepath + " file") pass
def open(filename): sayz("stpZ version "+___stpZversion___) with gzip_utf8.open(filename, 'rb') as f: file_content = f.read() ext = os.path.splitext(os.path.basename(filename))[1] fname=os.path.splitext(os.path.basename(filename))[0] basepath=os.path.split(filename)[0] filepath = os.path.join(basepath,fname + u'.stp') tempdir = tempfile.gettempdir() # get the current temporary directory tempfilepath = os.path.join(tempdir,fname + u'.stp') with builtin.open(tempfilepath, 'w') as f: #py3 f.write(file_content) #ImportGui.insert(filepath) ImportGui.open(tempfilepath) try: os.remove(tempfilepath) except OSError: sayzerr("error on removing "+tempfilepath+" file") pass
if save_memory == False: Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName, out_dir, False) check_Model = True if save_memory == True or check_Model == True: doc = FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) step_path = os.path.join(out_dir, ModelName + u'.step') if check_Model == True: #ImportGui.insert(step_path,ModelName) ImportGui.open(step_path) docu = FreeCAD.ActiveDocument if cq_cad_tools.checkUnion(docu) == True: FreeCAD.Console.PrintMessage( 'step file is correctly Unioned\n') else: FreeCAD.Console.PrintError('step file is NOT Unioned\n') stop FC_majorV = int(FreeCAD.Version()[0]) FC_minorV = int(FreeCAD.Version()[1]) if FC_majorV == 0 and FC_minorV >= 17: for o in docu.Objects: if hasattr(o, 'Shape'): chks = cq_cad_tools.checkBOP(o.Shape) print('chks ', chks) print(cq_cad_tools.mk_string(o.Label))
# freecad macro from pathlib import Path import ImportGui import Mesh step_root = Path('/home/rlha/d/iros-kit-template/STEP_Files') stl_root = Path('/home/rlha/d/iros-kit-template/stl') for step_file in step_root.glob('*.STEP'): if step_file.name == 'IROS2020_Practice.STEP': continue ImportGui.open(str(step_file)) stl_name = step_file.name.replace('.STEP', '.stl') Mesh.export(App.ActiveDocument.Objects, str(stl_root / stl_name)) App.closeDocument(App.ActiveDocument.Name)
def runGeometryCheck(App, Gui, step_path, log, modelName, save_memory=True, stop_on_first_error=True): FC_majorV = int(FreeCAD.Version()[0]) FC_minorV = int(FreeCAD.Version()[1]) try: FC_subV = int(FreeCAD.Version()[2].split(" ")[0]) except Exception: FC_subV = 0 if FC_majorV == 0 and FC_minorV == 16 and FC_subV < 6712: raise FreeCADVersionError( '0.16-6712', 'old 0.16 releases have a bug in the step exporter.') geometry_error_container = GeometryError() ImportGui.open(step_path) docu = FreeCAD.ActiveDocument docu.Label = modelName log.write('\n## Checking {:s}\n'.format(modelName)) if checkUnion(docu): FreeCAD.Console.PrintMessage('step file is correctly Unioned\n') log.write('\t- Union check: [ pass ]\n') else: #FreeCAD.Console.PrintError('step file is NOT Unioned\n') log.write('\t- Union check: [ FAIL ]\n') geometry_error_container.append(NotUnionedError(modelName)) #stop if FC_majorV == 0 and FC_minorV >= 17: if docu.Objects == 0: FreeCAD.Console.PrintError( 'Step import seems to fail. No objects to check\n') for o in docu.Objects: if hasattr(o, 'Shape'): o.Shape.fixTolerance(1e-4) chks = checkBOP(o.Shape) #print 'chks ',chks if chks != True: #msg='shape \''+o.Name+'\' \''+ mk_string(o.Label)+'\' is INVALID!\n' msg = 'shape "{name:s}" "{label:s}" is INVALID\n'.format( name=o.Name, label=o.Label) #FreeCAD.Console.PrintError(msg) #FreeCAD.Console.PrintWarning(chks[0]) geometry_error_container.append( BOBError(modelName, o.Name, o.Label, chks[0])) log.write('\t- Geometry check: [ FAIL ]\n') log.write('\t\t- Effected shape: "{name:s}" "{label:s}"\n'. format(name=o.Name, label=o.Label)) #stop else: #msg='shape \''+o.Name+'\' \''+ mk_string(o.Label)+'\' is valid\n' msg = 'shape "{name:s}" "{label:s}" is valid\n'.format( name=o.Name, label=o.Label) FreeCAD.Console.PrintMessage(msg) log.write('\t- Geometry check: [ pass ]\n') else: log.write('\t- Geometry check: [ skipped ]\n') log.write('\t\t- Geometry check needs FC 0.17+\n') raise FreeCADVersionError('0.17', 'Geometry check needs FC 0.17') if stop_on_first_error and geometry_error_container.error_encountered: raise geometry_error_container if save_memory == True: saveFCdoc(App, Gui, docu, 'temp', './', False) docu = FreeCAD.ActiveDocument FreeCAD.closeDocument(docu.Name) if geometry_error_container.error_encountered: raise geometry_error_container
# Set the directory variable before running import FreeCAD import ImportGui import FreeCADGui import os #directory = "/home/mikael/kicad_ws/osrf_hw/kicad_3dmodels/BGA" directory = os.getcwd() print directory if not os.path.isdir(directory): print "ERROR directory " + directory + " doesn't exist" exit(1) for root, subdirs, files in os.walk(directory): for filename in files: if filename.lower().endswith('.stp') or filename.lower().endswith( '.step'): file_path = os.path.join(root, filename) ImportGui.open(file_path) wrlname = file_path[ 0:file_path.rfind(file_path[file_path.rfind('.'):])] + ".wrl" Gui.export(App.ActiveDocument.findObjects("Part::Feature"), wrlname) App.closeDocument(App.ActiveDocument.Name) exit(1)
def MakeHeader(n, model, all_params): global formerDOC global LIST_license ModelName = model.replace('yy', "{n:02}".format(n=n)) full_path=os.path.realpath(__file__) expVRML.say(full_path) scriptdir=os.path.dirname(os.path.realpath(__file__)) expVRML.say(scriptdir) sub_path = full_path.split(scriptdir) expVRML.say(sub_path) sub_dir_name =full_path.split(os.sep)[-2] expVRML.say(sub_dir_name) sub_path = full_path.split(sub_dir_name)[0] expVRML.say(sub_path) models_dir=sub_path+"_3Dmodels" script_dir=os.path.dirname(os.path.realpath(__file__)) #models_dir=script_dir+"/../_3Dmodels" expVRML.say(models_dir) out_dir=models_dir+all_params[model]['output_directory'] if not os.path.exists(out_dir): os.makedirs(out_dir) CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) App.ActiveDocument=App.getDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) header_type = all_params[model]['type'] pitch = all_params[model]['pitch'] rows = all_params[model]['rows'] base_width = all_params[model]['base_width'] base_height = all_params[model]['base_height'] base_chamfer = all_params[model]['base_chamfer'] pin_width = all_params[model]['pin_width'] pin_length_above_base = all_params[model]['pin_length_above_base'] pin_end_chamfer = all_params[model]['pin_end_chamfer'] rotation = all_params[model]['rotation'] if base_chamfer == 'auto': base_chamfer = pitch/10. if pin_end_chamfer == 'auto': pin_end_chamfer = pin_width/4. if header_type == 'Vertical_THT': pin_length_below_board = all_params[model]['pin_length_below_board'] base = make_Vertical_THT_base(n, pitch, rows, base_width, base_height, base_chamfer) pins = make_Vertical_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, pin_width, pin_end_chamfer) elif header_type == 'Horizontal_THT': pin_length_below_board = all_params[model]['pin_length_below_board'] base_x_offset = all_params[model]['base_x_offset'] base = make_Horizontal_THT_base(n, pitch, rows, base_width, base_height, base_x_offset, base_chamfer) pins = make_Horizontal_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, base_width, pin_width, pin_end_chamfer, base_x_offset) elif header_type == 'Vertical_SMD': pin_length_horizontal = all_params[model]['pin_length_horizontal'] base_z_offset = all_params[model]['base_z_offset'] if rows == 1: pin_1_start = all_params[model]['pin_1_start'] else: pin_1_start = None pins = make_Vertical_SMD_pins(n, pitch, rows, pin_length_above_base, pin_length_horizontal, base_height, base_width, pin_width, pin_end_chamfer, base_z_offset, pin_1_start) base = make_Vertical_SMD_base(n, pitch, base_width, base_height, base_chamfer, base_z_offset) else: print 'Header type: ' print header_type print ' is not recognized, please check parameters' stop show(base) show(pins) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],pins_color) #Color_Objects(Gui,objs[2],marking_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:body_color_key, col_pin[:-1]:pins_color_key, #col_mark[:-1]:marking_color_key } expVRML.say(material_substitutions) #objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=CheckedModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=CheckedModelName restore_Main_Tools() if (rotation !=0): z_RotateObject(doc, rotation) #out_dir = models_dir+"/generated_pinheaders" doc.Label = CheckedModelName #save the STEP file exportSTEP(doc, ModelName, out_dir) if LIST_license[0]=="": LIST_license=Lic.LIST_int_license LIST_license.append("") Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc) # scale and export Vrml model scale=1/2.54 #exportVRML(doc,ModelName,scale,out_dir) objs=GetListOfObjects(FreeCAD, doc) expVRML.say("######################################################################") expVRML.say(objs) expVRML.say("######################################################################") export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions) export_file_name=out_dir+os.sep+ModelName+'.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) #save the VRML file #scale=0.3937001 #exportVRML(doc,name,scale,out_dir) if save_memory == False: Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName, out_dir, False) check_Model=True if save_memory == True or check_Model==True: closeCurrentDoc(CheckedModelName) step_path=os.path.join(out_dir,ModelName+u'.step') if check_Model==True: #ImportGui.insert(step_path,ModelName) ImportGui.open(step_path) docu = FreeCAD.ActiveDocument if cq_cad_tools.checkUnion(docu) == True: FreeCAD.Console.PrintMessage('step file is correctly Unioned\n') else: FreeCAD.Console.PrintError('step file is NOT Unioned\n') stop FC_majorV=int(FreeCAD.Version()[0]) FC_minorV=int(FreeCAD.Version()[1]) if FC_majorV == 0 and FC_minorV >= 17: for o in docu.Objects: if hasattr(o,'Shape'): chks=cq_cad_tools.checkBOP(o.Shape) print 'chks ',chks print cq_cad_tools.mk_string(o.Label) if chks != True: msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is INVALID!\n' FreeCAD.Console.PrintError(msg) FreeCAD.Console.PrintWarning(chks[0]) stop else: msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is valid\n' FreeCAD.Console.PrintMessage(msg) else: FreeCAD.Console.PrintError('BOP check requires FC 0.17+\n') # Save the doc in Native FC format saveFCdoc(App, Gui, docu, ModelName,out_dir, False) closeCurrentDoc(docu.Label) return 0
# Set the directory variable before running import FreeCAD import ImportGui import FreeCADGui import os # directory = "/home/mikael/kicad_ws/osrf_hw/kicad_3dmodels/BGA" directory = os.getcwd() print directory if not os.path.isdir(directory): print "ERROR directory " + directory + " doesn't exist" exit(1) for root, subdirs, files in os.walk(directory): for filename in files: if filename.lower().endswith(".stp") or filename.lower().endswith(".step"): file_path = os.path.join(root, filename) ImportGui.open(file_path) wrlname = file_path[0 : file_path.rfind(file_path[file_path.rfind(".") :])] + ".wrl" Gui.export(App.ActiveDocument.findObjects("Part::Feature"), wrlname) App.closeDocument(App.ActiveDocument.Name) exit(1)
def make_3D_model(models_dir, model_class, modelName): LIST_license = [ "", ] CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace( '(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument = Gui.getDocument(CheckedmodelName) destination_dir = model_class.get_dest_3D_dir(modelName) model_filename = model_class.get_dest_file_name(modelName) material_substitutions = model_class.make_3D_model(modelName) doc = FreeCAD.ActiveDocument doc.Label = CheckedmodelName objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = CheckedmodelName restore_Main_Tools() script_dir = os.path.dirname(os.path.realpath(__file__)) expVRML.say(models_dir) out_dir = models_dir + os.sep + destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) exportSTEP(doc, model_filename, out_dir) if LIST_license[0] == "": LIST_license = Lic.LIST_int_license LIST_license.append("") Lic.addLicenseToStep(out_dir+'/', model_filename+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc) # scale and export Vrml model scale = 1 / 2.54 #exportVRML(doc,model_filename,scale,out_dir) del objs objs = GetListOfObjects(FreeCAD, doc) expVRML.say( "######################################################################" ) expVRML.say(objs) expVRML.say( "######################################################################" ) export_objects, used_color_keys = expVRML.determineColors( Gui, objs, material_substitutions) export_file_name = out_dir + os.sep + model_filename + '.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) Gui.activateWorkbench("PartWorkbench") # if save_memory == False: Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() check_Model = True if save_memory == True: check_Model = True doc = FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) step_path = os.path.join(out_dir, model_filename + u'.step') if check_Model == True: #ImportGui.insert(step_path,model_filename) ImportGui.open(step_path) docu = FreeCAD.ActiveDocument if cq_cad_tools.checkUnion(docu) == True: FreeCAD.Console.PrintMessage('step file for ' + model_filename + ' is correctly Unioned\n') else: FreeCAD.Console.PrintError('step file ' + model_filename + ' is NOT Unioned\n') FreeCAD.closeDocument(docu.Name) sys.exit() saveFCdoc(App, Gui, docu, model_filename, out_dir, False) if save_memory == True: FreeCAD.closeDocument(docu.Name)
Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName,out_dir, False) check_Model=False if save_memory == True or check_Model==True: doc=FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) step_path=os.path.join(out_dir,ModelName+u'.step') if check_Model==True: #ImportGui.insert(step_path,ModelName) ImportGui.open(step_path) docu = FreeCAD.ActiveDocument if cq_cad_tools.checkUnion(docu) == True: FreeCAD.Console.PrintMessage('step file is correctly Unioned\n') else: FreeCAD.Console.PrintError('step file is NOT Unioned\n') stop FC_majorV=int(FreeCAD.Version()[0]) FC_minorV=int(FreeCAD.Version()[1]) if FC_majorV == 0 and FC_minorV >= 17: for o in docu.Objects: if hasattr(o,'Shape'): chks=cq_cad_tools.checkBOP(o.Shape) print 'chks ',chks print cq_cad_tools.mk_string(o.Label) if chks != True:
def runGeometryCheck(App, Gui, step_path, log, modelName, save_memory=True, stop_on_first_error = True): FC_majorV=int(FreeCAD.Version()[0]) FC_minorV=int(FreeCAD.Version()[1]) try: FC_subV=int(FreeCAD.Version()[2].split(" ")[0]) except Exception: FC_subV = 0 if FC_majorV == 0 and FC_minorV == 16 and FC_subV < 6712: raise FreeCADVersionError('0.16-6712', 'old 0.16 releases have a bug in the step exporter.') geometry_error_container = GeometryError() ImportGui.open(step_path) docu = FreeCAD.ActiveDocument docu.Label = modelName log.write('\n## Checking {:s}\n'.format(modelName)) if checkUnion(docu): FreeCAD.Console.PrintMessage('step file is correctly Unioned\n') log.write('\t- Union check: [ pass ]\n') else: #FreeCAD.Console.PrintError('step file is NOT Unioned\n') log.write('\t- Union check: [ FAIL ]\n') geometry_error_container.append(NotUnionedError(modelName)) #stop if FC_majorV == 0 and FC_minorV >= 17: if docu.Objects == 0: FreeCAD.Console.PrintError('Step import seems to fail. No objects to check\n') for o in docu.Objects: if hasattr(o,'Shape'): o.Shape.fixTolerance(1e-4) chks=checkBOP(o.Shape) #print 'chks ',chks if chks != True: #msg='shape \''+o.Name+'\' \''+ mk_string(o.Label)+'\' is INVALID!\n' msg = 'shape "{name:s}" "{label:s}" is INVALID\n'.format(name=o.Name, label=o.Label) #FreeCAD.Console.PrintError(msg) #FreeCAD.Console.PrintWarning(chks[0]) geometry_error_container.append(BOBError(modelName, o.Name, o.Label, chks[0])) log.write('\t- Geometry check: [ FAIL ]\n') log.write('\t\t- Effected shape: "{name:s}" "{label:s}"\n'.format(name=o.Name, label=o.Label)) #stop else: #msg='shape \''+o.Name+'\' \''+ mk_string(o.Label)+'\' is valid\n' msg = 'shape "{name:s}" "{label:s}" is valid\n'.format(name=o.Name, label=o.Label) FreeCAD.Console.PrintMessage(msg) log.write('\t- Geometry check: [ pass ]\n') else: log.write('\t- Geometry check: [ skipped ]\n') log.write('\t\t- Geometry check needs FC 0.17+\n') raise FreeCADVersionError('0.17', 'Geometry check needs FC 0.17') if stop_on_first_error and geometry_error_container.error_encountered: raise geometry_error_container if save_memory == True: saveFCdoc(App, Gui, docu, 'temp', './', False) docu = FreeCAD.ActiveDocument FreeCAD.closeDocument(docu.Name) if geometry_error_container.error_encountered: raise geometry_error_container
def MakeHeader(n, model, all_params): global formerDOC global LIST_license ModelName = model.replace('yy', "{n:02}".format(n=n)) full_path=os.path.realpath(__file__) expVRML.say(full_path) scriptdir=os.path.dirname(os.path.realpath(__file__)) expVRML.say(scriptdir) sub_path = full_path.split(scriptdir) expVRML.say(sub_path) sub_dir_name =full_path.split(os.sep)[-2] expVRML.say(sub_dir_name) sub_path = full_path.split(sub_dir_name)[0] expVRML.say(sub_path) models_dir=sub_path+"_3Dmodels" script_dir=os.path.dirname(os.path.realpath(__file__)) #models_dir=script_dir+"/../_3Dmodels" expVRML.say(models_dir) out_dir=models_dir+all_params[model]['output_directory'] if not os.path.exists(out_dir): os.makedirs(out_dir) CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) App.ActiveDocument=App.getDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) header_type = all_params[model]['type'] pitch = all_params[model]['pitch'] rows = all_params[model]['rows'] base_width = all_params[model]['base_width'] base_height = all_params[model]['base_height'] base_chamfer = all_params[model]['base_chamfer'] pin_width = all_params[model]['pin_width'] pin_length_above_base = all_params[model]['pin_length_above_base'] pin_end_chamfer = all_params[model]['pin_end_chamfer'] rotation = all_params[model]['rotation'] if base_chamfer == 'auto': base_chamfer = pitch/10. if pin_end_chamfer == 'auto': pin_end_chamfer = pin_width/4. if header_type == 'Vertical_THT': pin_length_below_board = all_params[model]['pin_length_below_board'] base = make_Vertical_THT_base(n, pitch, rows, base_width, base_height, base_chamfer) pins = make_Vertical_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, pin_width, pin_end_chamfer) elif header_type == 'Horizontal_THT': pin_length_below_board = all_params[model]['pin_length_below_board'] base_x_offset = all_params[model]['base_x_offset'] base = make_Horizontal_THT_base(n, pitch, rows, base_width, base_height, base_x_offset, base_chamfer) pins = make_Horizontal_THT_pins(n, pitch, rows, pin_length_above_base, pin_length_below_board, base_height, base_width, pin_width, pin_end_chamfer, base_x_offset) elif header_type == 'Vertical_SMD': pin_length_horizontal = all_params[model]['pin_length_horizontal'] base_z_offset = all_params[model]['base_z_offset'] if rows == 1: pin_1_start = all_params[model]['pin_1_start'] else: pin_1_start = None pins = make_Vertical_SMD_pins(n, pitch, rows, pin_length_above_base, pin_length_horizontal, base_height, base_width, pin_width, pin_end_chamfer, base_z_offset, pin_1_start) base = make_Vertical_SMD_base(n, pitch, base_width, base_height, base_chamfer, base_z_offset) else: print 'Header type: ' print header_type print ' is not recognized, please check parameters' stop show(base) show(pins) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],pins_color) #Color_Objects(Gui,objs[2],marking_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] #col_mark=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:body_color_key, col_pin[:-1]:pins_color_key, #col_mark[:-1]:marking_color_key } expVRML.say(material_substitutions) #objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=CheckedModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=CheckedModelName restore_Main_Tools() if (rotation !=0): z_RotateObject(doc, rotation) #out_dir = models_dir+"/generated_pinheaders" doc.Label = CheckedModelName #save the STEP file exportSTEP(doc, ModelName, out_dir) if LIST_license[0]=="": LIST_license=Lic.LIST_int_license LIST_license.append("") Lic.addLicenseToStep(out_dir+'/', ModelName+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc) # scale and export Vrml model scale=1/2.54 #exportVRML(doc,ModelName,scale,out_dir) objs=GetListOfObjects(FreeCAD, doc) expVRML.say("######################################################################") expVRML.say(objs) expVRML.say("######################################################################") export_objects, used_color_keys = expVRML.determineColors(Gui, objs, material_substitutions) export_file_name=out_dir+os.sep+ModelName+'.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) #save the VRML file #scale=0.3937001 #exportVRML(doc,name,scale,out_dir) if save_memory == False: Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName, out_dir, False) check_Model=True if save_memory == True or check_Model==True: doc=FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) step_path=os.path.join(out_dir,ModelName+u'.step') if check_Model==True: #ImportGui.insert(step_path,ModelName) ImportGui.open(step_path) docu = FreeCAD.ActiveDocument if cq_cad_tools.checkUnion(docu) == True: FreeCAD.Console.PrintMessage('step file is correctly Unioned\n') else: FreeCAD.Console.PrintError('step file is NOT Unioned\n') stop FC_majorV=int(FreeCAD.Version()[0]) FC_minorV=int(FreeCAD.Version()[1]) if FC_majorV == 0 and FC_minorV >= 17: for o in docu.Objects: if hasattr(o,'Shape'): chks=cq_cad_tools.checkBOP(o.Shape) print 'chks ',chks print cq_cad_tools.mk_string(o.Label) if chks != True: msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is INVALID!\n' FreeCAD.Console.PrintError(msg) FreeCAD.Console.PrintWarning(chks[0]) stop else: msg='shape \''+o.Name+'\' \''+cq_cad_tools.mk_string(o.Label)+'\' is valid\n' FreeCAD.Console.PrintMessage(msg) else: FreeCAD.Console.PrintError('BOP check requires FC 0.17+\n') # Save the doc in Native FC format saveFCdoc(App, Gui, docu, ModelName,out_dir, False) doc=FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) return 0
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")