Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the CLI command "pc ai regenerate <part>" #201

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions partcad-cli/src/partcad_cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from partcad.user_config import user_config

from .cli_add import *
from .cli_ai_regenerate import *
from .cli_init import *
from .cli_info import *
from .cli_install import *
Expand Down Expand Up @@ -84,6 +85,17 @@ def main():
cli_help_status(subparsers)
cli_help_test(subparsers)

# AI subcommands
parser_ai = subparsers.add_parser(
"ai",
help="AI related commands",
)
ai_subparsers = parser_ai.add_subparsers(
dest="ai_command",
required=True,
)
cli_help_ai_regenerate(ai_subparsers)

# Supply subcommands
parser_supply = subparsers.add_parser(
"supply",
Expand Down Expand Up @@ -149,6 +161,14 @@ def main():
with pc_logging.Process("AddAssy", "this"):
cli_add_assembly(args, ctx)

elif args.command == "ai":
if args.ai_command == "regenerate":
with pc_logging.Process("AiRegen", "this"):
cli_ai_regenerate(args, ctx)
else:
print("Unknown AI command.\n")
parser.print_help()

elif args.command == "info":
with pc_logging.Process("Info", "this"):
cli_info(args, ctx)
Expand Down
75 changes: 75 additions & 0 deletions partcad-cli/src/partcad_cli/cli_ai_regenerate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#
# OpenVMP, 2024
#
# Author: Roman Kuzmenko
# Created: 2024-11-30
#
# Licensed under Apache License, Version 2.0.
#

import partcad.logging as pc_logging
import partcad.utils as pc_utils


def cli_help_ai_regenerate(subparsers):
parser = subparsers.add_parser(
"regenerate",
help="Regenerate a sketch, part or assembly",
)

parser.add_argument(
"-P",
"--package",
help="Package to retrieve the object from",
type=str,
dest="package",
default=None,
)

group_type = parser.add_mutually_exclusive_group(required=False)
group_type.add_argument(
"-i",
help="The object is an interface",
dest="interface",
action="store_true",
)
group_type.add_argument(
"-a",
help="The object is an assembly",
dest="assembly",
action="store_true",
)
group_type.add_argument(
"-s",
help="The object is a sketch",
dest="sketch",
action="store_true",
)
group_type.add_argument(
"-S",
help="The object is a scene",
dest="scene",
action="store_true",
)

parser.add_argument(
"object",
help="Path to the part (default), assembly or scene to regenerate",
type=str,
)


def cli_ai_regenerate(args, ctx):
if args.sketch or args.interface or args.assembly or args.scene:
pc_logging.error("This object type is not yet supported")
return

if not ":" in args.object:
args.object = ":" + args.object
args.package, args.object = pc_utils.resolve_resource_path(
ctx.get_current_project_path(), args.object
)

package = ctx.get_project(args.package)
obj = package.get_part(args.object)
obj.regenerate()
Loading