Examples of using sketch.copy

Examples of using sketch.copy

OldSchoolMakerD
Explorer Explorer
776 Views
3 Replies
Message 1 of 4

Examples of using sketch.copy

OldSchoolMakerD
Explorer
Explorer

I'd like to understand better how one can use the sketch.copy function.  What I'm doing in my script is letting a user select a face on a sketch, and then I want to copy and paste that sketch in multiple other sketches, optionally using the Matrix3D transformation to scale it.  My code uses

selFace = ui.selectEntity("Pick face to replicate", "Profiles")

to let someone pick the profile.  From there, I can get the entity of selFace, which itself is of type adsk.fusion.Profile. 

From the profile, I can get the sketch containing the profile.

Later, I'm basically calling sketch.copy using the profile's parent sketch, so it's like this:

profile.parentSketch.copy(**something**, mat3D, otherSketch)

The problem is that I keep getting

RuntimeError: 3 : invalid input in sketchEntities

depending on what I put in for **something**.  The API calls for an ObjectCollection there, and so I create a new ObjectCollection and add the selected profile to it.

I figure I'm either adding the wrong kinds of objects to the ObjectCollection, or I'm adding the wrong instances of objects to it -- because, I presume they must be entities that belong to the parentSketch in some way.

 

What's the right way to do this?  Given a sketch and a selected profile, how should I construct the ObjectCollection so that parentSketch.copy will work?

0 Likes
Accepted solutions (1)
777 Views
3 Replies
Replies (3)
Message 2 of 4

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi @OldSchoolMakerD ,

 

The Sketch.copy() method expect as first parameter an object collection of sketch curves, not of profile(s).

Since you have the profile, you can add all profileCurves inside all profilesLoops of the profile into the object collection, and that will solve your problem.

 

Hope this could help.  Let me know if this works for you.

 

Regards,

Jorge

Message 3 of 4

OldSchoolMakerD
Explorer
Explorer

Thanks!  I'll try that.  I guess reading the big API PDF doesn't make it easy for me to understand what's a child of Entity, etc., and being in Python instead of C++ isn't helping me understand that, either.

 

Also, sort of answering my own question here... I ran across this post.  Of course I found the day after posting my question...

 

https://forums.autodesk.com/t5/fusion-360-api-and-scripts/how-to-duplicate-a-sketch-by-using-api/td-...

 

0 Likes
Message 4 of 4

OldSchoolMakerD
Explorer
Explorer

@Jorge_JaramilloThat did the trick - thanks!  The following pseudocode:

-- Let the user select a profile

selFace = ui.selectEntity("Pick face to replicate", "Profiles")
profile = selFace.entity

 

create an empty adsk.core.ObjectCollection

for each loop in profile.profileLoops

  for each curve in loop.profileCurves

    add the curve to the objectCollection

profile.parentSketch.copy(objectCollection, matrix, targetSketch)

 

The next level issue I've run into is that sometimes the math gets weirded out and I can't Loft across the copied profiles, but that's for a different thread.

0 Likes