-
Notifications
You must be signed in to change notification settings - Fork 7
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
Add an --expression flag to specify what cq-cli should render #26
Conversation
Thanks @justbuchanan I can only get it to work if I am calling
import cadquery as cq
def make_box():
box = cq.Workplane().box(10, 10, 10)
return box
show_object(make_box()) Without the
|
As currently-implemented, yes this is expected. I can see an argument for wanting it to work the other way though where you supply the name of a function and cq-cli calls the function and renders the return value. Implementing the feature that way has two main challenges that I see:
I envision it working like this: # model.py
import cadquery as cq
def make_box():
box = cq.Workplane().box(10, 10, 10)
return box
def make_cylinder():
cyl = cq.Workplane().circle(3).extrude(10)
return cyl
# this code does not run under cq-cli, but does when viewing the model with cq-editor
if __name__ == '__cq_main__':
asm = cq.Assembly()
asm.add(make_box(), ...)
asm.add(make_cylinder(), ...)
show_object(asm) # export individual parts
cq-cli --entrypoint "show_object(make_box())" --infile model.py --outfile box.stl
cq-cli --entrypoint "show_object(make_cylinder())" --infile model.py --outfile cylinder.stl |
--entrypoint is now just the name of a python function to call and show
I reworked this a little so that entrypoint no longer requires show_object(). See 8af4998 |
Thinking about this a bit more, I actually like the initial approach better where we just append |
Switching back to the way you initially had it, you could inject all sorts of code.
or
That second one will probably have weird consequences when using CQGI though. So maybe your suggestion of using |
Sounds good, I changed this to accept a python expression and renamed the flag.
What did you have in mind for |
The original though was sparked by my idea of FreeCAD support where you might have multiple parts inside a file. I think the same thing applies with CadQuery files where you have multiple part methods and maybe an assembly. I have scripts where I have separate methods for a regular assembly and an exploded assembly, and it would be nice to be able to tell cq-cli to use one over the other so that I don't have to hard code the calls into the code, add command line switches, and/or add conditionals. Maybe I'm approaching this from the wrong angle though. Thoughts? |
It sounds like our use cases are roughly the same here - I also typically have a python function for each part and for each assembly. For 3d printing, I want to export each part defined in the model as an individual stl. I think the cq-cli --infile model.py --expression "part1()" --outfile part1.stl
cq-cli --infile model.py --expression "part2()" --outfile part2.stl
cq-cli --infile model.py --expression "my_assembly()" --outfile asm.gltf |
@justbuchanan Are you ok with |
I think this is good as-is if you're ok with it. Just added a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for adding this @justbuchanan !
This is an attempt to implement the feature in #18.
Usage:
cq-cli --infile model.py --outfile out.step --entrypoint="show_object(mypart())"
As-is, this requires
show_object
to be part of the entrypoint, which doesn't seem great, but I don't think it's too unexpected for users since the code in--infile
previously would require at least one call toshow_object
anyways. Making--entrypoint
not require theshow_object
call may be quite a pain, as you outlined in #18 (comment)Other potential names for the flag: --expr/--expression, --snippet?