CadQuery / cq-cli

Command Line Interface for executing CadQuery scripts and converting their output to another format.
Apache License 2.0
22 stars 7 forks source link

feature request: allow specifying an "expression" to render as a command-line argument #18

Closed justbuchanan closed 7 months ago

justbuchanan commented 1 year ago

I have a model designed in cadquery that is made up of multiple 3d-printed parts, each defined in their own python function. I'd like an easy way to export each of these individual parts as stl files.

I want to do something like this:

# model.py

def part1():
  return cq.Workplane("XY")...

def part2():
  return cq.Workplane("XY")...

def part3():
  return cq.Workplane("XY")...
# export just part1
cq-cli --codec stl --infile model.py --outfile part1.stl --expr "part1()"

# export all parts
for part in part1 part2 part3; do
  cq-cli --codec stl --infile model.py --outfile "$part.stl" --expr "$part()"
done
jmwright commented 1 year ago

I have been considering adding something like an entrypoint argument to handle situations like this. I think the challenge is in getting this to work with CQGI. I may have to monkey-patch methods that don't call show_object, or I'll have to write a shim that imports the module somehow, involves the method, and then calls show_object on the result. All the ways I've thought of to do it are pretty messy.

@justbuchanan cq-cli should be installable via pip using git now, but I haven't updated the readme with the information. This allows cq-cli to integrate better with a Python environment.

justbuchanan commented 1 year ago

Great, glad to hear this is something you've considered :). And thanks for the info on cqgi difficulties - if I have time, I may take a look at that and see what I can figure out.

Thanks for the tip on pip-installability.

jmwright commented 1 year ago

@justbuchanan Feel free to register your interest on that PR. It wasn't actually a feature I needed, so when the PR discussion lasted longer than expected, I got distracted on other things. I looks like I just need to fix the test coverage to make that PR ready for merge.

justbuchanan commented 1 year ago

Sounds good, would you mind linking the PR you're thinking of?

jmwright commented 1 year ago

Sorry, I was posting everything on my phone and meant to put that message in the tuple PR discussion #17 https://github.com/CadQuery/cadquery/pull/1373

jmwright commented 1 year ago

@justbuchanan Feel free to add your ideas for making this work and/or submit a PR. It's going to be a while before I am able to get back to this.

justbuchanan commented 7 months ago

This feature was implemented in #26 - closing the issue.