Issue
Is there an example available that shows how to add a sketch to an Assembly using the API?
Solution
Proxy objects represent an object within an assembly and can be used to add a sketch. For example, if you insert the same part twice into an assembly all of the faces of the part are accessible through either one of the occurrences. The actual faces only exist in the part, not in the assembly but they are represented in the assembly as FaceProxy objects. The FaceProxy object supports all of the methods of a standard Face object but any queries will return information as if that face actually exists in the assembly.
The example below uses a PlanarSketchProxy. It creates a PlanarSketch in the part and then creates the proxy in the assembly for the sketch. This sketch then behaves as if it exists in the assembly. In this case, this means that it automatically does the transformations between assembly and part space.
Public Sub CreateSplineInPart()
' assume we have had inventor application
Dim oAsmDoc As AssemblyDocument
oAsmDoc = _InvApplication.ActiveDocument
Dim oOcc As ComponentOccurrence
oOcc = oAsmDoc.ComponentDefinition.Occurrences.Item(1)
Dim oPartDef As PartComponentDefinition
oPartDef = oOcc.Definition
Dim oSketch As PlanarSketch
oSketch = oPartDef.Sketches.Add( _
oPartDef.WorkPlanes.Item(3))
Dim oSketchProxy As PlanarSketchProxy = Nothing
Call oOcc.CreateGeometryProxy( _
oSketch, oSketchProxy)
Dim oTG As TransientGeometry
oTG = _InvApplication.TransientGeometry
Dim oPoints As ObjectCollection
oPoints = _
_InvApplication.TransientObjects. _
CreateObjectCollection
Call oPoints.Add( _
oSketchProxy.ModelToSketchSpace( _
oTG.CreatePoint(0, 0, 0)))
Call oPoints.Add( _
oSketchProxy.ModelToSketchSpace( _
oTG.CreatePoint(1, 1, 0)))
Call oPoints.Add( _
oSketchProxy.ModelToSketchSpace( _
oTG.CreatePoint(2, 0, 0)))
Call oPoints.Add( _
oSketchProxy.ModelToSketchSpace( _
oTG.CreatePoint(4, 2, 0)))
Call oSketchProxy.SketchSplines.Add(oPoints)
End Sub