dcowden / cadquery

CadQuery-- a parametric cad script framework
Other
432 stars 56 forks source link

cutThruAll() Question #12

Closed jmwright closed 10 years ago

jmwright commented 10 years ago

In the polygon example, cutThruAll is used to cut polygons into a plate. When I tried the example in FreeCAD the polygons did not extrude all the way through, and I'm having trouble understanding where the cut depth is set for them.

http://parametricparts.com/docs/examples.html#id8

Also, the origin for the part seems to be offset, but hasn't been on any of the other examples. I don't see anything in this example code that screams "origin change" to me.

Any thoughts?

dcowden commented 10 years ago

Hi, Jeremy:

Ok i can explain this behavior. I'm able to duplicate your results outside of FreeCAD on the website too.

The reason the origin is offset is because the default behavior of box centers the box at the origin, rather than having the origin at the bottom left corner. So for example this probably creates what you had in mind:

return Workplane("front").box(3.0,4.0,0.25,centered=(False,False,False))

see the docs here: http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.Workplane.box

This script works doesnt work either, though you might guess it would:

  return

Workplane("front").box(3.0,4.0,0.25,centered=(False,False,False)).pushPoints ( [ ( 1.5,1.0 ),(1.5,3.0) ]).polygon(6,1.0).cutThruAll()

That's because the cutThruAll() function requires a boolean argument that defines the cut direction, which defaults to False. Inverting the cut direction works:

 return

Workplane("front").box(3.0,4.0,0.25,centered=(False,False,False)).pushPoints ( [ ( 1.5,1.0 ),(1.5,3.0) ]).polygon(6,1.0).cutThruAll(True)

That function is documented here: http://parametricparts.com/docs/classreference.html#cadfile.cadutils.cadquery.Workplane.cutThruAll

On Tue, Jun 24, 2014 at 9:13 PM, Jeremy Wright notifications@github.com wrote:

In the polygon example, cutThruAll is used to cut polygons into a plate. When I tried the example in FreeCAD the polygons did not extrude all the way through, and I'm having trouble understanding where the cut depth is set for them.

http://parametricparts.com/docs/examples.html#id8

Also, the origin for the part seems to be offset, but hasn't been on any of the other examples. I don't see anything in this example code that screams "origin change" to me.

Any thoughts?

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/12.

jmwright commented 10 years ago

Thanks for the info Dave.

When I add a box in FreeCAD using its GUI, the box is centered on the origin. I think that's what threw me off. Also, the previous examples I did involved extrusions which were centered around the origin. That probably added to my confusion.

The cut direction boolean makes sense, but then I don't understand why the polygons cut at all through the plate. This screenshot shows that the polygons were cut half-way down into the plate.

polygon_cuts_in_plate

Here's the code that made that plate and the polygon pockets.

#Create a plate with two polygons cut through it
result = cadquery.Workplane("front").box(3.0,4.0,0.25).pushPoints ( [ ( 0,0.75 ),(0,-0.75) ]) \
    .polygon(6,1.0).cutThruAll()

#Get a cadquery solid object
solid = result.val()

#Use the wrapped property of a cadquery primitive to get a FreeCAD solid
Part.show(solid.wrapped)

I must still be missing something.

dcowden commented 10 years ago

​A fair question. It is because the workplane established initially is on the xy-plane ( running through the origin), and the polygons are created on this plane, and not on the surface of the box.

​Consequently, regardless of the direction flag in cutThruAll(), it only cuts through all in one direction.

​So the cut starts at the xy-work plane, and then cuts in either the positive or negative direction ( but not both). that means regardless of the direction flag, it will only cut 1/2 of the solid in this case.

It might make sense to change the behavior of cutThruAll to cut in both directions-- or at least provide an option to do so.

​This example works because the original workplane that was established is below the entire part, so the cut can go through the whole part:

​ return Workplane("front").box(3.0,4.0,0.25,centered=(False,False,False)).pushPoints ( [ ( 1.0,1.5 ),(1.0,2.55) ]).polygon(6,1.0).cutThruAll(True)

​ ​Similarly, the following example works because the box is created centered on the origin,but then we move the active workplane to the bottom surface before constructing the polygons, so that again they cut through all of the part when the cut goes in one direction:

​​ ​​ return Workplane("XY").box(3.0,4.0,0.25).faces("<Z").workplane().pushPoints ( [ ( 0,-0.75 ),(0,.75) ]).polygon(6,1.0).cutThruAll(False) ​

​The workplane established by faces("<Z") in this case is offset from the xy plane by 1/2 the thickness of the part, at z=-0.125

​For completeness, this example is similar-- but we establish a new plane​ on the top of the part, and then cut the other way:

​ return Workplane("XY").box(3.0,4.0,0.25).faces(">Z").workplane().pushPoints ( [ ( 0,-0.75 ),(0,.75) ]).polygon(6,1.0).cutThruAll(False) ​

​In short, workplane management is the answer to your question. This is definitely one of the reasons that workplane visualization would help-- if you were able to see the workplane, you'd immediately see that it is through the center of the part-- and it would probably have been more clear why the polygon cuts only cut through 1/2 of the part.

On Jun 25, 2014 11:14 PM, "Jeremy Wright" notifications@github.com wrote:

Thanks for the info Dave.

When I add a box in FreeCAD using its GUI, the box is centered on the origin. I think that's what threw me off. Also, the previous examples I did involved extrusions which were centered around the origin. That probably added to my confusion.

The cut direction boolean makes sense, but then I don't understand why the polygons cut at all through the plate. This screenshot shows that the polygons were cut half-way down into the plate.

[image: polygon_cuts_in_plate] https://cloud.githubusercontent.com/assets/1015439/3394381/afb16834-fcde-11e3-8e53-11ec9cb00d21.jpg

Here's the code that made that plate and the polygon pockets.

Create a plate with two polygons cut through itresult = cadquery.Workplane("front").box(3.0,4.0,0.25).pushPoints ( [ ( 0,0.75 ),(0,-0.75) ]) \

.polygon(6,1.0).cutThruAll()

Get a cadquery solid objectsolid = result.val()

Use the wrapped property of a cadquery primitive to get a FreeCAD solidPart.show(solid.wrapped)

I must still be missing something.

— Reply to this email directly or view it on GitHub https://github.com/dcowden/cadquery/issues/12#issuecomment-47183727.

jmwright commented 10 years ago

Thanks for explaining that. A workplane visualization feature sounds like a great idea.