@@ -2122,6 +2122,8 @@ def _addPendingWire(self, wire: Wire) -> None:
2122
2122
2123
2123
def _consolidateWires (self ) -> List [Wire ]:
2124
2124
2125
+ # note: do not use CQContext.popPendingEdges or Wires here, this method does not
2126
+ # clear pending edges or wires.
2125
2127
wires = cast (
2126
2128
List [Union [Edge , Wire ]],
2127
2129
[el for el in chain (self .ctx .pendingEdges , self .ctx .pendingWires )],
@@ -2159,39 +2161,33 @@ def wire(self, forConstruction: bool = False) -> "Workplane":
2159
2161
Returns a CQ object with all pending edges connected into a wire.
2160
2162
2161
2163
All edges on the stack that can be combined will be combined into a single wire object,
2162
- and other objects will remain on the stack unmodified
2164
+ and other objects will remain on the stack unmodified. If there are no pending edges,
2165
+ this method will just return self.
2163
2166
2164
2167
:param forConstruction: whether the wire should be used to make a solid, or if it is just
2165
2168
for reference
2166
- :type forConstruction: boolean. true if the object is only for reference
2167
2169
2168
2170
This method is primarily of use to plugin developers making utilities for 2-d construction.
2169
2171
This method should be called when a user operation implies that 2-d construction is
2170
- finished, and we are ready to begin working in 3d
2172
+ finished, and we are ready to begin working in 3d.
2171
2173
2172
2174
SEE '2-d construction concepts' for a more detailed explanation of how CadQuery handles
2173
- edges, wires, etc
2175
+ edges, wires, etc.
2174
2176
2175
2177
Any non edges will still remain.
2176
2178
"""
2177
2179
2178
- edges = self .ctx .pendingEdges
2179
-
2180
2180
# do not consolidate if there are no free edges
2181
- if len (edges ) == 0 :
2181
+ if len (self . ctx . pendingEdges ) == 0 :
2182
2182
return self
2183
2183
2184
- self .ctx .pendingEdges = []
2185
-
2186
- others = []
2187
- for e in self .objects :
2188
- if type (e ) != Edge :
2189
- others .append (e )
2190
-
2184
+ edges = self .ctx .popPendingEdges ()
2191
2185
w = Wire .assembleEdges (edges )
2192
2186
if not forConstruction :
2193
2187
self ._addPendingWire (w )
2194
2188
2189
+ others = [e for e in self .objects if not isinstance (e , Edge )]
2190
+
2195
2191
return self .newObject (others + [w ])
2196
2192
2197
2193
def each (
@@ -2757,10 +2753,7 @@ def twistExtrude(
2757
2753
"""
2758
2754
# group wires together into faces based on which ones are inside the others
2759
2755
# result is a list of lists
2760
- wireSets = sortWiresByBuildOrder (list (self .ctx .pendingWires ))
2761
-
2762
- # now all of the wires have been used to create an extrusion
2763
- self .ctx .pendingWires = []
2756
+ wireSets = sortWiresByBuildOrder (self .ctx .popPendingWires ())
2764
2757
2765
2758
# compute extrusion vector and extrude
2766
2759
eDir = self .plane .zDir .multiply (distance )
@@ -3210,13 +3203,12 @@ def cutThruAll(self, clean: bool = True, taper: float = 0) -> "Workplane":
3210
3203
3211
3204
:param boolean clean: call :py:meth:`clean` afterwards to have a clean shape
3212
3205
:raises ValueError: if there is no solid to subtract from in the chain
3206
+ :raises ValueError: if there are no pending wires to cut with
3213
3207
:return: a CQ object with the resulting object selected
3214
3208
3215
3209
see :py:meth:`cutBlind` to cut material to a limited depth
3216
3210
"""
3217
- wires = self .ctx .pendingWires
3218
- self .ctx .pendingWires = []
3219
-
3211
+ wires = self .ctx .popPendingWires ()
3220
3212
solidRef = self .findSolid ()
3221
3213
3222
3214
rv = []
@@ -3237,8 +3229,7 @@ def loft(
3237
3229
Make a lofted solid, through the set of wires.
3238
3230
:return: a CQ object containing the created loft
3239
3231
"""
3240
- wiresToLoft = self .ctx .pendingWires
3241
- self .ctx .pendingWires = []
3232
+ wiresToLoft = self .ctx .popPendingWires ()
3242
3233
3243
3234
r : Shape = Solid .makeLoft (wiresToLoft , ruled )
3244
3235
@@ -3268,9 +3259,7 @@ def _extrude(
3268
3259
# group wires together into faces based on which ones are inside the others
3269
3260
# result is a list of lists
3270
3261
3271
- wireSets = sortWiresByBuildOrder (list (self .ctx .pendingWires ))
3272
- # now all of the wires have been used to create an extrusion
3273
- self .ctx .pendingWires = []
3262
+ wireSets = sortWiresByBuildOrder (self .ctx .popPendingWires ())
3274
3263
3275
3264
# compute extrusion vector and extrude
3276
3265
eDir = self .plane .zDir .multiply (distance )
@@ -3316,11 +3305,8 @@ def _revolve(
3316
3305
3317
3306
This method is a utility method, primarily for plugin and internal use.
3318
3307
"""
3319
- # We have to gather the wires to be revolved
3320
- wireSets = sortWiresByBuildOrder (list (self .ctx .pendingWires ))
3321
-
3322
- # Mark that all of the wires have been used to create a revolution
3323
- self .ctx .pendingWires = []
3308
+ # Get the wires to be revolved
3309
+ wireSets = sortWiresByBuildOrder (self .ctx .popPendingWires ())
3324
3310
3325
3311
# Revolve the wires, make a compound out of them and then fuse them
3326
3312
toFuse = []
@@ -3373,19 +3359,17 @@ def _sweep(
3373
3359
mode = wire
3374
3360
3375
3361
if not multisection :
3376
- wireSets = sortWiresByBuildOrder (list ( self .ctx .pendingWires ))
3362
+ wireSets = sortWiresByBuildOrder (self .ctx .popPendingWires ( ))
3377
3363
for ws in wireSets :
3378
3364
thisObj = Solid .sweep (
3379
3365
ws [0 ], ws [1 :], p , makeSolid , isFrenet , mode , transition
3380
3366
)
3381
3367
toFuse .append (thisObj )
3382
3368
else :
3383
- sections = self .ctx .pendingWires
3369
+ sections = self .ctx .popPendingWires ()
3384
3370
thisObj = Solid .sweep_multi (sections , p , makeSolid , isFrenet , mode )
3385
3371
toFuse .append (thisObj )
3386
3372
3387
- self .ctx .pendingWires = []
3388
-
3389
3373
return Compound .makeCompound (toFuse )
3390
3374
3391
3375
def interpPlate (
0 commit comments