dcowden / cadquery

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

rotateAboutCenter Not Working #34

Closed jmwright closed 9 years ago

jmwright commented 10 years ago

OS: Ubuntu 14.04 CQ Version: 0.1.5 (installed via pip) FreeCAD Version: 0.14

I've tried quite a few configurations of rotateAboutCenter and have not been able to get any of them to work in FreeCAD. I looked back through the examples to try to find how to call it correctly, and found this one:

Ex023_Parametric_Enclosure

I tested that example in FreeCAD and found that rotateAboutCenter does not seem to work in it either.

jmwright commented 10 years ago

I'm now using the newly added importStep function, and I'm getting the following when I try to use rotateAboutCenter on the returned CQ object.

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/cadquery/CQ.py", line 674, in rotateAboutCenter
    return self.each(_rot,False)
AttributeError: 'CQ' object has no attribute 'each'

Here are the steps that will reproduce the error in the FreeCAD Python console.

import cadquery
from cadquery import importers
cq_elec_switch = importers.importStep("/home/jwright/Documents/Projects/pbswitch/vendor/parts/SS_01GL_E.step")
cq_elec_switch.rotateAboutCenter((1, 0, 0), 90.0)

I thought maybe it was because I was passing a CQ object to rotateAboutCenter instead of the stack, but I can't figure out the incantation to make it work.

Any thoughts?

jmwright commented 9 years ago

I'm working on this along with the CQ.rotate addition. Here's some more information. I built the following test script.

import sys
sys.path.append('/home/jwright/Documents/Projects/CadQuery/cadquery')
import cadquery
from cadquery import importers

this_works = cadquery.Workplane("XY").box(5, 5, 5)
print "This works: " + str(this_works)
this_works = this_works.rotateAboutCenter((0, 0, 1), 90)

step_location = '/home/jwright/Documents/Projects/CustomFitSwitch/vendor/SS_01GL_E.step'
this_doesnt = importers.importStep(step_location)
print "This doesn't: " + str(this_doesnt)
this_doesnt = this_doesnt.rotateAboutCenter((0, 0, 1), 90)

Here's the output.

$ python testrotate.py
This works: <cadquery.CQ.Workplane object at 0x7f6ca0956d50>
This doesn't: <cadquery.CQ.CQ object at 0x7f6ca0956e10>
Traceback (most recent call last):
  File "testrotate.py", line 13, in <module>
    this_doesnt = this_doesnt.rotateAboutCenter((0, 0, 1), 90)
  File "/home/jwright/Documents/Projects/CadQuery/cadquery/cadquery/CQ.py", line 704, in rotateAboutCenter
    return self.each(_rot, False)
AttributeError: 'CQ' object has no attribute 'each'

The CQ class doesn't have an each function, which makes sense to me since it wraps a single solid (I think). Workplane does include each though. I'm not sure what the best way to fix this is yet. I can make rotateAboutCenter work now, but I want to respect the original intent.

dcowden commented 9 years ago

wow now you're testing my code memory!

IIRC Workplane is a subclass of the CQ object. so we could consider moving the each function up to the CQ object.

On Wed, Dec 10, 2014 at 11:53 AM, Jeremy Wright notifications@github.com wrote:

I'm working on this along with the CQ.rotate addition. Here's some more information. I built the following test script.

import sys sys.path.append('/home/jwright/Documents/Projects/CadQuery/cadquery')import cadqueryfrom cadquery import importers

this_works = cadquery.Workplane("XY").box(5, 5, 5)print "This works: " + str(this_works) this_works = this_works.rotateAboutCenter((0, 0, 1), 90)

step_location = '/home/jwright/Documents/Projects/CustomFitSwitch/vendor/SS_01GL_E.step' this_doesnt = importers.importStep(step_location)print "This doesn't: " + str(this_doesnt) this_doesnt = this_doesnt.rotateAboutCenter((0, 0, 1), 90)

Here's the output.

