Hello world!

204 views
Skip to first unread message

Todd Allen

unread,
Feb 5, 2016, 9:19:06 PM2/5/16
to CadQuery
I'm new to CadQuery and thinking about trying to port some of my models coded in Python for Fusion 360.  I thought I might get started with CadQuery by attempting to add a new feature.  One of the appealing aspects of CadQuery is it being open source.  I'd like to dive in and find out how easy or hard it is to contribute to the project as that is one of the key aspects for me to evaluate if I want to pursue using CadQuery as a primary choice for CAD.

A couple features I use a lot that I don't see in CadQuery are fillets for line sketches and subtractive (and intersection) combining of objects.  Sweep extrusions I'd also find useful.  Eventually, I'd also be interested in joints/assemblies, constrained motion and animation.  Before jumping in, I wanted to be sure of what is missing and not currently being worked on by anyone else.  And I'd welcome any advice as to how I should proceed and get started.  I've got a working install of the CadQuery Module for FreeCAD under Ubuntu 15.04 and have looked at and played with most of the examples.

I'm a retired programmer and went cold turkey on coding for several years.  Mostly I did assembly code for DSPs and I've only got a few months experience dabbling with CAD and even less with Python though I have a lot of experience with 3D graphics for video gaming.

Much thanks for all your efforts so far and any assistance I might receive jumping in.

Todd Allen

Todd Allen

unread,
Feb 6, 2016, 4:09:54 AM2/6/16
to CadQuery
I know bugs are supposed to be reported to the issue tracker and not here, but I'm guessing this isn't so much a CadQuery issue/bugs but rather some sort of system configuration problem and I'm hoping for a little guidance to track it down.

I've run through all of the test suite and everything apparently works except the following issues:


There was one caught unintentional error (as opposed to those in TestCQGI):

ERROR: testMultiFaceWorkplane (tests.TestCadQuery.TestCadQuery)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/todd/apps/cadquery_freecad_module/CadQuery/Libs/cadquery-lib/tests/TestCadQuery.py", line 490, in testMultiFaceWorkplane
    w = s.faces('>Z').workplane()
  File "/home/todd/apps/cadquery_freecad_module/CadQuery/Libs/cadquery-lib/cadquery/cq.py", line 345, in workplane
    center = Shape.CombinedCenter(self.objects)
  File "/home/todd/apps/cadquery_freecad_module/CadQuery/Libs/cadquery-lib/cadquery/freecad_impl/shapes.py", line 226, in CombinedCenter
    total_mass = sum(o.wrapped.Mass for o in objects)
  File "/home/todd/apps/cadquery_freecad_module/CadQuery/Libs/cadquery-lib/cadquery/freecad_impl/shapes.py", line 226, in <genexpr>
    total_mass = sum(o.wrapped.Mass for o in objects)
AttributeError: 'Part.TopoShape' object has no attribute 'Mass'


The following test suite functions cause uncaught segmentation faults:
testOccBottle, testSimpleMirror, testIbeam

The above were somewhat painful to track as there was no output to indicate the crashing function, just an abort.  By alphabetizing the list of test functions and seeing the last one to successfully complete, I was able identify them and suppress them from being tested, allowing me to get through the rest of the test suite.  The output in /tmp for everything else looked pretty good.

Anyway, does this pattern of failure suggest a likely culprit?  Otherwise is there a recommended debugging tool to dig deeper?

Finally, I suggest perhaps adding something to the docs regarding the test suite.  I think there is value there for users as well as developers.

Todd Allen

unread,
Feb 6, 2016, 5:53:58 AM2/6/16
to CadQuery
After reading up on Python ide's I decided to give the free wing101 a try.  It was easy to use and let me do breakpoint debugging.  Anyway the 3 test functions that abort with a segfault all call mirrorY() or mirrorX() and I think those calls are doing something to the model that later causes a crash in getSVG().  With an uncaught segfault there's no stack trace after the crash making homing in on the exact issue a bit tedious, but I can do so later after some sleep if needed.  I also remember when running the examples, I wasn't getting a crash from Ex009_Polylines.py which creates an IBeam using mirroring like the crashing test functions, but the resulting object rendered weird like maybe some faces had inverted or bad normals.

