API: Copying a SketchBlockDefinition from one part file to another

API: Copying a SketchBlockDefinition from one part file to another

mike_ponti
Enthusiast Enthusiast
617 Views
2 Replies
Message 1 of 3

API: Copying a SketchBlockDefinition from one part file to another

mike_ponti
Enthusiast
Enthusiast
hi, Does anybody have any guidance on copying a sketch block defintion from one part file to another? So far as I can see, I will have to go through each property in the source sketch block defintion and create equivalent objects to place in the destination sketch block definition. Any ideas on a more efficient way to handle this would be appreciated! Thanks Mike
0 Likes
Accepted solutions (1)
618 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

You can use the CopyTo method to copy a sketch block definition from one document to another.  Below is a very basic example that illustrates it.

 

Public Sub CopyBlocks()
    ' Somehow get a reference to the document you want to copy from and the
    ' one you're copying to.
    Dim sourceDoc As PartDocument
    Dim targetDoc As PartDocument
    Set sourceDoc = ThisApplication.Documents.Item(4)
    Set targetDoc = ThisApplication.Documents.Item(5)
    
    ' Get the sketch block definition you want to copy.
    Dim sourceBlockDef As SketchBlockDefinition
    Set sourceBlockDef = sourceDoc.ComponentDefinition.SketchBlockDefinitions.Item(1)
    
    ' Copy the sketch block definition into the other document.
    Call sourceBlockDef.CopyTo(targetDoc)
End Sub

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

mike_ponti
Enthusiast
Enthusiast

Thanks, not sure how I missed that call in the api file. Smiley Frustrated

0 Likes