The PlanarSketch.AddByProjectingEntity can be used in a part environment to project geometry onto a sketch plane. It is also applicable to project geometry from one occurrence to another.
The only issue you need to mote is: you must use a proxy object, not a native object, no matter the geometries or the object which is projected to, such as a sketch.
The following code assumes an assembly has two parts. It projects the first edge of the first surfacebody of the part1 to the first sketch of the part2.
static void Test()
{
_InvApplication = (Inventor.Application)
System.Runtime.InteropServices.Marshal.
GetActiveObject("Inventor.Application");
// assume we have had Inventor application
AssemblyDocument asmDoc =
(AssemblyDocument)_InvApplication.ActiveDocument;
ComponentOccurrence occ1 =
asmDoc.ComponentDefinition.Occurrences[1];
ComponentOccurrence occ2 =
asmDoc.ComponentDefinition.Occurrences[2];
PartComponentDefinition partDef1 =
(PartComponentDefinition)occ1.Definition;
PartComponentDefinition partDef2 =
(PartComponentDefinition)occ2.Definition;
Edge oEdge = partDef1.SurfaceBodies[1].Edges[1];
object objedge;
occ1.CreateGeometryProxy(oEdge, out objedge);
EdgeProxy oProxyEdge = (EdgeProxy)objedge;
PlanarSketch mySketch =
(PlanarSketch)partDef2.Sketches[1];
object objsketch;
occ2.CreateGeometryProxy(mySketch, out objsketch);
PlanarSketchProxy myProxySketchProxy =
(PlanarSketchProxy)objsketch;
//SketchEntity projEdge =
// mySketch.AddByProjectingEntity(oProxyEdge);
SketchEntity projEdge =
myProxySketchProxy.AddByProjectingEntity
(oProxyEdge);
}