trying to duplicate/copy-paste sketch via api/script

vsent4
Community Visitor

trying to duplicate/copy-paste sketch via api/script

vsent4
Community Visitor
Community Visitor

insimple words i need to just copy and paste a sketch in same component

the code im using is given below

 

i dont understand whats my mistake and have started to think maybe the way i'm trying todo is not currect

 

your simple input on best way to dupilcate/copy-paste a sketch with the flexibility to transform new sketch will give me results to my 2 days of brain stroming thanks

 

added a screen shot showing 'asdf' sketch is having a simple circle which need to be duplicated in another sketch of the same component

 

please feel free to be creative copy-paste in same or different component doesnt matter or even different file


import adsk.core, adsk.fusion, traceback

def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface

# Get active design
product = app.activeProduct
design = adsk.fusion.Design.cast(product)
sketch = adsk.fusion.Sketch
transform = adsk.core.Matrix3D
objcol = adsk.fusion.Sketch

# Get root component in this design
rootComp = design.rootComponent

# Get the first sub component
occs = rootComp.occurrences
subComp1 = occs.item(0).component

sketchInSubComp1 = subComp1.sketches.item(0)
ui.messageBox(str(sketchInSubComp1.name))

# create a new/copy sketch
compSketchProp = subComp1.sketches
xyPlane = subComp1.xYConstructionPlane #only selects the xy constructionplane
#createSketchSubComp2 = subComp1.sketches.add(xyPlane)
copysketchs = sketch.copy(subComp1,transform.copy,xyPlane)

except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

 

vsent4_0-1667818402318.png

 

0 Likes
Reply
217 Views
1 Reply
Reply (1)

Rushikesh.kadam
Autodesk
Autodesk

@vsent4 here is a similar post on copying a sketch using API https://forums.autodesk.com/t5/fusion-360-api-and-scripts/how-to-duplicate-a-sketch-by-using-api/m-p....

 

Regards,




Rushikesh Kadam
Senior QA Engineer
Quality Assurance
Autodesk, Inc.


1 Like