Jeremy Wright

unread,
Feb 6, 2016, 8:41:47 AM2/6/16
to Todd Allen, CadQuery

Hi Todd, and welcome to the community.

> A couple features I use a lot that I don't see in CadQuery are fillets for line sketches and subtractive (and intersection) combining of objects.  Sweep extrusions I'd also find useful.  Eventually, I'd also be interested in joints/assemblies, constrained motion and animation.  Before jumping in, I wanted to be sure of what is missing and not currently being worked on by anyone else.  And I'd welcome any advice as to how I should proceed and get started.  I've got a working install of the CadQuery Module for FreeCAD under Ubuntu 15.04 and have looked at and played with most of the examples.

Line sketching is tough in CadQuery. There is no 2D fillet feature, and complex sketches are tedious. We've talked about tying to improve that directly in CadQuery, or maybe just make it easier to import 2D sketches to build off of.

CadQuery can combine objects, but it's not very strong at all on boolean operations.

Sweep extrusion is on the To-Do list, but I'm not sure when it will get implemented.

It will probably be a long time before joints/assemblies, constrained motion and animation are implemented, if they get done at all. I don't think anyone would be opposed to those being added, we are just focused on other things.

About the error you're getting - What version of FreeCAD are you running? I'm guessing your error is related to this issue. https://github.com/dcowden/cadquery/issues/135

I've never tried Wing101. I've been using PyCharm for CadQuery development, and like it. Use whatever works for you though.

On Feb 6, 2016 5:53 AM, "Todd Allen" <speed...@gmail.com> wrote:
After reading up on Python ide's I decided to give the free wing101 a try.  It was easy to use and let me do breakpoint debugging.  Anyway the 3 test functions that abort with a segfault all call mirrorY() or mirrorX() and I think those calls are doing something to the model that later causes a crash in getSVG().  With an uncaught segfault there's no stack trace after the crash making homing in on the exact issue a bit tedious, but I can do so later after some sleep if needed.  I also remember when running the examples, I wasn't getting a crash from Ex009_Polylines.py which creates an IBeam using mirroring like the crashing test functions, but the resulting object rendered weird like maybe some faces had inverted or bad normals.

--
cadquery home: https://github.com/dcowden/cadquery
post issues at https://github.com/dcowden/cadquery/issues
run it at home at : https://github.com/jmwright/cadquery-freecad-module
see it in action at http://www.parametricparts.com
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cadquery/22de3c41-415f-4388-992a-da4ad3419cac%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave Cowden

unread,
Feb 6, 2016, 9:23:34 AM2/6/16
to Jeremy Wright, Todd Allen, CadQuery

Yes, @Todd, the tests should be passing... Certainly there shouldn't be segfaults!

In addition to the issue Jeremy pointed out, there are a couple of tests that print out stack traces while they are asserting error behavior, and we have talked about removing them so it doesn't look like a failure when the tests run. But without a doubt they should be passing.

Todd Allen

unread,
Feb 6, 2016, 1:11:58 PM2/6/16
to CadQuery, speed...@gmail.com
I'm using FreeCAD 0.14, git rev 3702 which is the version in the Ubuntu 15.10 repository.  The CadQuery docs say version 0.14 or later is ok.  If that isn't acccurate should I add the launchpad repository for FreeCAD to have the latest "Ubuntu stable" release or should I be cloning FreeCAD's github master branch?

I found the cut functions and can for the short term probably get by doing fillets post extrusion if there is a way to map between sketch corners and vertical edges in the extrusion, which will let me get started playing with redoing some models in CadQuery.  If I'm still mostly enamored with the CadQuery approach after that I'd expect to want to work on enhancing CadQuery's sketching features.  Using a separate process to do sketches and import them is not appealing.

Jeremy Wright

unread,
Feb 6, 2016, 1:32:01 PM2/6/16
to Todd Allen, CadQuery

I use the FreeCAD stable and daily PPAs since the version of FreeCAD in the Ubuntu repos is always woefully out of date.

Stable: https://launchpad.net/~freecad-maintainers/+archive/ubuntu/freecad-stable

Daily: https://launchpad.net/~freecad-maintainers/+archive/ubuntu/freecad-daily

