Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Examples of using sketch.copy

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
OldSchoolMakerD
152 Views, 3 Replies

Examples of using sketch.copy

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?

3 REPLIES 3
Message 2 of 4

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

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-...

 

Message 4 of 4

@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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report