- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I wrote a little script to find all projected sketch curves and delete them all. The script accurately counts that there are 10 projected sketch curves, then I call deleteMe method on all of them (in a for loop) but several remain untouched. It seems to be exactly every other curve that remains untouched.
It seems strange that they are not all deleted. I've even tried deleting all curves in the sketch but it still only deletes half of the sketches.
Why is the deleteMe method only deleting half of the curves and skipping the others? Is there some trick to iterating over the sketchCurve objects in the collection? Is this a bug?
Here is a link to the screencast. I've attached the test design file here. The code is below:
#Author-Sam Chaney
#Description-Selects and deletes all projected sketch entities
import adsk.core, adsk.fusion, adsk.cam, traceback, sys
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(app.activeProduct)
active_component = design.activeComponent
sketches = active_component.sketches
active_sketch = adsk.core.Application.get().activeEditObject #Use this instead of chosen_sketch if you want to use active sketch
sketch_name, cancelled = ui.inputBox('Enter exact name of sketch to delete projected entities')
if cancelled:
ui.messageBox('Cancelled!')
sys.exit('Cancelled')
if sketches.itemByName(sketch_name) is None:
ui.messageBox(f'Sketch named "{sketch_name}" not found')
sys.exit('Sketch not found')
chosen_sketch = sketches.itemByName(sketch_name)
curves = chosen_sketch.sketchCurves
ui.messageBox(f'Curve count is {curves.count}')
lines = curves.sketchLines
points = chosen_sketch.sketchPoints
def is_projected(entity):
projected_entities =[]
if entity.isLinked:
projected_entities.append(entity)
return projected_entities
def delete_projected(collection):
for entity in collection:
# if entity.isLinked:
# ui.messageBox('entity was linked')
entity.deleteMe()
def delete_all(collection):
for entity in collection:
entity.deleteMe # should delete all curves in sketch no matter what
delete_projected(curves)
delete_all(curves) # even this only deletes 5 lines. It's every other line
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.