Delete multiple sketches

Delete multiple sketches

dinocoglitore
Advocate Advocate
824 Views
2 Replies
Message 1 of 3

Delete multiple sketches

dinocoglitore
Advocate
Advocate

Hi all, I am looking for a better way to delete multiple sketchs with only one or few instructions.

 

Actually I follow a simple method using a loop but I hope that exist a more efficient way using some Api method.

 

This what I do (I am a newbye so please excuse me !)

 

sketchArray = []

# in a loop I create sketches with assigned names:

..........

sketchPlane.name="SK-"+str(k)

 

# append name in an array

sketchArray.append(k)

sketchArray[k] = sketchPlane.name

 

.........

 

#in another loop (after I use all the sketches) I delete the sketches

for k in range(0,n):

  sketches.itemByName(sketchArray[k]).deleteMe()

 

Many Thanks

Dino

0 Likes
Accepted solutions (2)
825 Views
2 Replies
Replies (2)
Message 2 of 3

liujac
Alumni
Alumni
Accepted solution

Hi,

 

You may add a sub component under the root component and add the sketches to the sub component. Just delete the sub component at the end.

 

import adsk.core, adsk.fusion, adsk.cam, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        design = adsk.fusion.Design.cast(app.activeProduct)
        rootComp = design.rootComponent
        
        transform = adsk.core.Matrix3D.create()
        occ = rootComp.occurrences.addNewComponent(transform)
        
        subComp = occ.component
        sketches = subComp.sketches
        
        for i in range (0, 100):
            sketches.add(rootComp.xYConstructionPlane)
        
        occ.deleteMe()
        
        ui.messageBox('Done')

    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 3

dinocoglitore
Advocate
Advocate
Accepted solution

I thank you very much.

You answered  my question in a very elegant form. I will implement you solution in my script writing that you are the author so I can remeber how far is my knowledge from a correct way of using API.

Many thanks. 

Dino

 

0 Likes