$ python testrotate.py This works: <cadquery.CQ.Workplane object at 0x7f6ca0956d50> This doesn't: <cadquery.CQ.CQ object at 0x7f6ca0956e10> Traceback (most recent call last): File "testrotate.py", line 13, in this_doesnt = this_doesnt.rotateAboutCenter((0, 0, 1), 90) File "/home/jwright/Documents/Projects/CadQuery/cadquery/cadquery/CQ.py", line 704, in rotateAboutCenter return self.each(_rot, False) AttributeError: 'CQ' object has no attribute 'each'

The CQ class doesn't have an each function, which makes sense to me since it wraps a single solid (I think). Workplane does include each though. I'm not sure what the best way to fix this is yet. I can make rotateAboutCenter work now, but I want to respect the original intent.

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

jmwright commented 9 years ago

The CQ object wraps "a CAD primitive", which sounds like it wraps just one. If that's the case, should it really have an each function?

I think I might have a solution.

  1. Keep the rotateAboutCenter function in CQ, but have it just use the rotate function that I finished earlier today. Those would both rotate only the single wrapped CAD primitive.
  2. Add a rotateAllAboutCenter function to Workplane that does what the current rotateAboutCenter in CQ does.

Does that sounds like a good solution?

jmwright commented 9 years ago

Maybe I'm looking at this wrong. The translate function in the CQ class acts on the stack too, but it seems to do it in a differently.

http://parametricparts.com/docs/classreference.html?highlight=translate#cadfile.cadutils.cadquery.CQ.translate

dcowden commented 9 years ago

I'd prefer to leave the old function doing what it did to avoid breaking existing scripts that use it. Maybe the new function should have th e new behavior? On Dec 10, 2014 2:02 PM, "Jeremy Wright" notifications@github.com wrote:

The CQ object wraps "a CAD primitive", which sounds like it wraps just one. If that's the case, should it really have an each function?

I think I might have a solution.

  1. Keep the rotateAboutCenter function in CQ, but have it just use the rotate function that I finished earlier today. Those would both rotate only the single wrapped CAD primitive.
  2. Add a rotateAllAboutCenter function to Workplane that does what the current rotateAboutCenter in CQ does.

Does that sounds like a good solution?

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

jmwright commented 9 years ago

Moving each would probably be a good idea. PyCharm flags each as being undefined for rotateAboutCenter since each is not at the top CQ level.

I'll go ahead and leave the implementation of rotateAboutCenter alone, but try moving each up to the CQ class.

jmwright commented 9 years ago

It looks like the Workplane class is duplicated between CQ.py and workplane.py. What's the reason for that?

dcowden commented 9 years ago

No good reason. It's probably a mistake when I restored from PP to create the standalone cq version.

I'm not even sure which one is the right one! I f isn't know there were two. On Dec 10, 2014 10:10 PM, "Jeremy Wright" notifications@github.com wrote:

It looks like the Workplane class is duplicated between CQ.py and workplane.py. What's the reason for that?

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

jmwright commented 9 years ago

So, I realized last night that all of my issues with rotate and rotateAboutCenter stem from returning a CQ object from the importSTEP function instead of CQ.Workplane. I think that was the first thing I contributed to CQ. If cadquery.Workplane("XY").box(5, 5, 5) returns a CQ.Workplane, then importSTEP probably should too. I'm going to close this issue and the rotate issue as wontfix.

I started experimenting with returning a CQ.Workplane object from importSTEP last night, and hit a few problems. I may start an issue on that if I don't get any traction.

I may also start a separate issue about the duplicate Workplane code once I've had a chance to dig into it a little more.

jmwright commented 9 years ago

I thought that fixing STEP import (commit 7c8f0e40c4f87199b06bc2159039f1af53e9445f ) would fix this issue. It fixed part of the issue, but I'm still having trouble. The each call inside rotateAboutCenter is returning a CQ.Workplane object with no objects inside of it. I think that's why rotateAboutCenter seems to have no effect when I use it. I hope to have time tomorrow to troubleshoot this a little more.

jmwright commented 9 years ago

Fixed in pull request #59