I run off the daily PPA unless they break something major, them I roll back to stable.

It's fairly easy to use CadQuery's selectors to select edges and then fillet them after extrusion.

https://github.com/dcowden/cadquery/blob/master/examples/FreeCAD/Ex020_Rounding_Corners_with_Fillets.py

However, it sounds like that no matter what, you would want advanced 2D features anyway.

Todd Allen

unread,
Feb 6, 2016, 4:57:50 PM2/6/16
to CadQuery, wrig...@gmail.com
I forked the dcowden/cadquery in anticipation of making a fix for the segfault.  I tracked it to line 252 of exporters.py
    (visibleG0,visibleG1,hiddenG0,hiddenG1) = Drawing.project(shape,viewVector)
which calls into FreeCAD.

So it looks like this issue originates in FreeCAD with an issue in mirroring and then crashes in FreeCAD projecting a corrupted shape.

At this point I'm inclined to switch to a newer release of FreeCAD than to pursue this deeper into the older FreeCAD 14 code.

BTW, I had previously cloned the jmwright/cadquery-freecad-module before also forking dcowden/cadquery.  Is there an elegant way for me to retain the freecad cadquery workbench integration while using my forked branch of cadquery from dcowden?

Dave Cowden

unread,
Feb 6, 2016, 5:15:44 PM2/6/16
to Todd Allen, CadQuery, Jeremy Wright
awesome sleuthing, thanks for digging that up. that makes sense, because a fairly recent contribution involved mirroring I think.

I'll let @jmwright answer your question on the workbench-- he knows it better than i do. If you are on a linux system, you might be able to replace the cadquery folder under your cfm module with a symlink to your cloned cq project.

Jeremy Wright

unread,
Feb 6, 2016, 5:28:50 PM2/6/16
to Dave Cowden, Todd Allen, CadQuery

The module (CFM) includes CadQuery as a git subtree, so I'm theory, you should be able to do all your branching inside CFM.

https://medium.com/@v/git-subtrees-a-tutorial-6ff568381844#.rj1vnis8q

I've never tried setting up a pull request that way though.

Todd Allen

unread,
Feb 7, 2016, 1:37:55 PM2/7/16
to CadQuery, speed...@gmail.com
The launchpad FreeCAD stable ppa doesn't have packages for Ubuntu 15.10, though the daily ppa does.  I decided to instead clone FreeCAD from github and build a debug version.

I still get the segfaults in CadQuery's test suite when using my build of FreeCAD rev 16 from the latest github master branch.  But it looks like to chase them deeper into the external FreeCAD lib built from .cpp files, I'll also need to build a debug version of the Python interpreter...

I'm guessing I'm still getting the crashes because FreeCAD depends on OCE.  The OCE packages I got from the Ubuntu repository were revision 15.  There's a launchpad OCE ppa but it only contains revs 15 and 17.1, no rev 16.  It looks like I'll have to try my luck with OCE rev 17.1 or I'll have to build OCE from source too.

I love the idea of selectors but they don't seem universally appropriate.  For complex sketches especially those generated algorithmically I think they will be hard to use.  I suppose one might write an algorithm to generate a sequence of selectors to find each edge but it seems a perverse thing to do.

Jeremy Wright

unread,
Feb 7, 2016, 1:51:10 PM2/7/16
to Todd Allen, CadQuery

I created a script to set up an OCE/PythonOCC development environment. You can specify the version tag name, and comment out the installation steps for PythonOCC. You should be able to add any compilation options you need too.

Todd Allen

unread,
Feb 10, 2016, 1:11:46 PM2/10/16
to CadQuery
One of my desires is to sketch filleted corners.  And another is to do sweeps.  Here's an implementation in FreeCAD of one of my approaches for these in Fusion 360.  Fusion 360 has an amazingly cumbersome API and to shield myself as much as possible from it I do my modeling through a layer of routines such as this.  My first glance at Cadquery got me excited because it also shields one from the ugliness of an underlying API and in a manner with much flexibility.  Being new to Python and FreeCAD my approach lacks the sophistication of Cadquery's.  Although my tests use static point sequences, in practice I often generate them algorithmically.  I expect they could also come from Cadquery's stack.  Perhaps after using Cadquery more I might see a nice way to integrate my approach with Cadquery's.

