Comments (9)
@rowanG077 glad to hear that CQ-editor works! Regarding the issue - this is actually expected behavior for CQ2. Every operation creates new workplane object which holds reference to its parent. You need to store the result explicitly:
top_workplane = top_workplane.transformed(rotate = (0, 0, 0))\
.transformed(offset = (0, 3, 0))\
.rect(1, 1)\
.cutThruAll()
The rationale for this change was ease of debugging. Every operation is now stored on the stack and you can inspect all the steps using the Inspect CQ object
function.
from cq-editor.
I see. So is there no other way to somehow store a known point from which to do multiple things? If I store the new workplane and then use that then of course I get a completely different part since I rotate and offset the workplane each time.
Basically if I want to old behavior I would have to undo all transforms each time I perform this. This vastly increases the code size and complexity.
Would the "Tagged entities" feature help with this. It's mentioned on the documentation page: https://dcowden.github.io/cadquery/roadmap.html.
from cq-editor.
Maybe something like explicitly storing a workplane and then restoring it into a part could work. Something like this:
import cadquery as cq
result = cq.Workplane("XY" )\
.box(10, 10, 1)
top_workplane = result.faces(">Z").workplane().store()
result = top_workplane.transformed(rotate = (0, 0, 0))\
.transformed(offset = (0, 3, 0))\
.rect(1, 1)\
.cutThruAll()
result = result.loadWorkplane(top_workplane)
.sphere(1)
show_object(result)
I don't have any clue about the internals of cadquery or pythonocc to say whether this is possible at all but something like this seems to be the most elegant while preserving that every operation is now stored on the stack.
from cq-editor.
With the current API I was able to come up with the following solution:
from cadquery import *
class RectMaker(object):
def __init__(self,a=0.8,angle=120):
self.ix = 0
self.angle=angle
self.w = cq.Wire.makePolygon(map(Vector,[(-a,a,0),(a,a,0),(a,-a,0),(-a,-a,0),(-a,a,0)]))
def __call__(self,pt):
rv = self.w.rotate((0,0,0),(0,0,1),self.ix*self.angle).translate(pt)
self.ix+=1
return rv
r = cq.Workplane("XY" )\
.box(10, 10, 1).faces(">Z")\
.polarArray(3.5,0,360,3).eachpoint(RectMaker()).cutThruAll()
show_object(r)
I must say I do not fully like it. We do have a polarArray
, but no clean way to rotate the object at each point. @jmwright @dcowden any thoughts on how to improve this?
from cq-editor.
@rowanG077 @adam-urbanczyk I'm not sure that I have much that's useful to add. There has been discussion before about using copy.copy and copy.deepcopy as @rowanG077 is using store() in the code above (I think), but I'm not sure of the implications.
I haven't spent enough time with the CQ 2.0 API to really come up with a cleaner or more concise solution than @adam-urbanczyk posted. His solution does have a nice code re-use aspect to it. The RectMaker class can be modified and reused for any number of use cases. There's more boilerplate with Adam's code, but less repetition than with the original example. I'm not sure how helpful this all is for @rowanG077 though.
from cq-editor.
Thank you for providing a solution. In this case this works fine of course. But in general I use storing workplanes for multiple reasons. For instance in one of the parts I do something like this example and then keep on using that workplane to add other things to the part. Sometimes it's very impractical to obtain the exact some workplane again because the part has been modified.
Something I have been thinking about is the implement a transform stack. Then I can obtain a workplane, transform it and then undo those transforms to obtain the original workplane. This would require monkey patching a lot of methods though which also sucks. (center, transform...)
from cq-editor.
Sometimes it's very impractical to obtain the exact some workplane again because the part has been modified.
By default, CadQuery uses the center of mass to determine the center of a workplane. This leads to some unintuitive behavior when you remove material from a model in an asymmetrical way, because that center moves. Using the geometric bounding box helps combat that. Also, using the direction Nth selectors, along with the logical selector operators can help you get back to an original location of a workplane.
from cq-editor.
@rowanG077 here is yet another solution that is closest to your design intent. I must say that personally I'd prefer to go the polarArray
way and maybe extend the API of CQ to allow for rotation of each wire.
I will close this issue. If you want to continue or have similar issues regarding CQ2.0 please use the cadquery repo https://github.com/CadQuery/cadquery.
import cadquery as cq
result = cq.Workplane("XY" )\
.box(10, 10, 1)
top_workplane = result.faces(">Z").workplane()
starting_plane = top_workplane.plane
top_workplane = top_workplane.transformed(
rotate = (0, 0, 0)
)\
.transformed(
offset = (0, 3, 0),
)\
.rect(1, 1)\
.cutThruAll()
top_workplane.plane = starting_plane
top_workplane = top_workplane.transformed(
rotate = (0, 0, 120)
)\
.transformed(
offset = (0, 3, 0),
)\
.rect(1, 1)\
.cutThruAll()
top_workplane.plane = starting_plane
top_workplane = top_workplane.transformed(
rotate = (0, 0, 240)
)\
.transformed(
offset = (0, 3, 0),
)\
.rect(1, 1)\
.cutThruAll()
show_object(top_workplane)
from cq-editor.
@adam-urbanczyk Yeah in this case using polarArray
is better. But it's in some cases to have a constant starting point. In some parts I do over 10 things on a single workplane and use transforms each time to get to the correct locations. Rewritting would have been a nightmare.
Thank you for your quick support!
from cq-editor.
Related Issues (20)
- Can you add the function of importing, .stp, .step, and .stl format files? HOT 2
- Make touchpads and touch-screens usable for navigating the 3D view (with patch inside) HOT 1
- Permit disabling fov change during reload HOT 2
- Using more editor features from spyder HOT 1
- vi mode using vim-spyder HOT 4
- Request: new stable release - or clarify recommended installation method HOT 3
- Dark mode theme HOT 2
- Is it possible to use cq-warehouse inside a Pre-Built Packages ? HOT 3
- When exception is raised, the "Current traceback" window is empty HOT 3
- Bug on trying to open cq-editor HOT 1
- fit and render on file opening HOT 2
- Installation with Micromamba fails HOT 9
- Can't launch CQ-editor nor cadquery on Raspberry pi HOT 4
- Fails to Run on pop OS HOT 1
- CQ Editor cannot find files in module search path HOT 4
- Where did Linux nightly release go? HOT 2
- show_object fails with TypeError HOT 3
- Not runable after installing according to Readme HOT 2
- copy traceback
- Drop-downs not working
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cq-editor.