Copy Sketch from part occurrence to main assembly

Builder
Builder

Hello there.

 

I'm struggling with the CopySketch command, with no success yet. My goal is copying (with link) into the main assembly a sketch that is placed inside one of the occurrences placed in that assembly. I work this way because I'm going to define a number of sketches with patterns in just one part, which will be copied to a high number of different assemblies containing that "base-patterns" part. So, editing just that part will update all patterns on all assemblies.

 

I use this approach a lot working with SE patterns, using the same part sketch in different assemblies in order to generate linked patterns.

 

From the API, I have tried several approaches, with no succes, Copysketch always raises an exception. Remember, the copy comes from the occurrence and must be placed in the main assembly:

 

 

 Private Sub AddPatrernAndCopySketches(objAssemblyDoc As SolidEdgeAssembly.AssemblyDocument,
                                      (strPattPartFilename As String)
  
        Dim objOcc As SolidEdgeAssembly.Occurrence

'Add the part with sketches to copy and reach the sketches collection objOcc = objAssembly.Occurrences.AddByFilename(strPattPartFilename) Dim objPartDoc As SolidEdgePart.PartDocument = CType(objOcc.OccurrenceDocument, SolidEdgePart.PartDocument) Dim objSketches As SolidEdgePart.Sketchs = objPartDoc.Sketches
'Copy each of the sketches into the main-parent assebmly For i As Integer = 1 To objSketches.Count 'Build a top level reference for the sketch. Is this correct??? Dim objSketchRef As SolidEdgeFramework.Reference = CType(objAssembly.CreateReference(objOcc, objSketches.Item(i)), SolidEdgeFramework.Reference) 'This fails and makes me soooo sad!
objAssembly.CopySketch(objSketchRef, objAssemblyDoc, True) Next ... End Sub

 

According to the documentation, the code shown should work, since I use a Reference for the Sketch and the main AssemblyDocument as the target. Not sure if the Reference definition is wrong or simply this command can't work in bottom->up direction. The only example I have found deals with a sketch copy from the main assembly to one of the occurrences.

 

I have tried passing the Sketch directly, not by means of a Reference, with no success. Also, I have tried to use the Profile object inside the Sketch, instead of the Sketch itself, with the same result.

 

Any clues? Sketch copying is a powerful feature when dealing with patterns.

 

Much thanks in advance!

 

 

 

 

1 REPLY

Re: Copy Sketch from part occurrence to main assembly

Builder
Builder

It seems that i have found the problem. The fourth  (reportedly) optional argument for CopySketch must be present, and in a nice flawor. Quite weird.

 

Different results:

 

Private Sub AddPatrernAndCopySketches(objAssemblyDoc As SolidEdgeAssembly.AssemblyDocument,
strPattPartFilename As String)

Dim objOcc As SolidEdgeAssembly.Occurrence

'Add the part with sketches to copy and reach the sketches collection
objOcc = objAssembly.Occurrences.AddByFilename(strPattPartFilename)

Dim objPartDoc As SolidEdgePart.PartDocument = CType(objOcc.OccurrenceDocument,
SolidEdgePart.PartDocument)

Dim objSketches As SolidEdgePart.Sketchs = objPartDoc.Sketches

'Copy each of the sketches into the main-parent assebmly
For i As Integer = 1 To objSketches.Count
'Build a top level reference for the sketch.
Dim objSketchRef As SolidEdgeFramework.Reference = CType(objAssembly.CreateReference(objOcc, objSketches.Item(i)),
SolidEdgeFramework.Reference)
'This fails
objAssembly.CopySketch(objSketchRef, objAssemblyDoc, True)

'This works
objAssembly.CopySketch(objSketchRef, objAssemblyDoc, True, Nothing)

'This also works, and we get some useful trace info
Dim objErrors As SolidEdgeConstants.CopySketchErrorStatusConstants
objAssembly.CopySketch(objSketchRef, objAssemblyDoc, True, CObj(objErrors))

'...but this fails, too!
objAssembly.CopySketch(objSketchRef, objAssemblyDoc, True, New Object)
Next
...
End Sub

 

The command works fine from assembly to occurrences and viceversa, using Layout or Sketch to feed it and Occurrence or Reference to specify placement. But beware with the last not-so-optional argument!

 

Hope someone finds this useful!