Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Copy sketch entities into another sketch

sylvain_boyer6TGNB
Enthusiast

Copy sketch entities into another sketch

sylvain_boyer6TGNB
Enthusiast
Enthusiast

I am struggling with the following, I have 2 ketches in a components: 

->Cmp

-->Sketch_Target  (empty)

-->Sketch_Source (contains some sketch entities)

 

I am trying to copy the sketch entities from the source to the target then delete the source. 

 

 

try: 
     sketch_target = comp.sketches.item(0)
     sketch_source = comp.sketches.item(1)
     ui.messageBox("the component contains the sketches: "+ sketch_target.name +" and "+sketch_source.name)                
     sketch_source.copy(sketch_source.sketchCurves, adsk.core.Matrix3D.create(), sketch_target) 
except:
     ui.messageBox("cannot copy the sketch")

 

 

 

But it does not work. Does anyone has an example to share, or can tell me where I am wrong?

 

Sylvain

0 Likes
Reply
Accepted solutions (1)
243 Views
1 Reply
Reply (1)

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

The Sketch.copy() method expect an ObjectCollection object as it's first parameter and sketchCurves is not of that type.

You can replace your copy call as so:

    # sketch_source.copy(sketch_source.sketchCurves, adsk.core.Matrix3D.create(), sketch_target)
    sketch_source.copy(
        adsk.core.ObjectCollection.createWithArray([skc for skc in sketch_source.sketchCurves]),
        adsk.core.Matrix3D.create(),
        sketch_target)

 

Regards,

Jorge Jaramillo

 

0 Likes