Projecting sketch from iPart member to another part in assembly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone,
I have assembly with few occurrences. In one of them (assembly) I want to project sketch from one sub occurrence to another, create cut extrude from this sketch and make second sub occurrence and projected sketch adaptive from position of first. Main important thing is first sub occurrence is iPart member.
I try to do that like this:
private void iCut()
{
// Set a reference to the active assembly document
Inventor.AssemblyDocument oDoc;
oDoc = (Inventor.AssemblyDocument)ThisApplication.ActiveDocument;
// Get Asembly Component Definition
AssemblyComponentDefinition oTopAsmDef;
oTopAsmDef = oDoc.ComponentDefinition;
// Get First Occurrence reference from top level assembly (WallAssembly:1)
ComponentOccurrence oWallAssembly = oTopAsmDef.Occurrences[1];
// Get Assembly component definition
AssemblyComponentDefinition oWallAssemblyDef = (AssemblyComponentDefinition)oWallAssembly.Definition;
/////////////////////////////////
//////// First Occurrence
//////////////////////////////////
// Get occurrence reference to the first sub occurence at oOcc. "Plate:1"
ComponentOccurrence oPlate = oWallAssemblyDef.Occurrences[1];
//Create occurrence proxy to the Plate:1
object oObject;
oWallAssembly.CreateGeometryProxy(oPlate, out oObject);
ComponentOccurrenceProxy oPlateProxy = (ComponentOccurrenceProxy)oObject;
// Get part component definition
PartComponentDefinition oPlateDef = (PartComponentDefinition)oPlateProxy.Definition;
// Get Second sketch from "Plate:1". In this sketch will project cutout sketch from iPart
PlanarSketch oPlateSketch = oPlateDef.Sketches[2];
// Create sketch proxy to the above sketch
oPlateProxy.CreateGeometryProxy(oPlateSketch, out oObject);
PlanarSketchProxy oPlateSketchProxy = (PlanarSketchProxy)oObject;
///////////////////////////////////////////////////////////////////////////////////
//////// Second Occurrence
//////////////////////////////////////////////////////////////////////////////////
// Get occurrence reference to the second sub occurence at oOcc. "Gasket_20:1"
ComponentOccurrence oGasket = oWallAssemblyDef.Occurrences[2];
//Create occurrence proxy to the second occurrence ("Gasket_20:1")
oWallAssembly.CreateGeometryProxy(oGasket, out oObject);
ComponentOccurrenceProxy oGasketProxy = (ComponentOccurrenceProxy)oObject;
// Get Part component definition from ("Gasket_20:1"). This definition is iPart Member definition
PartComponentDefinition oGasketDef = (PartComponentDefinition)oGasketProxy.Definition;
//Get the actual factory document
PartDocument factoryDoc = oGasketDef.iPartMember.ReferencedDocumentDescriptor.ReferencedDocument;
// Get part definition
PartComponentDefinition factoryDef = (PartComponentDefinition)factoryDoc.ComponentDefinition;
// Get reference to the Sketch "CutOutSketch" from Gasket.ipt
PlanarSketch oGasketSketch = factoryDef.Sketches["CutOutSketch"];
// Get all lines from oGasketSketch
SketchLines oGasketLines = oGasketSketch.SketchLines;
// Get enumerator
IEnumerator eGasketLines = oGasketLines.GetEnumerator();
SketchEntity projLine = null;
SketchLine oGasketLine = null;
while (eGasketLines.MoveNext())
{
// Get current line from gasket sketch
oGasketLine = (SketchLine)eGasketLines.Current;
// Create proxy to this line
oGasketProxy.CreateGeometryProxy(oGasketLine, out oObject);
SketchLineProxy oGasketLineProxy = (SketchLineProxy)oObject;
// Project line to the oPlateSketchProxy
projLine = oPlateSketchProxy.AddByProjectingEntity(oGasketLineProxy);
}
// Create a profile.
Profile oProfile = default(Profile);
oProfile = oPlateSketchProxy.Profiles.AddForSolid();
// Create a cut out
ExtrudeDefinition oExtrudeDef = oPlateDef.Features.ExtrudeFeatures.
CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kCutOperation);
oExtrudeDef.SetThroughAllExtent(PartFeatureExtentDirectionEnum.kNegativeExtentDirection);
ExtrudeFeature oExtrude = oPlateDef.Features.ExtrudeFeatures.Add(oExtrudeDef);
}
Unfortunately I got error when create proxy to the line just before project it in to the sketch.
oGasketProxy.CreateGeometryProxy(oGasketLine, out oObject);
Any Ideas how to fix this?
Many thanks in advance.
P.S.
In attached file you could find inventor files.