def make_3D_model(models_dir, variant, pinnumber): LIST_license = ["",] modelName = all_params[variant].serie + '_' + str(pinnumber) modelfileName = '' CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '').replace(',', '_') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument=Gui.getDocument(CheckedmodelName) case = None pins = None if all_params[variant].serie == 'MKDS-1,5': case = make_case_MKDS_1_5_10_5_08(all_params[variant], pinnumber) pins = make_pins_MKDS_1_5_10_5_08(all_params[variant], pinnumber) show(case) show(pins) # # modelfileName = modelfileName + all_params[variant].manufacture + '_' + all_params[variant].serie modelfileName = modelfileName + '-' + str(pinnumber) modelfileName = modelfileName + '-' + '{:.2f}'.format(all_params[variant].PS) modelfileName = modelfileName + '_1x' + '{:02d}'.format(pinnumber) modelfileName = modelfileName + '_P' + '{:.2f}'.format(all_params[variant].PS) + "mm" modelfileName = modelfileName + '_Horizontal'
def make_3D_model(models_dir, variant): LIST_license = [ "", ] FreeCAD.Console.PrintMessage("\r\nMaking %s\r\n" % variant) modelName = variant modelfileName = '' CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace( '(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument = Gui.getDocument(CheckedmodelName) case = None pins = None if all_params[variant].modeltype == 'BX0036': case = make_case_BX0036(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant])
def export_one_part(modul, variant): if not variant in modul.all_params: FreeCAD.Console.PrintMessage( "Parameters for %s doesn't exist in 'M.all_params', skipping." % variant) return ModelName = modul.all_params[variant].model_name FileName = modul.all_params[variant].file_name Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument = Gui.getDocument(ModelName) (pins, body) = modul.generate_part(variant) color_attr = body_color + (0, ) show(body, color_attr) color_attr = pins_color + (0, ) show(pins, color_attr) doc = FreeCAD.ActiveDocument doc.Label = ModelName objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = ModelName + "__body" objs[1].Label = ModelName + "__pins" restore_Main_Tools() out_dir = destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) used_color_keys = [body_color_key, pins_color_key] export_file_name = destination_dir + os.sep + FileName + '.wrl' export_objects = [] export_objects.append( expVRML.exportObject(freecad_object=objs[0], shape_color=body_color_key, face_colors=None)) export_objects.append( expVRML.exportObject(freecad_object=objs[1], shape_color=pins_color_key, face_colors=None)) scale = 1 / 2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) fusion = FuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs[0].Name, objs[1].Name, keepOriginals=True) exportSTEP(doc, FileName, out_dir, fusion) L.addLicenseToStep(out_dir+'/', FileName+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc) saveFCdoc(App, Gui, doc, FileName, out_dir)
def export_one_part(params): FreeCAD.Console.PrintMessage('\r\n' + params.model_name) ModelName = params.model_name FileName = params.file_name Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument = Gui.getDocument(ModelName) (pins, body) = M.generate_part(params) color_attr = body_color + (0, ) show(body, color_attr) color_attr = pins_color + (0, ) show(pins, color_attr) doc = FreeCAD.ActiveDocument doc.Label = ModelName objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = ModelName + "__body" objs[1].Label = ModelName + "__pins" restore_Main_Tools() out_dir = destination_dir used_color_keys = [body_color_key, pins_color_key] export_file_name = destination_dir + os.sep + FileName + '.wrl' export_objects = [] export_objects.append( expVRML.exportObject(freecad_object=objs[0], shape_color=body_color_key, face_colors=None)) export_objects.append( expVRML.exportObject(freecad_object=objs[1], shape_color=pins_color_key, face_colors=None)) scale = 1 / 2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) fusion = FuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs[0].Name, objs[1].Name, keepOriginals=True) exportSTEP(doc, FileName, out_dir, fusion) L.addLicenseToStep(out_dir+'/', FileName+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc) FreeCAD.activeDocument().recompute() #FreeCADGui.activateWorkbench("PartWorkbench") FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.activeDocument().activeView().viewAxometric() saveFCdoc(App, Gui, doc, FileName, out_dir)
def MakeHeader(n, params): name = HeaderName(n, params) #having a period '.' character in the model name REALLY messes with things. docname = name.replace(".", "") newdoc = FreeCAD.newDocument(docname) App.setActiveDocument(docname) Gui.ActiveDocument = Gui.getDocument(docname) pins = MakePinRow(n, params) #duplicate pin rows if params.rows > 1: for i in range(1, params.rows): pins = pins.union( MakePinRow(n, params).translate((0, i * params.p, 0))) base = MakeBase(n, params) #assign some colors base_color = (50, 50, 50) pins_color = (225, 175, 0) show(base, base_color + (0, )) show(pins, pins_color + (0, )) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label = docname objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = docname restore_Main_Tools() if (params.rot != 0): z_RotateObject(doc, params.rot) out_dir = "./generated_pinheaders/" doc.Label = docname #save the STEP file exportSTEP(doc, name, out_dir) #save the VRML file scale = 0.3937001 exportVRML(doc, name, scale, out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, name, out_dir) Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() return 0
def MakeHeader(n, params): name = HeaderName(n,params) #having a period '.' character in the model name REALLY messes with things. docname = name.replace(".","") newdoc = FreeCAD.newDocument(docname) App.setActiveDocument(docname) Gui.ActiveDocument=Gui.getDocument(docname) pins = MakePinRow(n,params) #duplicate pin rows if params.rows > 1: for i in range(1,params.rows): pins = pins.union(MakePinRow(n,params).translate((0,i*params.p,0))) base = MakeBase(n,params) #assign some colors base_color = (50,50,50) pins_color = (225,175,0) show(base,base_color+(0,)) show(pins,pins_color+(0,)) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=docname objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=docname restore_Main_Tools() if (params.rot !=0): z_RotateObject(doc, params.rot) out_dir = "./generated_pinheaders/" doc.Label = docname #save the STEP file exportSTEP(doc, name, out_dir) #save the VRML file scale=0.3937001 exportVRML(doc,name,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, name,out_dir) Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() return 0
def makeNumberRing (self): """ create the ring with numbers (0..9) on cover frame of rotary coded switch. This function can be implemented not before CADQuery version 2 or higher is available within FreeCAD. :rtype: ``solid`` """ body = cq.Workplane("XY")\ .text("0", self.number_font_size, 1.0) show(body) return body
def main(argmodel_to_build, argcolor_pin_mark): global color_pin_mark global model_to_build global excluded_pins_xmirror global excluded_pins_x color_pin_mark = argcolor_pin_mark model_to_build = argmodel_to_build if model_to_build == "all": variants = all_params.keys() else: variants = [model_to_build] for variant in variants: FreeCAD.Console.PrintMessage("\r\n" + variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument = Gui.getDocument(ModelName) case, pins = make_dip(all_params[variant]) color_attr = case_color + (0,) show(case, color_attr) # FreeCAD.Console.PrintMessage(pins_color) color_attr = pins_color + (0,) # FreeCAD.Console.PrintMessage(color_attr) show(pins, color_attr) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label = ModelName objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = ModelName restore_Main_Tools() # rotate if required if all_params[variant].rotation != 0: rot = all_params[variant].rotation z_RotateObject(doc, rot) out_dir = destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) # out_dir="./generated_qfp/" # export STEP model exportSTEP(doc, ModelName, out_dir) # scale and export Vrml model scale = 0.3937001 exportVRML(doc, ModelName, scale, out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName, out_dir) # display BBox FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True
def make_3D_model(self): """ create a 3D model of a WAGO serie 734 connector. Two parts will be created: plastic body, pins. This function will be called from the main_generator script. :return: list of the materials used for the 3D model :rtype: ``dictionary`` """ destination_dir = self.get_dest_3D_dir() case = self.makePlasticCase() pins = self.make_pins() show(case) show(pins) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) body_color = shaderColors.named_colors[self.body_color_key].getDiffuseFloat() pin_color = shaderColors.named_colors[self.pin_color_key].getDiffuseFloat() # must be the same order of the above show(..) calls Color_Objects(Gui, objs[0], body_color) Color_Objects(Gui, objs[1], pin_color) col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:self.body_color_key, col_pin[:-1]:self.pin_color_key, } expVRML.say(material_substitutions) # fuse all parts of model while len(objs) > 1: FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) del objs objs = GetListOfObjects(FreeCAD, doc) #rotate if required if (self.rotation != 0): z_RotateObject(doc, self.rotation) s = objs[0].Shape shape = s.copy() shape.Placement = s.Placement; shape.translate(self.offsets) objs[0].Placement = shape.Placement return material_substitutions
def export_one_part(modul, variant): if not variant in modul.all_params: FreeCAD.Console.PrintMessage("Parameters for %s doesn't exist in 'M.all_params', skipping." % variant) return ModelName = modul.all_params[variant].model_name FileName = modul.all_params[variant].file_name Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) (pins, body) = modul.generate_part(variant) color_attr = body_color + (0,) show(body, color_attr) color_attr = pins_color + (0,) show(pins, color_attr) doc = FreeCAD.ActiveDocument doc.Label=ModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label = ModelName + "__body" objs[1].Label = ModelName + "__pins" restore_Main_Tools() out_dir=destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) used_color_keys = [body_color_key, pins_color_key] export_file_name=destination_dir+os.sep+FileName+'.wrl' export_objects = [] export_objects.append(expVRML.exportObject(freecad_object = objs[0], shape_color=body_color_key, face_colors=None)) export_objects.append(expVRML.exportObject(freecad_object = objs[1], shape_color=pins_color_key, face_colors=None)) scale=1/2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) fusion = FuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs[0].Name, objs[1].Name, keepOriginals=True) exportSTEP(doc,FileName,out_dir,fusion) L.addLicenseToStep(out_dir+'/', FileName+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc) saveFCdoc(App, Gui, doc, FileName,out_dir)
def make(self): show(self.make_body()) show(self.make_pins()) show(self.make_buttons()) show( self.make_pinmark(self.button_width - (0.1 if self.button_width > 1.0 else 0.0)))
def make_3D_model(models_dir, variant): LIST_license = ["",] modelName = all_params[variant].modelName CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument=Gui.getDocument(CheckedmodelName) if (all_params[variant].serie == 'RV_Disc'): case = make_case_RV_Disc(all_params[variant]) pins = make_pins_RV_Disc(all_params[variant]) show(case) show(pins)
def build_and_save(i): ModelName='pinstrip_p254_'+str(i)+'x1' Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) FreeCAD.Console.PrintMessage('making all pin headers\r\n') case, pins = make_pinheader(i) color_attr=case_color+(0,) show(case, color_attr) #FreeCAD.Console.PrintMessage(pins_color) color_attr=pins_color+(0,) #FreeCAD.Console.PrintMessage(color_attr) show(pins, color_attr) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=ModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=ModelName restore_Main_Tools() #rotate if required if (rotation!=0): z_RotateObject(doc, rotation) out_dir=destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) #out_dir="./generated_qfp/" # export STEP model exportSTEP(doc,ModelName,out_dir) # scale and export Vrml model scale=0.3937001 exportVRML(doc,ModelName,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName,out_dir) #display BBox FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True #import ImportGui #ImportGui.insert(u"C:/Cad/Progetti_K/FreeCAD-models/scripts/3D-models/CadQuery/reference-block.step","mypin") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() return 0
def build_and_save(i): ModelName = 'pinstrip_p254_' + str(i) + 'x1' Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument = Gui.getDocument(ModelName) FreeCAD.Console.PrintMessage('making all pin headers\r\n') case, pins = make_pinheader(i) color_attr = case_color + (0, ) show(case, color_attr) #FreeCAD.Console.PrintMessage(pins_color) color_attr = pins_color + (0, ) #FreeCAD.Console.PrintMessage(color_attr) show(pins, color_attr) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label = ModelName objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = ModelName restore_Main_Tools() #rotate if required if (rotation != 0): z_RotateObject(doc, rotation) out_dir = destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) #out_dir="./generated_qfp/" # export STEP model exportSTEP(doc, ModelName, out_dir) # scale and export Vrml model scale = 0.3937001 exportVRML(doc, ModelName, scale, out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName, out_dir) #display BBox FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True #import ImportGui #ImportGui.insert(u"C:/Cad/Progetti_K/FreeCAD-models/scripts/3D-models/CadQuery/reference-block.step","mypin") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() return 0
def make(self): r"""Create the 3D model of the rotary coded switch and brings it on the FreeCAD screen """ # Each show creates a part in FreeCAD and this part will be given a material color, within the method cq_model_generator.makeModel(...). # For this reason there must be a list called color_keys[]. This list is defined in cq_base_model, with two entries, # one for the body material, one for the pin material. If this is not sufficiant this list must be overridden by all classes # derived from cq_base_model. The number of entries must match the number of calling show()!! show (self.modelBody.makePlasticBody()) show (self.modelBody.makeTurnInset()) show (self.modelBody.makeCoverPlate()) show (self.makePins()) #self.modelBody.makeNumberRing() if self.CheckedmodelName is not None: self.modelBody.importNumberRing10 (self.CheckedmodelName)
def make(params, top_color=None, case_color=None, pins_color=None): import cadquery as cq from Helpers import show pt = min(0.025, params.A.min/10) # Plating thickness ef = min(0.020, params.A.min/20) # Edge fillet wp = cq.Workplane("XY") pin1 = wp.box(params.L.max, params.E.max, params.A.max)\ .translate((-params.D.max/2 + params.L.max/2, 0, params.A.max/2)) pin1.edges("|Y").fillet(ef) pin2 = wp.box(params.L.max, params.E.max, params.A.max)\ .translate((params.D.max/2 - params.L.max/2, 0, params.A.max/2)) pin2.edges("|Y").fillet(ef) pins = pin1.union(pin2) if params.family == "RESC": case = wp.box(params.D.max - 2*pt, params.E.max, params.A.max - 2*pt)\ .translate((0, 0, params.A.max/2)) top = wp.box(params.D.max - 2*params.L.max, params.E.max, pt)\ .translate((0, 0, params.A.max - pt/2)) pins = pins.cut(case) show(top, top_color or COLOR_BLACK)
def inner(obj, _depth=0): log.debug("display obj: %r: %r", type(self), obj) if isinstance(obj, Part): if _depth: # Assembly being displayed, parts need to be placed show(obj.world_obj, obj._render.rgbt) else: # Part being displayed, just show in local coords show(obj.local_obj, obj._render.rgbt) elif isinstance(obj, Assembly): obj.solve() for (name, component) in obj.components.items(): inner(component, _depth=_depth + 1) elif isinstance(obj, cadquery.CQ): show(obj)
def inner(obj, _depth=0): log.debug("display obj: %r", obj) if isinstance(obj, Part): if _depth: # Assembly being displayed, parts need to be placed show(obj.world_obj, obj._render.rgbt) else: # Part being displayed, just show in local coords show(obj.local_obj, obj._render.rgbt) elif isinstance(obj, Assembly): obj.solve() for (name, component) in obj.components.items(): inner(component, _depth=_depth + 1) elif isinstance(obj, cadquery.CQ): show(obj)
def export_one_part(module, pincount, configuration, log): series_definition = module.series_params if module.LICENCE_Info.LIST_license[0]=="": LIST_license=L.LIST_int_license LIST_license.append("") else: LIST_license=module.LICENCE_Info.LIST_license LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + module.LICENCE_Info.STR_licAuthor pins_per_row = pincount/series_definition.number_of_rows mpn = series_definition.mpn_format_string.format(pincount=pincount, pins_per_row=pins_per_row) orientation = configuration['orientation_options'][series_definition.orientation] format_string = getattr(series_definition, 'fp_name_format_string', configuration[getattr(series_definition, 'fp_name_format', 'fp_name_format_string')]) FileName = format_string.format(man=series_definition.manufacturer, series=series_definition.series, mpn=mpn, num_rows=series_definition.number_of_rows, pins_per_row=pins_per_row, pins=pincount, pitch=series_definition.pitch, orientation=orientation, mount_pin=series_definition.mount_pin) FileName = FileName.replace('__', '_') lib_name = configuration['lib_name_format_string'].format(man=series_definition.manufacturer) fc_mpn = mpn.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') ModelName = '{:s}_{:s}'.format(series_definition.manufacturer, fc_mpn) # For some reason the Model name can not start with a number. FreeCAD.Console.PrintMessage('\r\n'+FileName+'\r\n') #FileName = modul.all_params[variant].file_name Newdoc = FreeCAD.newDocument(ModelName) print(Newdoc.Label) App.setActiveDocument(ModelName) App.ActiveDocument=App.getDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) color_keys = series_definition.color_keys obj_suffixes = series_definition.obj_suffixes colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys] cq_obj_data = module.generate_part(pincount) for i in range(len(cq_obj_data)): color_i = colors[i] + (0,) show(cq_obj_data[i], color_i) doc = FreeCAD.ActiveDocument doc.Label = ModelName objs=GetListOfObjects(FreeCAD, doc) for i in range(len(objs)): objs[i].Label = ModelName + obj_suffixes[i] restore_Main_Tools() out_dir='{:s}{:s}.3dshapes'.format(global_3dpath, lib_name) if not os.path.exists(out_dir): os.makedirs(out_dir) used_color_keys = color_keys export_file_name=out_dir+os.sep+FileName+'.wrl' export_objects = [] for i in range(len(objs)): export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=color_keys[i], face_colors=None)) scale=1/2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs, keepOriginals=True) exportSTEP(doc,FileName,out_dir,fusion) step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName) L.addLicenseToStep(out_dir, '{:s}.step'.\ format(FileName), LIST_license, module.LICENCE_Info.STR_licAuthor, module.LICENCE_Info.STR_licEmail, module.LICENCE_Info.STR_licOrgSys, module.LICENCE_Info.STR_licPreProc) FreeCAD.activeDocument().recompute() saveFCdoc(App, Gui, doc, FileName, out_dir) #FreeCADGui.activateWorkbench("PartWorkbench") if save_memory == False and check_Model==False: FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.activeDocument().activeView().viewAxometric() if save_memory == True or check_Model==True: doc=FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) if check_Model==True: runGeometryCheck(App, Gui, step_path, log, ModelName, save_memory=save_memory)
def make_3D_model(models_dir, variant): LIST_license = [ "", ] modelName = all_params[variant].modelName CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace( '(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument = Gui.getDocument(CheckedmodelName) case = make_case(all_params[variant]) casetop = make_case_top(all_params[variant]) if (all_params[variant].pintype == CASE_THT_TYPE): pins = make_pins_tht(all_params[variant]) if (all_params[variant].pintype == CASE_THT_N_TYPE): pins = make_pins_tht_n(all_params[variant]) if (all_params[variant].pintype == CASE_SMD_TYPE): pins = make_pins_smd(all_params[variant]) show(case) show(casetop) show(pins) #show(pinmark) #stop doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) body_color_key = all_params[variant].body_color_key body_top_color_key = all_params[variant].body_top_color_key pin_color_key = all_params[variant].pin_color_key body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat() body_top_color = shaderColors.named_colors[ body_top_color_key].getDiffuseFloat() pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat() Color_Objects(Gui, objs[0], body_color) Color_Objects(Gui, objs[1], body_top_color) Color_Objects(Gui, objs[2], pin_color) col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_body_top = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] col_pin = Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0] material_substitutions = { col_body[:-1]: body_color_key, col_body_top[:-1]: body_top_color_key, col_pin[:-1]: pin_color_key } expVRML.say(material_substitutions) while len(objs) > 1: FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) del objs objs = GetListOfObjects(FreeCAD, doc) doc.Label = CheckedmodelName del objs 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 + destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) 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) 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 + modelName + '.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) #scale=0.3937001 #exportVRML(doc,modelName,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, modelName, out_dir) #display BBox Gui.activateWorkbench("PartWorkbench") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric()
def make_3D_model(models_dir, variant): LIST_license = [ "", ] modelName = all_params[variant].modelName CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace( '(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument = Gui.getDocument(CheckedmodelName) case = make_case(all_params[variant], type, modelName) if (all_params[variant].type == CASE_THT_TYPE): pins = make_pins_tht(all_params[variant], type, modelName) if (all_params[variant].type == CASE_SMD_TYPE): pins = make_pins_smd(all_params[variant], type, modelName) # color_attr=case_color+(0,) # show(case, color_attr) # #FreeCAD.Console.PrintMessage(pins_color) # color_attr=pins_color+(0,) # #FreeCAD.Console.PrintMessage(color_attr) # show(pins, color_attr) #doc = FreeCAD.ActiveDocument #objs=GetListOfObjects(FreeCAD, doc) show(case) show(pins) #show(pinmark) #stop 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) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label = CheckedmodelName del objs #objs=GetListOfObjects(FreeCAD, doc) #FuseObjs_wColors(FreeCAD, FreeCADGui, # doc.Name, objs[0].Name, objs[1].Name) #doc.Label=modelName objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = CheckedmodelName restore_Main_Tools() # objs=GetListOfObjects(FreeCAD, doc) # objs[0].Label=modelName # restore_Main_Tools() #rotate if required if (all_params[variant].rotation != 0): rot = all_params[variant].rotation z_RotateObject(doc, rot) npins = all_params[variant].npins e = all_params[variant].e E = all_params[variant].E c = 0.254 # lead thickness mvY = (npins * e / 4 - e / 2) mvX = (E - c) / 2 s = objs[0].Shape shape = s.copy() shape.Placement = s.Placement shape.translate((+mvX, -mvY, 0)) objs[0].Placement = shape.Placement #case = case.translate ((-mvX,-mvY,0)) #pins = pins.translate ((-mvX,-mvY,0)) # out_dir=destination_dir # if not os.path.exists(out_dir): # os.makedirs(out_dir) # #out_dir="./generated_qfp/" # # export STEP model # exportSTEP(doc,modelName,out_dir) script_dir = os.path.dirname(os.path.realpath(__file__)) #models_dir=script_dir+"/../_3Dmodels" expVRML.say(models_dir) out_dir = models_dir + destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) #out_dir="./generated_qfp/" # export STEP model 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 expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) #scale=0.3937001 #exportVRML(doc,modelName,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, modelName, out_dir) #display BBox Gui.activateWorkbench("PartWorkbench") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric()
body = body.cut(lowerbar) body = body.cut(front_U_cut) body = body.cut(top_side_L_cut) body = body.cut(bottom_side_L_cut) body = body.cut(body_top_square_hole) body = body.translate((0,body_off_center_y,0)) return body #return bottom_cutout def generate_part(params): pins = generate_pins(params) body = generate_body(params) body_length=params.body_length body = body.translate((0,0,body_off_center_z)) #made an error, need to rotate it by 180 degree center_x=body_corner_x+body_length/2 # pins = pins.rotate((center_x,0,0),(0,0,1),180) # body = body.rotate((center_x,0,0),(0,0,1),180) return (body, pins) #opend from within freecad if "module" in __name__ : params=series_params.variant_params['side_entry']['param_generator'](6) #params=series_params.variant_params['side_entry']['param_generator'](3) (body, pins) = generate_part(params) body = body.translate((0,0,body_off_center_z)) show(pins) show(body)
print( "Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace( '(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument = Gui.getDocument(CheckedModelName) #body, base, mark, pins = make_radial_th(all_params[variant]) body, base, mark, pins, top = make_radial_th( all_params[variant]) #body, base, mark, pins, top show(body) show(base) show(pins) show(mark) show(top) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) Color_Objects(Gui, objs[0], body_color) Color_Objects(Gui, objs[1], base_color) Color_Objects(Gui, objs[2], pins_color) Color_Objects(Gui, objs[3], mark_color) Color_Objects(Gui, objs[4], top_color) col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0]
.lineTo((body_width+body_corner_y), bottom_cutout_depth)\ .vLineTo(0).close().extrude(bottom_cutout_width) for i in range(0, num_pins): body = body.cut(bottom_cutout.translate((i * pin_pitch, 0, 0))) return body #return bottom_cutout def generate_part(part_key): pins = generate_pins(all_params[part_key]) body = generate_body(all_params[part_key]) body_lenght = all_params[part_key].body_length #made an error, need to rotate it by 180 degree center_x = body_corner_x + body_lenght / 2 pins = pins.rotate((center_x, 0, 0), (0, 0, 1), 180) body = body.rotate((center_x, 0, 0), (0, 0, 1), 180) return (pins, body) #opend from within freecad if "module" in __name__: part_to_build = "S02B_XH_A" #part_to_build = "B02B_XH_A" FreeCAD.Console.PrintMessage("Started from cadquery: Building " + part_to_build + "\n") (pins, body) = generate_part(part_to_build) show(pins) show(body)
def make(self): show(self.make_body()) show(self.make_pins()) show(self.make_buttons()) show(self.make_pinmark(self.button_width + 0.2))
def generateOneModel(params, log): excluded_pins_x=() ##no pin excluded excluded_pins_xmirror=() ##no pin excluded place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) ModelName = params.modelName FreeCAD.Console.PrintMessage( '\n\n############## ' + ModelName + ' ###############\n') CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) #case, pins, pinmark = make_case(params) case_bot, case, pins, pinmark = make_case(params) if case_bot is not None: show(case_bot) show(case) show(pins) show(pinmark) #stop doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) if case_bot is not None: Color_Objects(Gui,objs[0],body_bot_color) Color_Objects(Gui,objs[1],body_color) Color_Objects(Gui,objs[2],pins_color) Color_Objects(Gui,objs[3],marking_color) col_body_bot=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_body=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0] col_mark=Gui.ActiveDocument.getObject(objs[3].Name).DiffuseColor[0] material_substitutions={ col_body_bot[:-1]:body_bot_color_key, col_body[:-1]:body_color_key, col_pin[:-1]:pins_color_key, col_mark[:-1]:marking_color_key } expVRML.say(material_substitutions) if (color_pin_mark==True) and (place_pinMark==True): CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[1].Name, objs[3].Name) else: #removing pinMark App.getDocument(doc.Name).removeObject(objs[3].Name) ### #sleep del objs objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) else: 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) if (color_pin_mark==True) and (place_pinMark==True): CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name) else: #removing pinMark App.getDocument(doc.Name).removeObject(objs[2].Name) ### #sleep del objs objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) ## objs[0].Label='body' ## objs[1].Label='pins' ## objs[2].Label='mark' ### ## print objs[0].Name, objs[1].Name, objs[2].Name ## sleep doc.Label=CheckedModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=CheckedModelName restore_Main_Tools() #rotate if required if (params.rotation!=0): rot= params.rotation z_RotateObject(doc, rot) #out_dir=destination_dir+params.dest_dir_prefix+'/' script_dir=os.path.dirname(os.path.realpath(__file__)) #models_dir=script_dir+"/../_3Dmodels" #expVRML.say(models_dir) if len(params.dest_dir_prefix)>=1: out_dir=models_dir+destination_dir+os.sep+params.dest_dir_prefix else: out_dir=models_dir+destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) #out_dir="./generated_qfp/" # export STEP model exportSTEP(doc, ModelName, out_dir) global LIST_license 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) 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 added creaeAngle expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license, 0.9) # Save the doc in Native FC format #saveFCdoc(App, Gui, doc, ModelName,out_dir) #display BBox #FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True if footprints_dir is not None and os.path.isdir(footprints_dir) and not save_memory and not check_Model: #it doesn't make sense to import the footprint right before we close the file. #expVRML.say (ModelName) #stop sys.argv = ["fc", "dummy", footprints_dir+os.sep+ModelName, "savememory"] #setup = get_setup_file() # << You need the parentheses expVRML.say(sys.argv[2]) if not ksu_present: try: import kicadStepUptools ksu_present=True expVRML.say("ksu present!") kicadStepUptools.KSUWidget.close() #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized) #kicadStepUptools.KSUWidget.destroy() #for i in QtGui.qApp.topLevelWidgets(): # if i.objectName() == "kicadStepUp": # i.deleteLater() kicadStepUptools.KSUWidget.close() except: ksu_present=False expVRML.say("ksu not present") else: kicadStepUptools.KSUWidget.close() reload(kicadStepUptools) kicadStepUptools.KSUWidget.close() #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized) #kicadStepUptools.KSUWidget.destroy() #FreeCADGui.insert(u"C:\Temp\FCAD_sg\QFN_packages\QFN-12-1EP_3x3mm_Pitch0_5mm.kicad_mod") #FreeCADGui.insert(script_dir+os.sep+"ModelName.kicad_mod") if save_memory == False: Gui.activateWorkbench("PartWorkbench") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewBottom() #Gui.activeDocument().activeView().viewAxometric() saveFCdoc(App, Gui, doc, ModelName,out_dir) if save_memory == True or check_Model==True: doc=FreeCAD.ActiveDocument print("closing: {}".format(doc.Name)) FreeCAD.closeDocument(doc.Name) if check_Model==True: step_path = out_dir + '/' + ModelName + ".step" runGeometryCheck(App, Gui, step_path, log, ModelName, save_memory=save_memory)
variants = all_params.keys() else: variants = [model_to_build] for variant in variants: FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) case, pins = make_qfp(all_params[variant]) show(case, (80, 80, 80, 0)) show(pins) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=ModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=ModelName restore_Main_Tools() #rotate if required if (all_params[variant].rotation!=0): rot= all_params[variant].rotation z_RotateObject(doc, rot) out_dir=destination_dir
continue print("building %s" % model) ModelName = model CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) base, top, pins, pinmark, package_found = make_chip(model, all_params) if package_found == False: print("package_type is not recognized") continue top_color_key = all_params[model]['color'] top_color = shaderColors.named_colors[top_color_key].getDiffuseFloat() show(base) show(top) show(pins) show(pinmark) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],top_color) Color_Objects(Gui,objs[2],pins_color) Color_Objects(Gui,objs[3],pinmark_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_top=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] col_pins=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0]
models = [model_to_build] for model in models: if not model in all_params.keys(): print("Parameters for %s doesn't exist in 'all_params', skipping." % model) continue ModelName = model CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) body, pins, top = make_chip(model, all_params) show(body) show(pins) show(top) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],top_color) Color_Objects(Gui,objs[2],pins_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_top=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[2].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:body_color_key,
def make_3D_model(models_dir, variant): LIST_license = ["",] modelName = all_params[variant].modelName CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument=Gui.getDocument(CheckedmodelName) if (all_params[variant].serie == 'RV_Disc'): case = make_case_RV_Disc(all_params[variant]) pins = make_pins_RV_Disc(all_params[variant]) show(case) show(pins) else: print("Serie " + all_params[variant].serie + " is not supported") FreeCAD.Console.PrintMessage('\r\nSerie ' + all_params[variant].serie + ' is not supported\r\n') sys.exit() #show(pinmark) #stop doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) FreeCAD.Console.PrintMessage('#1\r\n') body_color_key = all_params[variant].body_color_key pin_color_key = all_params[variant].pin_color_key body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat() pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat() FreeCAD.Console.PrintMessage('#2\r\n') Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],pin_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] FreeCAD.Console.PrintMessage('#3\r\n') material_substitutions={ col_body[:-1]:body_color_key, col_pin[:-1]:pin_color_key } expVRML.say(material_substitutions) while len(objs) > 1: FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) del objs objs = GetListOfObjects(FreeCAD, doc) doc.Label = CheckedmodelName del objs 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+destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) 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) FreeCAD.Console.PrintMessage('#4\r\n') # scale and export Vrml model scale=1/2.54 #exportVRML(doc,modelName,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+modelName+'.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) #scale=0.3937001 #exportVRML(doc,modelName,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, modelName,out_dir) #display BBox Gui.activateWorkbench("PartWorkbench") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric()
notch2 = notch1.mirror("YZ") notches = notch1.union(notch2) body = body.cut(notches) return body def generate_part(num_pins): calc_dim = dimensions(num_pins) body = generate_body(num_pins, calc_dim) contacts = generate_contacts(num_pins, calc_dim) return (body, contacts) # opened from within freecad if "module" in __name__: num_pins = 16 # part_to_build = 'molex_54722_2x15' # part_to_build = 'molex_54722_2x17' # part_to_build = 'molex_54722_2x40' FreeCAD.Console.PrintMessage("Started from CadQuery: building " + str(num_pins) + "pins variant\n") (body, contacts) = generate_part(num_pins) show(body) show(contacts)
excluded_pins_xmirror=() ##no pin excluded place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '') CheckedModelName = CheckedModelName.replace('-', '_') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) case_bot, case, pins, pinmark = make_qfn(all_params[variant]) show(case_bot) show(case) show(pins) show(pinmark) #stop doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_bot_color) Color_Objects(Gui,objs[1],body_color) Color_Objects(Gui,objs[2],pins_color) Color_Objects(Gui,objs[3],marking_color) col_body_bot=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_body=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0]
place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '') CheckedModelName = CheckedModelName.replace('-', '_') Newdoc = FreeCAD.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) case, pins, pinmark = make_qfn(all_params[variant]) show(case) show(pins) show(pinmark) #stop 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={
# Spline path generated from our list of points (tuples) path = cadquery.Workplane("XZ").spline(pts) # Sweep a circle with a diameter of 1.0 units along the spline path we just created defaultSweep = cadquery.Workplane("XY").circle(1.0).sweep(path) # Sweep defaults to making a solid and not generating a Frenet solid. Setting Frenet to True helps prevent creep in # the orientation of the profile as it is being swept frenetShell = cadquery.Workplane("XY").circle(1.0).sweep(path, makeSolid=False, isFrenet=True) # We can sweep shapes other than circles defaultRect = cadquery.Workplane("XY").rect(1.0, 1.0).sweep(path) # Switch to a polyline path, but have it use the same points as the spline path = cadquery.Workplane("XZ").polyline(pts) # Using a polyline path leads to the resulting solid having segments rather than a single swept outer face plineSweep = cadquery.Workplane("XY").circle(1.0).sweep(path) # Switch to an arc for the path path = cadquery.Workplane("XZ").threePointArc((1.0, 1.5), (0.0, 1.0)) # Use a smaller circle section so that the resulting solid looks a little nicer arcSweep = cadquery.Workplane("XY").circle(0.5).sweep(path) # Translate the resulting solids so that they do not overlap and display them left to right show(defaultSweep) show(frenetShell.translate((5, 0, 0))) show(defaultRect.translate((10, 0, 0))) show(plineSweep.translate((15, 0, 0))) show(arcSweep.translate((20, 0, 0)))
else: variants = [model_to_build] for variant in variants: FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in M.all_params: print("Parameters for %s doesn't exist in 'M.all_params', skipping." % variant) continue ModelName = M.all_params[variant].model_name FileName = M.all_params[variant].file_name Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) (pins, body) = M.generate_part(variant) color_attr = body_color + (0,) show(body, color_attr) color_attr = pins_color + (0,) show(pins, color_attr) doc = FreeCAD.ActiveDocument doc.Label=ModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label = ModelName + "__body" objs[1].Label = ModelName + "__pins" restore_Main_Tools() out_dir=destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir)
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")
variants = [model_to_build] for variant in variants: FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) case, pins = make_inductor(all_params[variant]) show(case) show(pins) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],pins_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:body_color_key, col_pin[:-1]:pins_color_key }
def make_3D_model(models_dir, variant): LIST_license = ["",] FreeCAD.Console.PrintMessage("\r\nMaking %s\r\n" % variant) modelName = variant modelfileName = '' CheckedmodelName = modelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedmodelName) App.setActiveDocument(CheckedmodelName) Gui.ActiveDocument=Gui.getDocument(CheckedmodelName) case = None pins = None if all_params[variant].modeltype == 'BX0036': case = make_case_BX0036(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif all_params[variant].modeltype == 'Button1': case = make_case_Button1(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif all_params[variant].modeltype == 'Button2': case = make_case_Button2(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif all_params[variant].modeltype == 'Button3': case = make_case_Button3(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif all_params[variant].modeltype == 'Button4': case = make_case_Button4(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif all_params[variant].modeltype == 'Cylinder1': case = make_case_Cylinder1(all_params[variant]) pins = make_pins(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif variant == 'Seiko_MS621F': case = make_case_Seiko_MS621F(all_params[variant]) pins = make_pins_Seiko_MS621F(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # elif variant == 'Keystone_2993': case = make_case_Keystone_2993(all_params[variant]) pins = make_pins_Keystone_2993(all_params[variant]) show(case) show(pins) modelfileName = make_modelfileName_Common(all_params[variant]) # # else: FreeCAD.Console.PrintMessage("\r\nSerie %s does not exist, skipping'\r\n" % all_params[variant].serie) return #show(pinmark) #stop doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) body_color_key = all_params[variant].body_color_key pin_color_key = all_params[variant].pin_color_key body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat() pin_color = shaderColors.named_colors[pin_color_key].getDiffuseFloat() Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],pin_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:body_color_key, col_pin[:-1]:pin_color_key } expVRML.say(material_substitutions) while len(objs) > 1: FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) del objs objs = GetListOfObjects(FreeCAD, doc) doc.Label = CheckedmodelName del objs 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 + all_params[variant].dest_dir_prefix if not os.path.exists(out_dir): os.makedirs(out_dir) exportSTEP(doc, modelfileName, out_dir) if LIST_license[0]=="": LIST_license=Lic.LIST_int_license LIST_license.append("") Lic.addLicenseToStep(out_dir + os.sep, modelfileName + ".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc) # scale and export Vrml model scale=1/2.54 #exportVRML(doc, modelfileName,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 + modelfileName + '.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) #expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys)# , LIST_license expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) #scale=0.3937001 #exportVRML(doc, modelfileName,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, modelfileName, out_dir) #display BBox Gui.activateWorkbench("PartWorkbench") Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric()
def export_one_part(params, series_definition, log): ModelName = params.modelName footprint_dir = series_definition.footprint_dir CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') print('\n######################### {:s} ###########################\n'.format(ModelName)) Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) App.ActiveDocument=App.getDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) color_keys = [ series_definition.body_color_key, series_definition.pins_color_key, series_definition.mark_color_key ] colors = [shaderColors.named_colors[key].getDiffuseInt() for key in color_keys] body, pins, mark = make_gw(params) show(body, colors[0]+(0,)) show(pins, colors[1]+(0,)) show(mark, colors[2]+(0,)) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) 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]:series_definition.body_color_key, col_pin[:-1]:series_definition.pins_color_key, col_mark[:-1]:series_definition.mark_color_key } if (color_pin_mark==True) and (place_pinMark==True): CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name) else: #removing pinMark App.getDocument(doc.Name).removeObject(objs[2].Name) 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() #rotate if required if (params.rotation!=0): rot= params.rotation z_RotateObject(doc, rot) if no_export: return out_dir='{:s}{:s}.3dshapes'.format(global_3dpath, series_definition.lib_name) if not os.path.exists(out_dir): os.makedirs(out_dir) #out_dir="./generated_qfp/" # export STEP model exportSTEP(doc, ModelName, out_dir) global LIST_license 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) 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 doc in Native FC format footprint_dir = series_definition.footprint_dir if footprint_dir is not None and os.path.isdir(footprint_dir) \ and not save_memory and not check_Model: #expVRML.say (ModelName) #stop sys.argv = ["fc", "dummy", footprint_dir+os.sep+ModelName, "savememory"] #setup = get_setup_file() # << You need the parentheses expVRML.say(sys.argv[2]) ksu_already_loaded=False ksu_present=False for i in QtGui.qApp.topLevelWidgets(): if i.objectName() == "kicadStepUp": ksu_already_loaded=True ksu_tab = FreeCADGui.getMainWindow().findChild(QtGui.QDockWidget, "kicadStepUp") #"kicad StepUp 3D tools") if ksu_tab: ksu_already_loaded=True if ksu_already_loaded!=True: try: import kicadStepUptools ksu_present=True ksu_already_loaded=True kicadStepUptools.KSUWidget.close() #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized) #kicadStepUptools.KSUWidget.destroy() #for i in QtGui.qApp.topLevelWidgets(): # if i.objectName() == "kicadStepUp": # i.deleteLater() kicadStepUptools.KSUWidget.close() except: ksu_present=False expVRML.say("ksu not present") else: kicadStepUptools.KSUWidget.close() reload(kicadStepUptools) kicadStepUptools.KSUWidget.close() #kicadStepUptools.KSUWidget.setWindowState(QtCore.Qt.WindowMinimized) #kicadStepUptools.KSUWidget.destroy() saveFCdoc(App, Gui, doc, ModelName,out_dir) #FreeCADGui.activateWorkbench("PartWorkbench") if save_memory == False and check_Model==False: FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.activeDocument().activeView().viewAxometric() if save_memory == True or check_Model==True: doc=FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) if check_Model==True: runGeometryCheck(App, Gui, out_dir+'/'+ ModelName+".step", log, ModelName, save_memory=save_memory)
# This example is meant to be used from within the CadQuery module of FreeCAD. import cadquery from Helpers import show # The dimensions of the box. These can be modified rather than changing the # object's code directly. length = 80.0 height = 60.0 thickness = 10.0 center_hole_dia = 22.0 cbore_hole_diameter = 2.4 cbore_diameter = 4.4 cbore_depth = 2.1 # Create a 3D box based on the dimensions above and add 4 counterbored holes result = cadquery.Workplane("XY").box(length, height, thickness) \ .faces(">Z").workplane().hole(center_hole_dia) \ .faces(">Z").workplane() \ .rect(length - 8.0, height - 8.0, forConstruction=True) \ .vertices().cboreHole(cbore_hole_diameter, cbore_diameter, cbore_depth) # Render the solid show(result)
for variant in variants: FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) case, top, pins = make_chip(all_params[variant]) color_attr=case_color+(0,) show(case, color_attr) #FreeCAD.Console.PrintMessage(pins_color) color_attr=top_color+(0,) show(top, color_attr) color_attr=pins_color+(0,) #FreeCAD.Console.PrintMessage(color_attr) show(pins, color_attr) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) objs[1].Label="Fusion2" FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=ModelName objs=GetListOfObjects(FreeCAD, doc)
def export_one_part(modul, variant, with_plug=False): if not variant in modul.all_params: FreeCAD.Console.PrintMessage( "Parameters for %s not found - skipping." % variant) return ModelName = variant ModelName = ModelName.replace(".", "_") FileName = modul.all_params[variant].file_name FreeCAD.Console.PrintMessage("Model name: %s\r\n" % ModelName) FreeCAD.Console.PrintMessage("File name: %s\r\n" % FileName) Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) App.ActiveDocument = App.getDocument(ModelName) Gui.ActiveDocument = Gui.getDocument(ModelName) (pins, body) = modul.generate_part(variant, with_plug) color_attr = body_color + (0, ) show(body, color_attr) color_attr = pins_color + (0, ) show(pins, color_attr) doc = FreeCAD.ActiveDocument doc.Label = ModelName objs = FreeCAD.ActiveDocument.Objects FreeCAD.Console.PrintMessage(objs) i = 0 objs[i].Label = ModelName + "__body" i += 1 objs[i].Label = ModelName + "__pins" i += 1 restore_Main_Tools() if not os.path.exists(out_dir): os.makedirs(out_dir) used_color_keys = [body_color_key, pins_color_key] export_file_name = out_dir + os.sep + FileName + '.wrl' export_objects = [] i = 0 export_objects.append( expVRML.exportObject(freecad_object=objs[i], shape_color=body_color_key, face_colors=None)) i += 1 export_objects.append( expVRML.exportObject(freecad_object=objs[i], shape_color=pins_color_key, face_colors=None)) i += 1 scale = 1 / 2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, L.LIST_int_license) fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs, keepOriginals=True) exportSTEP(doc, FileName, out_dir, fusion) L.addLicenseToStep(out_dir+'/', FileName+".step", L.LIST_int_license,\ L.STR_int_licAuthor, L.STR_int_licEmail, L.STR_int_licOrgSys, L.STR_int_licPreProc) saveFCdoc(App, Gui, doc, FileName, out_dir) FreeCAD.activeDocument().recompute() FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.activeDocument().activeView().viewAxometric()
for variant in variants: FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) case, die = make_chip(all_params[variant]) show(case) show(die) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) Color_Objects(Gui,objs[0],body_color) Color_Objects(Gui,objs[1],die_color) col_body=Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_die=Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions={ col_body[:-1]:body_color_key, col_die[:-1]:die_color_key }
print( "Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace( '(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument = Gui.getDocument(CheckedModelName) case, pins = make_inductor(all_params[variant]) show(case) show(pins) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) Color_Objects(Gui, objs[0], body_color) Color_Objects(Gui, objs[1], pins_color) col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions = { col_body[:-1]: body_color_key, col_pin[:-1]: pins_color_key }
leads = leads.translate((F / 2, 0, 0)) angle = rot body = body.rotate((0, 0, 0), (0, 0, 1), angle) mmb = mmb.rotate((0, 0, 0), (0, 0, 1), angle) bar = bar.rotate((0, 0, 0), (0, 0, 1), angle) top = top.rotate((0, 0, 0), (0, 0, 1), angle) leads = leads.rotate((0, 0, 0), (0, 0, 1), angle) #show(body) #show(mmb) #show(bar) #show(leads) #show(top) #stop return (body, mmb, bar, leads, top) #body, base, mark, pins, top if "module" in __name__: variant = "CP_Axial_L10.0mm_D6.0mm_P15.00mm_Horizontal" body, mmb, bar, leads, top = generate_part( all_params[variant]) #body, base, mark, pins, top show(body) show(mmb) show(bar) show(leads) show(top)
def main(arg_model_to_build='AKA',arg_color_pin_mark=True): FreeCAD.Console.PrintMessage('\r\nRunning...\r\n') model_to_build=arg_model_to_build color_pin_mark=arg_color_pin_mark global excluded_pins_xmirror global excluded_pins_x ## maui run() # ## if (not "modelName" in all_params['AKA']): # ## ModelName = "newModel" # "LQFP64_p05_h12" # ## else: # ## ModelName = all_params.modelName # color_pin_mark=True # if len(sys.argv) < 3: # FreeCAD.Console.PrintMessage('No variant name is given! building AKA') # model_to_build='AKA' # else: # model_to_build=sys.argv[2] # if len(sys.argv)==4: # FreeCAD.Console.PrintMessage(sys.argv[3]+'\r\n') # if (sys.argv[3].find('no-pinmark-color')!=-1): # color_pin_mark=False # else: # color_pin_mark=True #++++++++++++++++++++++++++++++++ #----------------------- #FreeCAD.Console.PrintMessage(str(color_pin_mark)+'\r\n') #FreeCAD.Console.PrintMessage(str(sys.argv[3].find('no-pinmark-color'))) if model_to_build == "all": variants = all_params.keys() else: variants = [model_to_build] for variant in variants: if variant == 'SOT23_3' or variant == 'SC70_3': excluded_pins_x=(1,) ##used to build sot23-3; sc70 (asimmetrical pins, no pinmark) excluded_pins_xmirror=(0,2,) place_pinMark=False ##used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) elif variant == 'SOT23_5': excluded_pins_x=() ##used to build sot23-3; sc70 (asimmetrical pins, no pinmark) excluded_pins_xmirror=(1,) place_pinMark=False ##used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) else: excluded_pins_x=() ##no pin excluded excluded_pins_xmirror=() ##no pin excluded place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) case, pins, pinmark = make_gw(all_params[variant]) color_attr=case_color+(0,) show(case, color_attr) color_attr=pins_color+(0,) show(pins, color_attr) color_attr=mark_color+(0,) show(pinmark, color_attr) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) ## objs[0].Label='body' ## objs[1].Label='pins' ## objs[2].Label='mark' ### ## print objs[0].Name, objs[1].Name, objs[2].Name ## sleep #if place_pinMark==True: if (color_pin_mark==True) and (place_pinMark==True): CutObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[2].Name) else: #removing pinMark App.getDocument(doc.Name).removeObject(objs[2].Name) ### #sleep del objs objs=GetListOfObjects(FreeCAD, doc) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label=ModelName objs=GetListOfObjects(FreeCAD, doc) objs[0].Label=ModelName restore_Main_Tools() #rotate if required if (all_params[variant].rotation!=0): rot= all_params[variant].rotation z_RotateObject(doc, rot) #out_dir=destination_dir+all_params[variant].dest_dir_prefix+'/' script_dir=os.path.dirname(os.path.realpath(__file__)) out_dir=script_dir+destination_dir+all_params[variant].dest_dir_prefix+'/' if not os.path.exists(out_dir): os.makedirs(out_dir) #out_dir="./generated_qfp/" # export STEP model exportSTEP(doc,ModelName,out_dir) # scale and export Vrml model scale=0.3937001 exportVRML(doc,ModelName,scale,out_dir) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, ModelName,out_dir) #display BBox FreeCADGui.ActiveDocument.getObject("Part__Feature").BoundingBox = True Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric()
excluded_pins_x=() ##no pin excluded excluded_pins_xmirror=() ##no pin excluded place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName CheckedModelName = ModelName.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') Newdoc = App.newDocument(CheckedModelName) App.setActiveDocument(CheckedModelName) Gui.ActiveDocument=Gui.getDocument(CheckedModelName) body, pins, mark = make_Smx(all_params[variant]) show(body) show(pins) show(mark) 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],mark_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,
def generate_package3d(params, part_params, mpn): # License information if LICENCE_Info.LIST_license[0] == "": LIST_license = add_license.LIST_int_license else: LIST_license = LICENCE_Info.LIST_license LIST_license[0] = "Copyright (C) " + datetime.datetime.now().strftime( "%Y") + ", " + LICENCE_Info.STR_licAuthor # Build model name model_name = "Connector_Wuerth_{series_prefix}_{type}_{rows}x{pins:02d}_P{pitch}_{orientation}_{mpn}".format( series_prefix=params['series_prefix'], type=params['type'], rows=part_params['rows'], pins=part_params['pins'] // 2, pitch=params['pitch'], orientation=params['orientation'], mpn=mpn) FreeCAD.Console.PrintMessage('\r\nGenerate: ' + model_name + '\r\n') # Create new document doc = FreeCAD.newDocument("doc") App.setActiveDocument("doc") App.ActiveDocument = App.getDocument("doc") Gui.ActiveDocument = Gui.getDocument("doc") # Generate body body_color_key = "black body" body_color = shaderColors.named_colors[body_color_key].getDiffuseFloat() body = generate_body(params, part_params) show(body, body_color + (0, )) # Generate pins pins_color_key = "gold pins" pins_color = shaderColors.named_colors[pins_color_key].getDiffuseFloat() pins = generate_pins(params, part_params) show(pins, pins_color + (0, )) # Finalize doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) restore_Main_Tools() col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions = { col_body[:-1]: body_color_key, col_pin[:-1]: pins_color_key } expVRML.say(material_substitutions) # Create output directory output_dir = 'Connector_Wuerth_{series_prefix}_Bottom-Entry.3dshapes/'.format( series_prefix=params['series_prefix']) if not os.path.isdir(output_dir): os.makedirs(output_dir) filename = '{output_dir:s}{model_name:s}.wrl'.format(output_dir=output_dir, model_name=model_name) # Export wrl file export_objects, used_color_keys = expVRML.determineColors( Gui, objs, material_substitutions) colored_meshes = expVRML.getColoredMesh(Gui, export_objects, 1 / 2.54) expVRML.writeVRMLFile(colored_meshes, filename, used_color_keys, LIST_license) # Export step file exportSTEP(doc, model_name, output_dir, objs[0]) add_license.addLicenseToStep( output_dir, '{model_name}.step'.format(model_name=model_name), LIST_license, LICENCE_Info.STR_licAuthor, LICENCE_Info.STR_licEmail, LICENCE_Info.STR_licOrgSys, LICENCE_Info.STR_licPreProc) # Force recompute FreeCAD.activeDocument().recompute() # Save FCStd document saveFCdoc(App, Gui, doc, model_name, output_dir) # Close document doc = FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name)
if 'TO252' in packages: build_list.append(TO252(self.config_file)) if 'TO263' in packages: build_list.append(TO263(self.config_file)) if 'TO268' in packages: build_list.append(TO268(self.config_file)) if 'ATPAK' in packages: build_list.append(ATPAK(self.config_file)) if 'HSOF8' in packages: build_list.append(HSOF8(self.config_file)) if 'SOT669' in packages: build_list.append(SOT669(self.config_file)) if 'SOT89' in packages: build_list.append(SOT89(self.config_file)) return build_list # opened from within FreeCAD if "module" in __name__: print("Started from CadQuery workbench ...") CONFIG = '{path:s}/DPAK_config.yaml'.format(path=os.environ.get("MYSCRIPT_DIR")) series = HSOF8(CONFIG) model = series.build_series(verbose=True).next() for key in model.keys(): if key is not '__name': show(model[key]['part'])
def MakePart(params, name, n=1): global formerDOC global LIST_license #name = PartName(params, 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__)) expVRML.say(models_dir) out_dir = models_dir + destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) #having a period '.' character in the model name REALLY messes with things. also '-' docname = name.replace(".", "").replace("-", "_") newdoc = App.newDocument(docname) App.setActiveDocument(docname) App.ActiveDocument = App.getDocument(docname) Gui.ActiveDocument = Gui.getDocument(docname) FreeCAD.Console.PrintMessage(params) pins_output = MakeResistorPin(params, n) base_output = MakeResistor(params, n) show(base_output) show(pins_output) doc = FreeCAD.ActiveDocument objs = GetListOfObjects(FreeCAD, doc) # select the color based on shape if (params.shape == "power") or (params.shape == "radial") or (params.shape == "shunt"): # white colour for power resistors chosen_body_color = ceramic_color chosen_body_color_key = ceramic_color_key elif (params.shape == "bare"): # metal/pin colour for bare resistors chosen_body_color = pins_color chosen_body_color_key = pins_color_key else: # light brown colour for din/axial/arrays/etc. chosen_body_color = body_color chosen_body_color_key = body_color_key Color_Objects(Gui, objs[0], chosen_body_color) Color_Objects(Gui, objs[1], pins_color) col_body = Gui.ActiveDocument.getObject(objs[0].Name).DiffuseColor[0] col_pin = Gui.ActiveDocument.getObject(objs[1].Name).DiffuseColor[0] material_substitutions = { col_body[:-1]: chosen_body_color_key, col_pin[:-1]: pins_color_key, } expVRML.say(material_substitutions) FuseObjs_wColors(FreeCAD, FreeCADGui, doc.Name, objs[0].Name, objs[1].Name) doc.Label = docname objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = docname restore_Main_Tools() doc.Label = docname #save the STEP file exportSTEP(doc, name, out_dir) if LIST_license[0] == "": LIST_license = Lic.LIST_int_license LIST_license.append("") Lic.addLicenseToStep(out_dir+'/', name+".step", LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licOrg, STR_licPreProc) # scale and export Vrml model scale = 1 / 2.54 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 + name + '.wrl' colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) if save_memory == False: Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() # Save the doc in Native FC format saveFCdoc(App, Gui, doc, name, out_dir) if save_memory == True: closeCurrentDoc(docname) return 0
excluded_pins_x=() ##no pin excluded excluded_pins_xmirror=() ##no pin excluded place_pinMark=True ##default =True used to exclude pin mark to build sot23-3; sot23-5; sc70 (asimmetrical pins, no pinmark) FreeCAD.Console.PrintMessage('\r\n'+variant) if not variant in all_params: print("Parameters for %s doesn't exist in 'all_params', skipping." % variant) continue ModelName = all_params[variant].modelName Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) case, pins, pinmark = make_tantalum(all_params[variant]) color_attr=case_color+(0,) show(case, color_attr) color_attr=pins_color+(0,) show(pins, color_attr) color_attr=mark_color+(0,) show(pinmark, color_attr) doc = FreeCAD.ActiveDocument objs=GetListOfObjects(FreeCAD, doc) ## objs[0].Label='body' ## objs[1].Label='pins' ## objs[2].Label='mark' ### ## print objs[0].Name, objs[1].Name, objs[2].Name ##sleep #if place_pinMark==True:
screw = screw.faces(">Z").workplane()\ .circle(thread_r).extrude(pcb_thickness+0.1) screw = screw.faces("<Z").edges().fillet(head_fillet) screw = screw.faces("<Z").workplane()\ .rect(head_radius*2,slot_width).cutBlind(-slot_depth) screw = screw.union(screw.translate((2*mount_hole_to_pin+(num_pins-1)*pin_pitch,0,0))) return screw def generate_part(part_key): params = all_params[part_key] calc_dim = dimensions(params) pins = generate_pins(params) body, insert = generate_body(params, calc_dim) mount_screw = generate_mount_screw(params, calc_dim) return (pins, body, insert, mount_screw) #opend from within freecad if "module" in __name__ : part_to_build = "MSTB_01x02_5.00mm_MH" FreeCAD.Console.PrintMessage("Started from cadquery: Building " +part_to_build+"\n") (pins, body, insert, mount_screw) = generate_part(part_to_build) show(pins) show(body) if insert is not None: show(insert) if mount_screw is not None: show(mount_screw)
def export_model(model): file_name = model['metadata']['name'] parts = model['parts'] parts_list = parts.keys() # create document safe_name = file_name.replace('-', '_') FreeCAD.Console.PrintMessage('Model: {:s}\r\n'.format(file_name)) FreeCAD.newDocument(safe_name) App.setActiveDocument(safe_name) App.ActiveDocument = App.getDocument(safe_name) Gui.ActiveDocument = Gui.getDocument(safe_name) # colour model used_colour_keys = [] for part in parts_list: colour_key = parts[part]['colour'] used_colour_keys.append(colour_key) colour = shaderColors.named_colors[colour_key].getDiffuseInt() colour_attr = colour + (0,) show(parts[part]['name'], colour_attr) # label model and parts doc = FreeCAD.ActiveDocument doc.Label=safe_name objects=doc.Objects i = 0 for part in parts_list: objects[i].Label = '{n:s}__{p:s}'.format(n=safe_name, p=part) i += 1 restore_Main_Tools() doc.recompute() FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.activeDocument().activeView().viewTop() # create output folder if not os.path.exists(out_dir): os.makedirs(out_dir) # export VRML export_file_name = '{d:s}{s:s}{n:s}.wrl'.format(d=out_dir, s=os.sep, n=file_name) export_objects = [] i = 0 for part in parts_list: export_objects.append(expVRML.exportObject(freecad_object=objects[i], shape_color=parts[part]['colour'], face_colors=None)) i += 1 scale = 1 / 2.54 coloured_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) L.LIST_int_license[0] = "Copyright (C) " + datetime.now().strftime("%Y") + ", " + L.STR_int_licAuthor expVRML.writeVRMLFile(coloured_meshes, export_file_name, used_colour_keys, L.LIST_int_license) # export STEP fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui, safe_name, objects, keepOriginals=True) exportSTEP(doc, file_name, out_dir, fusion) L.addLicenseToStep('{d:s}/'.format(d=out_dir), '{n:s}.step'.format(n=file_name), L.LIST_int_license, L.STR_int_licAuthor, L.STR_int_licEmail, L.STR_int_licOrgSys, L.STR_int_licPreProc) # save FreeCAD models saveFCdoc(App, Gui, doc, file_name, out_dir) return
def export_one_part(modul, variant, configuration, log, with_plug=False): if not variant in modul.all_params: FreeCAD.Console.PrintMessage("Parameters for %s doesn't exist in 'M.all_params', skipping." % variant) return LIST_license[0] = "Copyright (C) "+datetime.now().strftime("%Y")+", " + STR_licAuthor params = modul.all_params[variant] series_params = modul.seriesParams series = series_params.series_name subseries, connector_style = params.series_name.split('-') pitch_mpn = '-{:g}'.format(params.pin_pitch) if series[0] == 'MSTB': pitch_mpn = '' if params.pin_pitch == 5.08: pitch_mpn = '-5,08' elif params.pin_pitch == 7.62: pitch_mpn = '-7,62' lib_name = configuration['lib_name_format_str'].format(series=series[0], style=series[1], pitch=params.pin_pitch) mpn = configuration['mpn_format_string'].format(subseries=subseries, style = connector_style, rating=series[1], num_pins=params.num_pins, pitch=pitch_mpn) FileName = configuration['fp_name_format_string'].format(man = configuration['manufacturer'], series = series[0], mpn = mpn, num_rows = 1, num_pins = params.num_pins, pitch = params.pin_pitch, orientation = configuration['orientation_str'][1] if params.angled else configuration['orientation_str'][0], flanged = configuration['flanged_str'][1] if params.flanged else configuration['flanged_str'][0], mount_hole = configuration['mount_hole_str'][1] if params.mount_hole else configuration['mount_hole_str'][0]) destination_dir=global_3dpath+lib_name if with_plug: destination_dir += "__with_plug" destination_dir+=".3dshapes" ModelName = variant ModelName = ModelName.replace(".","_") Newdoc = FreeCAD.newDocument(ModelName) App.setActiveDocument(ModelName) App.ActiveDocument=App.getDocument(ModelName) Gui.ActiveDocument=Gui.getDocument(ModelName) #App.setActiveDocument(ModelName) #Gui.ActiveDocument=Gui.getDocument(ModelName) (pins, body, insert, mount_screw, plug, plug_screws) = modul.generate_part(variant, with_plug) color_attr = body_color + (0,) show(body, color_attr) color_attr = pins_color + (0,) show(pins, color_attr) if insert is not None: color_attr = insert_color + (0,) show(insert, color_attr) if mount_screw is not None: color_attr = screw_color + (0,) show(mount_screw, color_attr) if plug is not None: color_attr = body_color + (0,) show(plug, color_attr) color_attr = screw_color + (0,) show(plug_screws, color_attr) doc = FreeCAD.ActiveDocument doc.Label=ModelName objs=FreeCAD.ActiveDocument.Objects FreeCAD.Console.PrintMessage(objs) i=0 objs[i].Label = ModelName + "__body" i+=1 objs[i].Label = ModelName + "__pins" i+=1 if insert is not None: objs[i].Label = ModelName + "__thread_insert" i+=1 if mount_screw is not None: objs[i].Label = ModelName + "__mount_screw" i+=1 if plug is not None: objs[i].Label = ModelName + "__plug" i+=1 objs[i].Label = ModelName + "__plug_screws" restore_Main_Tools() out_dir=destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) used_color_keys = [body_color_key, pins_color_key] export_file_name=destination_dir+os.sep+FileName+'.wrl' export_objects = [] i=0 export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=body_color_key, face_colors=None)) i+=1 export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=pins_color_key, face_colors=None)) i+=1 if insert is not None: export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=insert_color_key, face_colors=None)) used_color_keys.append(insert_color_key) i+=1 if mount_screw is not None: export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=screw_color_key, face_colors=None)) used_color_keys.append(screw_color_key) i+=1 if plug is not None: export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=body_color_key, face_colors=None)) i+=1 export_objects.append(expVRML.exportObject(freecad_object = objs[i], shape_color=screw_color_key, face_colors=None)) scale=1/2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects , scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs, keepOriginals=True) exportSTEP(doc,FileName,out_dir,fusion) step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName) L.addLicenseToStep(out_dir, '{:s}.step'.format(FileName), LIST_license,\ STR_licAuthor, STR_licEmail, STR_licOrgSys, STR_licPreProc) FreeCAD.activeDocument().recompute() # FreeCADGui.activateWorkbench("PartWorkbench") if save_memory == False and check_Model==False: Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() # Save the doc in Native FC format saveFCdoc(App, Gui, doc, FileName, out_dir) if save_memory == True or check_Model==True: doc=FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) if check_Model==True: runGeometryCheck(App, Gui, step_path, log, ModelName, save_memory=save_memory)
def export_one_part(module, pincount, configuration, log): series_definition = module.series_params if module.LICENCE_Info.LIST_license[0] == "": LIST_license = L.LIST_int_license LIST_license.append("") else: LIST_license = module.LICENCE_Info.LIST_license LIST_license[0] = "Copyright (C) " + datetime.now().strftime( "%Y") + ", " + module.LICENCE_Info.STR_licAuthor pins_per_row = pincount / series_definition.number_of_rows mpn = series_definition.mpn_format_string.format(pincount=pincount, pins_per_row=pins_per_row) orientation = configuration['orientation_options'][ series_definition.orientation] format_string = getattr( series_definition, 'fp_name_format_string', configuration[getattr(series_definition, 'fp_name_format', 'fp_name_format_string')]) FileName = format_string.format(man=series_definition.manufacturer, series=series_definition.series, mpn=mpn, num_rows=series_definition.number_of_rows, pins_per_row=pins_per_row, pins=pincount, pitch=series_definition.pitch, orientation=orientation, mount_pin=series_definition.mount_pin) FileName = FileName.replace('__', '_') lib_name = configuration['lib_name_format_string'].format( man=series_definition.manufacturer) fc_mpn = mpn.replace('.', '').replace('-', '_').replace('(', '').replace(')', '') ModelName = '{:s}_{:s}'.format( series_definition.manufacturer, fc_mpn) # For some reason the Model name can not start with a number. FreeCAD.Console.PrintMessage('\r\n' + FileName + '\r\n') #FileName = modul.all_params[variant].file_name Newdoc = FreeCAD.newDocument(ModelName) print(Newdoc.Label) App.setActiveDocument(ModelName) App.ActiveDocument = App.getDocument(ModelName) Gui.ActiveDocument = Gui.getDocument(ModelName) color_keys = series_definition.color_keys obj_suffixes = series_definition.obj_suffixes colors = [ shaderColors.named_colors[key].getDiffuseInt() for key in color_keys ] cq_obj_data = module.generate_part(pincount) for i in range(len(cq_obj_data)): color_i = colors[i] + (0, ) show(cq_obj_data[i], color_i) doc = FreeCAD.ActiveDocument doc.Label = ModelName objs = GetListOfObjects(FreeCAD, doc) for i in range(len(objs)): objs[i].Label = ModelName + obj_suffixes[i] restore_Main_Tools() out_dir = '{:s}{:s}.3dshapes'.format(global_3dpath, lib_name) if not os.path.exists(out_dir): os.makedirs(out_dir) used_color_keys = color_keys export_file_name = out_dir + os.sep + FileName + '.wrl' export_objects = [] for i in range(len(objs)): export_objects.append( expVRML.exportObject(freecad_object=objs[i], shape_color=color_keys[i], face_colors=None)) scale = 1 / 2.54 colored_meshes = expVRML.getColoredMesh(Gui, export_objects, scale) expVRML.writeVRMLFile(colored_meshes, export_file_name, used_color_keys, LIST_license) fusion = multiFuseObjs_wColors(FreeCAD, FreeCADGui, ModelName, objs, keepOriginals=True) exportSTEP(doc, FileName, out_dir, fusion) step_path = '{dir:s}/{name:s}.step'.format(dir=out_dir, name=FileName) L.addLicenseToStep(out_dir, '{:s}.step'.\ format(FileName), LIST_license, module.LICENCE_Info.STR_licAuthor, module.LICENCE_Info.STR_licEmail, module.LICENCE_Info.STR_licOrgSys, module.LICENCE_Info.STR_licPreProc) FreeCAD.activeDocument().recompute() saveFCdoc(App, Gui, doc, FileName, out_dir) #FreeCADGui.activateWorkbench("PartWorkbench") if save_memory == False and check_Model == False: FreeCADGui.SendMsgToActiveView("ViewFit") FreeCADGui.activeDocument().activeView().viewAxometric() if save_memory == True or check_Model == True: doc = FreeCAD.ActiveDocument FreeCAD.closeDocument(doc.Name) if check_Model == True: runGeometryCheck(App, Gui, step_path, log, ModelName, save_memory=save_memory)
def MakeHeader(n): global LIST_license, docname name = HeaderName(n) destination_dir = "/Box_Headers" 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 + destination_dir if not os.path.exists(out_dir): os.makedirs(out_dir) #having a period '.' character in the model name REALLY messes with things. docname = name.replace(".", "") newdoc = App.newDocument(docname) App.setActiveDocument(docname) a_doc = Gui.ActiveDocument Gui.ActiveDocument = Gui.getDocument(docname) pins = MakePinRow(n) pins = pins.union(MakePinRow(n).translate((0, 2.54, 0))) base = MakeBase(n) ##assign some colors #base_color = (50,50,50) #pins_color = (225,175,0) # #show(base,base_color+(0,)) #show(pins,pins_color+(0,)) 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 = docname objs = GetListOfObjects(FreeCAD, doc) objs[0].Label = docname restore_Main_Tools() #out_dir = "./generated_pinheaders/" doc.Label = docname #save the STEP file exportSTEP(doc, name, out_dir) if LIST_license[0] == "": LIST_license = Lic.LIST_int_license LIST_license.append("") Lic.addLicenseToStep(out_dir+'/', name+".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 + name + '.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) # Save the doc in Native FC format saveFCdoc(App, Gui, doc, name, out_dir) if close_doc != True: # avoid operations for memory leak Gui.SendMsgToActiveView("ViewFit") Gui.activeDocument().activeView().viewAxometric() return 0
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