diff --git a/.scripts/foot_gen.py b/.scripts/foot_gen.py index 179bfdb..282f9f2 100644 --- a/.scripts/foot_gen.py +++ b/.scripts/foot_gen.py @@ -42,7 +42,11 @@ for item in pcb.GetDrawings(): foot_path = lines[2].split(":")[-1].strip() if not lines[3].startswith("Z:"): continue - z_offset = float(lines[3].split(":")[-1].strip()) + z_str = lines[3].split(":")[-1].strip() + z_offset = eval(z_str) + if type(z_offset) is not tuple: + z_offset = (z_offset) + for line in lines[4:]: sp = line.split(':', 1) if len(sp) != 2: @@ -163,12 +167,17 @@ for foot in saved: # Export the step file os.system("kicad-cli pcb export vrml --units 'tenths' -f --user-origin " + str(ToMM(brd_cent.x)) + "x" + str(ToMM(brd_cent.y)) + "mm -o /tmp/dummy.wrl " + sys.argv[1]) +# Export step file of board with no additional components +if len(z_offset) > 1: + path = sys.path[0] + "/../../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + "_base" + ".wrl" + os.system("kicad-cli pcb export vrml --units 'tenths' -f --user-origin " + str(ToMM(brd_cent.x)) + "x" + str(ToMM(brd_cent.y)) + "mm -o " + path + " " + sys.argv[1]) + # Import the 3d model of the actual PCB dummy = FOOTPRINT(pcb) dummy.SetPosition(brd_cent) dummy_model = FP_3DMODEL() dummy_model.m_Filename = "/tmp/dummy.wrl" -dummy_model.m_Offset = VECTOR3D(0.0, 0.0, z_offset) +dummy_model.m_Offset = VECTOR3D(0.0, 0.0, z_offset[0]) dummy.Add3DModel(dummy_model) pcb.Add(dummy) @@ -178,8 +187,8 @@ pcb.Add(dummy) # Save and export step of board + mating connectors SaveBoard("test/test.kicad_pcb", pcb) -final_model_path = sys.path[0] + "/../../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + ".wrl" -os.system("kicad-cli pcb export vrml -f --units 'mm' --user-origin " + str(ToMM(brd_cent.x)) + "x" + str(ToMM(brd_cent.y)) + "mm -o " + final_model_path + " test/test.kicad_pcb") +path = sys.path[0] + "/../../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + ".wrl" +os.system("kicad-cli pcb export vrml -f --units 'mm' --user-origin " + str(ToMM(brd_cent.x)) + "x" + str(ToMM(brd_cent.y)) + "mm -o " + path + " test/test.kicad_pcb") # Generate footprint @@ -412,17 +421,21 @@ for i in range(len(corners)): # kicad_mod.append(RectLine(start=[-brd_width/2,-brd_height/2], end=[brd_width/2,brd_height/2], layer='F.SilkS', width=0.15)) -final_model_path = "${KIPRJMOD}/../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + ".wrl" -kicad_mod.append(Model(filename=final_model_path - ,at=[0,0,-1.6] - ,scale=[1,1,1] - ,rotate=[0,0,0])) +output_list = [(foot_name, -1.6)] +# Output another footprint if a second offset is specified +if len(z_offset) > 1: + output_list.append((foot_name+"_base", z_offset[1])) -# write file -file_handler = KicadFileHandler(kicad_mod) -final_foot_path = sys.path[0] + "/../../libs/melonlib/" + foot_path + ".pretty/" + foot_name + ".kicad_mod" -file_handler.writeFile(final_foot_path) +for [local_name, z] in output_list: + local_mod = deepcopy(kicad_mod) + local_mod.append(Model(filename="${KIPRJMOD}/../libs/melon3d/" + foot_path + ".3dshapes/" + local_name + ".wrl" + ,at=[0,0,z] + ,scale=[1,1,1] + ,rotate=[0,0,0])) + + # write file + file_handler = KicadFileHandler(local_mod) + file_handler.writeFile(sys.path[0] + "/../../libs/melonlib/" + foot_path + ".pretty/" + local_name + ".kicad_mod" ) import shutil - shutil.rmtree("test")