All comments, especially those pointing out problems or suggesting improvements are most appreciated.

I'm attaching my code as a file, if desired I can repost it inline.  It should run in any environment with FreeCAD.
pointSequences.py

Dave Cowden

unread,
Feb 10, 2016, 1:29:43 PM2/10/16
to Todd Allen, CadQuery
Hi, Todd:

I had a brief look at your code-- in particular, the pointsToWire function.  The 'secret sauce' in your code is really this line:

wire = DraftGeomUtils.filletWire(Part.Wire(edges), bendRadius)

which i assume fillets all of the corners to a given radius.

This would be very easy to integrate with cadquery.  There is already a cadquery function that does the majority of the code in pointsToWire-- constructing a polyline from a list of points. 


So the thing to do would be to implement a CQ function that fillets wires that are on the stack. it would work like this:

pts = [
(0, H/2.0),
(W/2.0, H/2.0),
(W/2.0, (H/2.0 - t)),
(t/2.0, (H/2.0-t)),
(t/2.0, (t - H/2.0)),
(W/2.0, (t - H/2.0)),
(W/2.0, H/-2.0),
(0, H/-2.0)
]

result = cadquery.Workplane("front").polyline(pts).fillet(bendRadius )

This would be a pretty easy function to write-- you would just grab all of the items on the current stack, and then aply the DraftGeomUtils.filletWire(..) function to it.

This would look a little like:

def filletWire(self, bendRadius ):
   
   newWires = []
for wire in self.wires().vals():
newWire = DraftGeomtils.filletWire(wire)
newWires.append(newWire)

return self.newObject(newWires)

It couldnt look exactly like this, because the filletWire function needs to be added to CQ.py, but we shouldnt add any freecad-specific code in CQ.py or Workplane.py. FreeCAD specific code goes in freecad_impl, so we'd need to write a function in there, and then call that.

But hopefully that communicates the idea.

To try out the concepts, you might try writing this as a cadquery plugin- which you can do without contributing back to the repository. Its an 'advanced' feature, but you can actually write your own function and hook it into the cadquery object pretty easily.

This reference might help with that: http://dcowden.github.io/cadquery/extending.html

It should be easy to write your pointsToWire code as a cadquery plugin using the format described, and you can see how you like it.

--
cadquery home: https://github.com/dcowden/cadquery
post issues at https://github.com/dcowden/cadquery/issues
run it at home at : https://github.com/jmwright/cadquery-freecad-module
see it in action at http://www.parametricparts.com
---
You received this message because you are subscribed to the Google Groups "CadQuery" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cadquery+u...@googlegroups.com.

Todd Allen

unread,
Feb 10, 2016, 2:28:44 PM2/10/16
to Dave Cowden, CadQuery

On Wed, Feb 10, 2016 at 12:29 PM, Dave Cowden <dave....@gmail.com> wrote:
The 'secret sauce' in your code is really this line:

wire = DraftGeomUtils.filletWire(Part.Wire(edges), bendRadius)

which i assume fillets all of the corners to a given radius.

Yes, it fillets all corners.  There's also a DraftGeomUtils.fillet() function that takes a list of edges instead of a wire which I use when applying different radius values to each corner.  With the rich set of Vector and Arc primitives it would have been easy enough to write the fillet functions if they didn't already exist, but I was glad when I saw it in DraftGeomUtils.

As far as bluesky ambitious dreaming, I didn't see much in the documented portion of the FreeCAD API for assembly and animation.  However, there is the robot workbench which hopefully contains API like primitives for those purposes but that can wait a while.

Dave Cowden

unread,
Feb 10, 2016, 2:31:37 PM2/10/16
to Todd Allen, CadQuery
As far as bluesky ambitious dreaming, I didn't see much in the documented portion of the FreeCAD API for assembly and animation.  However, there is the robot workbench which hopefully contains API like primitives for those purposes but that can wait a while.

​Ha, yeah, for assembly and animation, i think you're definitely out of CQ and FC's domain. I'd be happy to just solve the simpler problem of creating parts well first!  This problem is already more than i can handle ;)​
 
Reply all
Reply to author
Forward
0 new messages