Added support for generating a second 'base' footprint

This commit is contained in:
ac
2025-05-13 19:22:59 +10:00
parent 7a2452cc8e
commit 51f029af3a

View File

@@ -42,7 +42,11 @@ for item in pcb.GetDrawings():
foot_path = lines[2].split(":")[-1].strip() foot_path = lines[2].split(":")[-1].strip()
if not lines[3].startswith("Z:"): if not lines[3].startswith("Z:"):
continue 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:]: for line in lines[4:]:
sp = line.split(':', 1) sp = line.split(':', 1)
if len(sp) != 2: if len(sp) != 2:
@@ -163,12 +167,17 @@ for foot in saved:
# Export the step file # 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]) 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 # Import the 3d model of the actual PCB
dummy = FOOTPRINT(pcb) dummy = FOOTPRINT(pcb)
dummy.SetPosition(brd_cent) dummy.SetPosition(brd_cent)
dummy_model = FP_3DMODEL() dummy_model = FP_3DMODEL()
dummy_model.m_Filename = "/tmp/dummy.wrl" 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) dummy.Add3DModel(dummy_model)
pcb.Add(dummy) pcb.Add(dummy)
@@ -178,8 +187,8 @@ pcb.Add(dummy)
# Save and export step of board + mating connectors # Save and export step of board + mating connectors
SaveBoard("test/test.kicad_pcb", pcb) SaveBoard("test/test.kicad_pcb", pcb)
final_model_path = sys.path[0] + "/../../libs/melon3d/" + foot_path + ".3dshapes/" + foot_name + ".wrl" 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") 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 # 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)) # 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" output_list = [(foot_name, -1.6)]
kicad_mod.append(Model(filename=final_model_path # Output another footprint if a second offset is specified
,at=[0,0,-1.6] if len(z_offset) > 1:
,scale=[1,1,1] output_list.append((foot_name+"_base", z_offset[1]))
,rotate=[0,0,0]))
# write file for [local_name, z] in output_list:
file_handler = KicadFileHandler(kicad_mod) local_mod = deepcopy(kicad_mod)
final_foot_path = sys.path[0] + "/../../libs/melonlib/" + foot_path + ".pretty/" + foot_name + ".kicad_mod" local_mod.append(Model(filename="${KIPRJMOD}/../libs/melon3d/" + foot_path + ".3dshapes/" + local_name + ".wrl"
file_handler.writeFile(final_foot_path) ,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 import shutil
shutil.rmtree("test") shutil.rmtree("test")