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

CadQuery Varibles Editor doesn't set variables #95

Closed
robodan opened this issue May 24, 2018 · 10 comments
Closed

CadQuery Varibles Editor doesn't set variables #95

robodan opened this issue May 24, 2018 · 10 comments
Labels
bug defect lib:cqparts module wontfix cancelled, disregarded, ignored

Comments

@robodan
Copy link

robodan commented May 24, 2018

In b2, a simple cadquery script can set the global variables through the CadQuery Variable Editor. This works fine for me in FreeCad.
b2.txt

[ edited: uploaded bm2.txt was the wrong file. See my reply below with correct cqpart code]

Ubuntu Linux 18.04 amd64
FreeCad 0.17
Cadquery 1.2.0 pip install
cqparts 0.2.0 pip install

@jmwright
Copy link

@robodan This may be more of a CadQuery/FreeCAD Module issue than a cqparts one. The variables in your second script are made up of objects rather than being simple int, float, string, etc variables. At this time, CQGI (which the Variables Editor in the FreeCAD module relies on) only understands simple variables.

@robodan
Copy link
Author

robodan commented May 24, 2018

Oops, I included the wrong file. It should be this (which I can't seem to upload as a file).
I only expect config and scale to be configurable. They are simple variables (same as b2.txt).

from __future__ import print_function
from __future__ import division
from __future__ import absolute_import

import cadquery
import cqparts
from cqparts.params import *

import logging
logging.basicConfig(level=logging.DEBUG)

config = "FFF"                            # 3D printing
scale = 1.0                               # another config test


class MyPart(cqparts.Part):
    width = PositiveFloat(5, doc="just that big")
    length = PositiveFloat(5, doc="how far we'll go")

    def make(self):
        logging.info("config: %r scale: %f" % (config, scale))
        obj = cadquery.Workplane('XY').circle(self.width / 2)
        obj = obj.extrude(self.length)
        return obj

if __name__ == '__main__':
    mypart = MyPart()
    mypart.exporter("stl")("example_part.stl")
else:
    from cqparts.display import display
    mypart = MyPart()
    display(mypart)

@jmwright
Copy link

@robodan Can you wrap that in triple back ticks so that I can copy it? GitHub is trying to format it like markdown.

@robodan
Copy link
Author

robodan commented May 24, 2018 via email

@jmwright
Copy link

Your first script uses the show_object function which taps into CQGI, and your second script uses cqpart's display function which doesn't hook into CQGI. That's why the second script's variables aren't dynamically editable. There have been recent discussions on portability issues like this. I think that everyone would like things to work the same whether you're using stock CadQuery or cqparts. For now, I was able to make your second script work as expected by commenting out the display line and putting a show_object line right below it.

@robodan
Copy link
Author

robodan commented May 24, 2018

show_object of what?
This errors for me: show_object(mypart)

@jmwright
Copy link

Sorry, you have to pull local_obj out of mypart to show it through show_object. If it's an assembly I think you'd have to pull out global_obj, but @fragmuffin would know better than I on that.

show_object(mypart.local_obj)

@fragmuffin
Copy link
Member

@robodan yep, what @jmwright should work.

I think to leverage the current jmwright/cadquery-freecad-module with cqparts, you'd need to pass globally defined variables to the part's constructor.

g_width = 5
g_length = 5

mypart = MyPart(width=g_width, length=g_length)
show_object(mypart.local_obj)

from cqparts.utils import CoordSystem
mypart.world_coords = CoordSystem(origin=(0,20,0))  # (see note below)
show_object(mypart.world_obj)

@jmwright is that wright correct?

note: requesting world_obj before setting world_coords will raise an exception.
read this for details.

@jmwright
Copy link

@fragmuffin Correct. The global variables will be accessible to CQGI, and passing them into MyPart serves the original intent.

@fragmuffin
Copy link
Member

@robodan I'll close this issue with the above workaround.
This is also not strictly a problem with cqparts, but the cadquery.cqgi.

I've raised dcowden/cadquery#273 because this is not fixed, but the discussion needs to move to the right place.

Thank you for the feedback @robodan !
cqparts is moving fast, and I'm so glad people like yourself are critiquing it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug defect lib:cqparts module wontfix cancelled, disregarded, ignored
Projects
None yet
Development

No branches or pull requests

3 participants