diff --git a/cadquery/cqgi.py b/cadquery/cqgi.py index d654d72..ec945a6 100644 --- a/cadquery/cqgi.py +++ b/cadquery/cqgi.py @@ -101,7 +101,7 @@ def build(self, build_parameters=None, build_options=None): self.set_param_values(build_parameters) collector = ScriptCallback() env = EnvironmentBuilder().with_real_builtins().with_cadquery_objects() \ - .add_entry("build_object", collector.build_object) \ + .add_entry("show_object", collector.show_object) \ .add_entry("debug", collector.debug) \ .add_entry("describe_parameter",collector.describe_parameter) \ .build() @@ -286,14 +286,14 @@ def __str__(self): class ScriptCallback(object): """ Allows a script to communicate with the container - the build_object() method is exposed to CQ scripts, to allow them + the show_object() method is exposed to CQ scripts, to allow them to return objects to the execution environment """ def __init__(self): self.outputObjects = [] self.debugObjects = [] - def build_object(self, shape,options={}): + def show_object(self, shape,options={}): """ return an object to the executing environment, with options :param shape: a cadquery object @@ -340,7 +340,7 @@ class InvalidParameterError(Exception): class NoOutputError(Exception): """ - Raised when the script does not execute the build_object() method to + Raised when the script does not execute the show_object() method to return a solid """ pass diff --git a/doc/cqgi.rst b/doc/cqgi.rst index 84a3602..06c9fdf 100644 --- a/doc/cqgi.rst +++ b/doc/cqgi.rst @@ -31,13 +31,13 @@ The Script Side CQGI compliant containers provide an execution environment for scripts. The environment includes: * the cadquery library is automatically imported as 'cq'. - * the :py:meth:`cadquery.cqgi.ScriptCallback.build_object()` method is defined that should be used to export a shape to the execution environment + * the :py:meth:`cadquery.cqgi.ScriptCallback.show_object()` method is defined that should be used to export a shape to the execution environment * the :py:meth:`cadquery.cqgi.ScriptCallBack.debug()` method is defined, which can be used by scripts to debug model output during execution. -Scripts must call build_output at least once. Invoking build_object more than once will send multiple objects to -the container. An error will occur if the script does not return an object using the build_object() method. +Scripts must call build_output at least once. Invoking show_object more than once will send multiple objects to +the container. An error will occur if the script does not return an object using the show_object() method. -An optional options dictionary can be provided to the build_object method. If provided, it is passed onto the executing environment, and is used to render the object. Typically, this will be colors, transparency, and other visual affects. +An optional options dictionary can be provided to the show_object method. If provided, it is passed onto the executing environment, and is used to render the object. Typically, this will be colors, transparency, and other visual affects. This CQGI compliant script produces a cube with a circle on top, and displays a workplane as well as an intermediate circle as debug output:: @@ -50,7 +50,7 @@ This CQGI compliant script produces a cube with a circle on top, and displays a circle=top_of_cube_plane.circle(0.5) debug(circle, { 'color': 'red' } ) - build_object( circle.extrude(1.0),{"color": "#aaaaaa" ) + show_object( circle.extrude(1.0),{"color": "#aaaaaa" ) Note that importing cadquery is not required. At the end of this script, one object will be displayed, in addition to a workplane, a point, and a circle @@ -157,7 +157,7 @@ These are the most important Methods and classes of the CQGI parse CQModel.build BuildResult - ScriptCallback.build_object + ScriptCallback.show_object Complete CQGI api ----------------- diff --git a/doc/examples.rst b/doc/examples.rst index 06c79aa..4931140 100644 --- a/doc/examples.rst +++ b/doc/examples.rst @@ -43,7 +43,7 @@ Just about the simplest possible example, a rectangular box .. cq_plot:: result = cadquery.Workplane("front").box(2.0, 2.0, 0.5) - build_object(result) + show_object(result) .. topic:: Api References @@ -74,7 +74,7 @@ of a working plane is at the center of the face. The default hole depth is thro result = cq.Workplane("XY").box(length, height, thickness) \ .faces(">Z").workplane().hole(center_hole_dia) - build_object(result) + show_object(result) .. topic:: Api References @@ -97,7 +97,7 @@ By default, rectangles and circles are centered around the previous working poin .. cq_plot:: result = cq.Workplane("front").circle(2.0).rect(0.5, 0.75).extrude(0.5) - build_object(result) + show_object(result) .. topic:: Api References @@ -123,7 +123,7 @@ closed curve. result = cq.Workplane("front").lineTo(2.0, 0).lineTo(2.0, 1.0).threePointArc((1.0, 1.5),(0.0, 1.0))\ .close().extrude(0.25) - build_object(result) + show_object(result) .. topic:: Api References @@ -155,7 +155,7 @@ A new work plane center can be established at any point. #the new center is specified relative to the previous center, not global coordinates! result = result.extrude(0.25) - build_object(result) + show_object(result) .. topic:: Api References @@ -184,7 +184,7 @@ like :py:meth:`Workplane.circle` and :py:meth:`Workplane.rect`, will operate on r = r.pushPoints( [ (1.5, 0),(0, 1.5),(-1.5, 0),(0, -1.5) ] ) # now four points are on the stack r = r.circle( 0.25 ) # circle will operate on all four points result = r.extrude(0.125 ) # make prism - build_object(result) + show_object(result) .. topic:: Api References @@ -206,7 +206,7 @@ correct for small hole sizes. result = cq.Workplane("front").box(3.0, 4.0, 0.25).pushPoints ( [ ( 0,0.75 ),(0, -0.75) ]) \ .polygon(6, 1.0).cutThruAll() - build_object(result) + show_object(result) .. topic:: Api References @@ -238,7 +238,7 @@ This example uses a polyline to create one half of an i-beam shape, which is mir (0,H/-2.0) ] result = cq.Workplane("front").polyline(pts).mirrorY().extrude(L) - build_object(result) + show_object(result) .. topic:: Api References @@ -272,7 +272,7 @@ needs a complex profile ] r = s.lineTo(3.0, 0).lineTo(3.0, 1.0).spline(sPnts).close() result = r.extrude(0.5) - build_object(result) + show_object(result) .. topic:: Api References @@ -297,7 +297,7 @@ introduce horizontal and vertical lines, which make for slightly easier coding. r = cq.Workplane("front").hLine(1.0) # 1.0 is the distance, not coordinate r = r.vLine(0.5).hLine(-0.25).vLine(-0.25).hLineTo(0.0) # hLineTo allows using xCoordinate not distance result =r.mirrorY().extrude(0.25 ) # mirror the geometry and extrude - build_object(result) + show_object(result) .. topic:: Api References @@ -356,7 +356,7 @@ Mirroring 3D Objects result = result.union(mirXY_neg).union(mirXY_pos).union(mirZY_neg).union(mirZY_pos) - build_object(result) + show_object(result) .. topic:: Api References @@ -391,7 +391,7 @@ Keep in mind that the origin of new workplanes are located at the center of a fa result = cq.Workplane("front").box(2,3, 0.5) #make a basic prism result = result.faces(">Z").workplane().hole(0.5) #find the top-most face and make a hole - build_object(result) + show_object(result) .. topic:: Api References @@ -420,7 +420,7 @@ how deep the part is result = cq.Workplane("front").box(3,2, 0.5) #make a basic prism result = result.faces(">Z").vertices("Z").workplane() \ .transformed(offset=cq.Vector(0, -1.5, 1.0),rotate=cq.Vector(60, 0, 0)) \ .rect(1.5,1.5,forConstruction=True).vertices().hole(0.25) - build_object(result) + show_object(result) .. topic:: Api References @@ -494,7 +494,7 @@ In the example below, a rectangle is drawn, and its vertices are used to locate result = cq.Workplane("front").box(2, 2, 0.5).faces(">Z").workplane() \ .rect(1.5, 1.5, forConstruction=True).vertices().hole(0.125 ) - build_object(result) + show_object(result) .. topic:: Api References @@ -518,7 +518,7 @@ are removed, and then the inside of the solid is 'hollowed out' to make the shel .. cq_plot:: result = cq.Workplane("front").box(2, 2, 2).faces("+Z").shell(0.05) - build_object(result) + show_object(result) .. topic:: Api References @@ -541,7 +541,7 @@ and a circular section. result = cq.Workplane("front").box(4.0, 4.0, 0.25).faces(">Z").circle(1.5) \ .workplane(offset=3.0).rect(0.75, 0.5).loft(combine=True) - build_object(result) + show_object(result) .. topic:: Api References @@ -566,7 +566,7 @@ Similar to :py:meth:`Workplane.hole` , these functions operate on a list of poin result = cq.Workplane(cq.Plane.XY()).box(4,2, 0.5).faces(">Z").workplane().rect(3.5, 1.5, forConstruction=True)\ .vertices().cboreHole(0.125, 0.25, 0.125, depth=None) - build_object(result) + show_object(result) .. topic:: Api References @@ -592,7 +592,7 @@ Here we fillet all of the edges of a simple plate. .. cq_plot:: result = cq.Workplane("XY" ).box(3, 3, 0.5).edges("|Z").fillet(0.125) - build_object(result) + show_object(result) .. topic:: Api References @@ -619,7 +619,7 @@ with just a few lines of code. .rect(length-padding,height-padding,forConstruction=True) \ .vertices().cboreHole(2.4, 4.4, 2.1) - build_object(result) + show_object(result) Splitting an Object @@ -633,7 +633,7 @@ You can split an object using a workplane, and retain either or both halves #now cut it in half sideways result = c.faces(">Y").workplane(-0.5).split(keepTop=True) - build_object(result) + show_object(result) .. topic:: Api References @@ -675,7 +675,7 @@ ones at 13 lines, but that's very short compared to the pythonOCC version, which #make a shell result = p.faces(">Z").shell(0.3) - build_object(result) + show_object(result) .. topic:: Api References @@ -774,7 +774,7 @@ A Parametric Enclosure #return the combined result result =topOfLid.combineSolids(bottom) - build_object(result) + show_object(result) .. topic:: Api References @@ -859,7 +859,7 @@ regarding the underside of the brick. tmp = s # Render the solid - build_object(tmp) + show_object(tmp) Braille Example @@ -1043,7 +1043,7 @@ Braille Example if base_thickness < get_cylinder_radius(_cell_geometry): raise ValueError('Base thickness should be at least {}'.format(dot_height)) - build_object(make_embossed_plate(text_lines, _cell_geometry)) + show_object(make_embossed_plate(text_lines, _cell_geometry)) Panel With Various Connector Holes ----------------------------------- @@ -1093,4 +1093,4 @@ Panel With Various Connector Holes result = result.workplane(offset=1, centerOption='CenterOfBoundBox').center(-173,-30-idx*h_sep).moveTo(-2.9176,-5.3).threePointArc((-6.05,0),(-2.9176,5.3)).lineTo(2.9176,5.3).threePointArc((6.05,0),(2.9176,-5.3)).close().cutThruAll() # Render the solid - build_object(result) + show_object(result) diff --git a/doc/extending.rst b/doc/extending.rst index 8138b18..96f5943 100644 --- a/doc/extending.rst +++ b/doc/extending.rst @@ -176,5 +176,5 @@ This ultra simple plugin makes cubes of the specified size for each stack point. result = cq.Workplane("XY").box(6.0,8.0,0.5).faces(">Z")\ .rect(4.0,4.0,forConstruction=True).vertices() \ .makeCubes(1.0).combineSolids() - build_object(result) + show_object(result) diff --git a/doc/fileformat.rst b/doc/fileformat.rst index e34afa5..3ff968e 100644 --- a/doc/fileformat.rst +++ b/doc/fileformat.rst @@ -12,7 +12,7 @@ like `The CadQuery Freecad Module `_, there are a few conventions you need to be aware of: * cadquery is already imported as 'cq' - * to return an object to the container, you need to call the build_object() method. + * to return an object to the container, you need to call the show_object() method. Each script generally has three sections: diff --git a/doc/quickstart.rst b/doc/quickstart.rst index 6701942..feabc53 100644 --- a/doc/quickstart.rst +++ b/doc/quickstart.rst @@ -62,7 +62,7 @@ with place-holders for the dimensions. Paste this into the CodeWindow: result = cq.Workplane("XY").box(height, width, thickness) # Render the solid - build_object(result) + show_object(result) Press F2 to run the script. You should see Our basic base. @@ -91,7 +91,7 @@ This modification will do the trick: .faces(">Z").workplane().hole(diameter) # Render the solid - build_object(result) + show_object(result) Rebuild your model by pressing F2. Your block should look like this: @@ -149,7 +149,7 @@ Good news!-- we can get the job done with just two lines of code. Here's the cod .cboreHole(2.4, 4.4, 2.1) # Render the solid - build_object(result) + show_object(result) After pressing F2 to re-execute the model, you should see something like this: @@ -215,7 +215,7 @@ We can do that using the preset dictionaries in the parameter definition: .edges("|Z").fillet(2.0) # Render the solid - build_object(result) + show_object(result) **Line 13** fillets the edges using the :py:meth:`cadquery.CQ.fillet` method. diff --git a/doc/selectors.rst b/doc/selectors.rst index c40c547..70fa3ce 100644 --- a/doc/selectors.rst +++ b/doc/selectors.rst @@ -36,7 +36,7 @@ Selectors can be combined logically, currently defined operators include **and** .edges("|Z and >Y") \ .chamfer(0.2) - build_object(result) + show_object(result) Much more complex expressions are possible as well: @@ -49,7 +49,7 @@ Much more complex expressions are possible as well: .edges("not(X or Y)") \ .chamfer(0.1) - build_object(result) + show_object(result) .. _filteringfaces: @@ -137,4 +137,4 @@ It is possible to use user defined vectors as a basis for the selectors. For exa # chamfer only one edge result = result.edges('>(-1,1,0)').chamfer(1) - build_object(result) + show_object(result) diff --git a/tests/TestCQGI.py b/tests/TestCQGI.py index 08c63dc..b2a278b 100644 --- a/tests/TestCQGI.py +++ b/tests/TestCQGI.py @@ -4,7 +4,7 @@ Currently, this includes: Parsing a script, and detecting its available variables Altering the values at runtime - defining a build_object function to return results + defining a show_object function to return results """ from cadquery import cqgi @@ -19,7 +19,7 @@ foo="bar" result = "%s|%s|%s|%s" % ( str(height) , str(width) , foo , str(a) ) - build_object(result) + show_object(result) """ ) @@ -31,7 +31,7 @@ foo="bar" debug(foo, { "color": 'yellow' } ) result = "%s|%s|%s|%s" % ( str(height) , str(width) , foo , str(a) ) - build_object(result) + show_object(result) debug(height ) """ ) @@ -120,9 +120,9 @@ def test_that_two_results_are_returned(self): script = textwrap.dedent( """ h = 1 - build_object(h) + show_object(h) h = 2 - build_object(h) + show_object(h) """ ) @@ -136,7 +136,7 @@ def test_that_assinging_number_to_string_works(self): script = textwrap.dedent( """ h = "this is a string" - build_object(h) + show_object(h) """ ) result = cqgi.parse(script).build( {'h': 33.33}) @@ -146,7 +146,7 @@ def test_that_assigning_string_to_number_fails(self): script = textwrap.dedent( """ h = 20.0 - build_object(h) + show_object(h) """ ) result = cqgi.parse(script).build( {'h': "a string"}) @@ -156,14 +156,14 @@ def test_that_assigning_unknown_var_fails(self): script = textwrap.dedent( """ h = 20.0 - build_object(h) + show_object(h) """ ) result = cqgi.parse(script).build( {'w': "var is not there"}) self.assertTrue(isinstance(result.exception, cqgi.InvalidParameterError)) - def test_that_not_calling_build_object_raises_error(self): + def test_that_not_calling_show_object_raises_error(self): script = textwrap.dedent( """ h = 20.0 @@ -176,7 +176,7 @@ def test_that_cq_objects_are_visible(self): script = textwrap.dedent( """ r = cadquery.Workplane('XY').box(1,2,3) - build_object(r) + show_object(r) """ ) @@ -188,7 +188,7 @@ def test_setting_boolean_variable(self): script = textwrap.dedent( """ h = True - build_object( "*%s*" % str(h) ) + show_object( "*%s*" % str(h) ) """ ) @@ -208,7 +208,7 @@ def do_stuff(): x = 1 y = 2 - build_object( "result" ) + show_object( "result" ) """ )