Add pci gpu example script

main
Jeff Moe 2024-01-18 13:12:00 -07:00
parent d480c698ae
commit f7fd7253a0
1 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,93 @@
#!/usr/bin/env python3
"""
This script creates pci_gpu and allows for various exports.
Usage: python3 pci_gpu --display --stl output.stl --dxf output.dxf --svg output.svg
"""
import argparse
from bd_cruft import pci_gpu
from build123d import *
from ocp_vscode import *
def display_object(obj: BuildPart):
"""
Display the given object in the IDE with specified color and transparency.
:param obj: The object to be displayed.
:type obj: Any
"""
show_object(
obj,
name="Pcigpu",
black_edges=True,
)
def export_stl(obj: BuildPart, filename):
"""
Export the given object as an STL file.
:param obj: The object to be exported.
:type obj: BuildPart
:param filename: The path of the output file.
:type filename: str
"""
try:
print("exporting STL to ", filename)
obj.part.export_stl(filename)
except Exception as e:
logging.error(f"Error exporting STL to {filename}: {e}")
def parse_args(**kwargs):
"""
Parse the command line arguments.
:param kwargs: Additional arguments to pass to ArgumentParser.parse_args()
:return: The parsed command line arguments.
:rtype: Any
"""
parser = argparse.ArgumentParser(description="Create pci_gpu.")
parser.add_argument(
"--display", action="store_false", help="Display the generated pci_gpu in IDE"
)
parser.add_argument(
"--stl",
dest="stl_filename",
type=str,
metavar="FILENAME",
help="Export the pci_gpu as an STL file",
)
config = {
"display": True,
"stl_filename": None,
}
parser.set_defaults(**config)
args = parser.parse_args(**kwargs)
return args
def main():
args = parse_args()
pci_gpu1_config = pci_gpu.PcigpuConfig()
pci_gpu1 = pci_gpu.create_pci_gpu(**pci_gpu1_config.model_dump())
if any([args.stl_filename]):
args.display = False
if args.display:
display_object(pci_gpu1)
if args.stl_filename is not None:
export_stl(pci_gpu1, args.stl_filename)
if __name__ == "__main__":
main()