public void selEdge(string promt, SelectionFilterEnum filter) { PartFeature pf = CmdMgr.Pick(filter, promt) as PartFeature; HoleFeature hf = pf as HoleFeature; if (hf == null) { return; } //ICollection<Edge> col = null; foreach (Face item in hf.SideFaces) { Edge ed = checkBox1.Checked ? item.Edges[2] : item.Edges[1]; edges.Add(ed); } // System.Collections.IEnumerator en = PartCompDef.Features.GetEnumerator(); // en.Reset(); // while(en.Current != null) // { // en. // } PartCompDef = hf.Parent as PartComponentDefinition; // for (int i = 1; i < PartCompDef.Features.Count; i++) // { // MirrorFeature mf = PartCompDef.Features[i] as MirrorFeature; // if (mf == null) continue; // HoleFeature holeF = PartCompDef.Features[i - 1] as HoleFeature; // if (hf == null) // holeF = PartCompDef.Features[i - 2] as HoleFeature; // else // continue; // foreach (PartFeature item in mf.ParentFeatures) // { // if (item is HoleFeature && holeF.Equals(item)) // { // if (mf.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) // edges.Add(mf.Faces[1].Edges[1]); // } // } // } foreach (MirrorFeature item in PartCompDef.Features.MirrorFeatures) { foreach (PartFeature m in item.ParentFeatures) { if (m.Equals(hf)) { if (item.Faces[1].SurfaceType != SurfaceTypeEnum.kCylinderSurface) { continue; } Edge ed = checkBox1.Checked ? item.Faces[1].Edges[2] : item.Faces[1].Edges[1]; edges.Add(ed); } } } }
private void createPart2() { // create a new part PartDocument oDoc = (PartDocument)mApp.Documents.Add(DocumentTypeEnum.kPartDocumentObject); PartComponentDefinition oDef = oDoc.ComponentDefinition; TransientGeometry oTG = mApp.TransientGeometry; // create sketch elements PlanarSketch oSketch = oDef.Sketches.Add(oDef.WorkPlanes[3]); oSketch.SketchLines.AddAsTwoPointRectangle(oTG.CreatePoint2d(-5, -5), oTG.CreatePoint2d(5, 5)); SketchPoint oSketchPt = oSketch.SketchPoints.Add(oTG.CreatePoint2d(0, 0)); Profile oProfile = oSketch.Profiles.AddForSolid(); // create a plate with a hole feature ExtrudeDefinition oExtrudDef = oDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kJoinOperation); oExtrudDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kPositiveExtentDirection); ExtrudeFeature oExtrudeF = oDef.Features.ExtrudeFeatures.Add(oExtrudDef); // Create an object collection for the hole center points. ObjectCollection oHoleCenters = default(ObjectCollection); oHoleCenters = mApp.TransientObjects.CreateObjectCollection(); oHoleCenters.Add(oSketchPt); // create hole feature HolePlacementDefinition oHPdef = (HolePlacementDefinition)oDef.Features.HoleFeatures.CreateSketchPlacementDefinition(oHoleCenters); HoleFeature oHoleF = oDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oHPdef, "2", PartFeatureExtentDirectionEnum.kNegativeExtentDirection); Face oFace = oHoleF.SideFaces[1]; AttributeSet oAttSet = default(AttributeSet); Inventor.Attribute oAtt = null; oAttSet = oFace.AttributeSets.Add("demoAttset"); oAtt = oAttSet.Add("demoAtt", ValueTypeEnum.kStringType, "namedEdge"); if (System.IO.File.Exists("c:\temp\test2.ipt")) { System.IO.File.Delete("c:\temp\test2.ipt"); } oDoc.SaveAs("c:\\temp\\test2.ipt", false); }
/// <summary> /// creation of hole tables in a drawing. /// Select a drawing view that contains holes and run the following sample /// </summary> /// <remarks></remarks> public void CreateHoleTables() { // Set a reference to the drawing document. // This assumes a drawing document is active. DrawingDocument oDrawDoc = (DrawingDocument)_InvApplication.ActiveDocument; // Set a reference to the active sheet. Sheet oActiveSheet = oDrawDoc.ActiveSheet; // Set a reference to the drawing view. // This assumes that a drawing view is selected. DrawingView oDrawingView = oDrawDoc.SelectSet[1]; // Create origin indicator if it has not been already created. if (!oDrawingView.HasOriginIndicator) { // Create point intent to anchor the origin to. GeometryIntent oDimIntent = null; Point2d oPointIntent = null; // Get the first curve on the view DrawingCurve oCurve = oDrawingView.get_DrawingCurves()[1]; // Check if it has a strt point oPointIntent = oCurve.StartPoint; if (oPointIntent == null) { // Else use the center point oPointIntent = oCurve.CenterPoint; } oDimIntent = oActiveSheet.CreateGeometryIntent(oCurve, oPointIntent); oDrawingView.CreateOriginIndicator(oDimIntent); } Point2d oPlacementPoint = null; // Set a reference to th sheet's border Inventor.Border oBorder = oActiveSheet.Border; if ((oBorder != null)) { // A border exists. The placement point // is the top-left corner of the border. oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(oBorder.RangeBox.MinPoint.X, oBorder.RangeBox.MaxPoint.Y); } else { // There is no border. The placement point // is the top-left corner of the sheet. oPlacementPoint = _InvApplication.TransientGeometry.CreatePoint2d(0, oActiveSheet.Height); } // Create a 'view' hole table // This hole table includes all holes as specified by the active hole table style HoleTable oViewHoleTable = default(HoleTable); oViewHoleTable = oActiveSheet.HoleTables.Add(oDrawingView, oPlacementPoint); oPlacementPoint.X = oActiveSheet.Width / 2; // Create a 'feature type' hole table // This hole table includes specified hole types only HoleTable oFeatureHoleTable = oActiveSheet.HoleTables.AddByFeatureType(oDrawingView, oPlacementPoint, true, true, true, true, false, false, false); //add a new row // get the model document Document oModelDoc = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument; HoleFeature oHoleF = null; if (oModelDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { AssemblyDocument oRefAssDoc = (AssemblyDocument)oModelDoc; AssemblyComponentDefinition oAssDef = oRefAssDoc.ComponentDefinition; if (oAssDef.Features.HoleFeatures.Count > 0) { //as a demo: get the first hole feature oHoleF = oAssDef.Features.HoleFeatures[1]; } } else if (oModelDoc.DocumentType == DocumentTypeEnum.kPartDocumentObject) { PartDocument oRefPartDoc = (PartDocument)oModelDoc; PartComponentDefinition oPartDef = oRefPartDoc.ComponentDefinition; if (oPartDef.Features.HoleFeatures.Count > 0) { //as a demo: get the first hole feature oHoleF = oPartDef.Features.HoleFeatures[1]; } } // add a new row to the hole table if ((oHoleF != null)) { DrawingCurvesEnumerator oHoleCurves = oDrawingView.get_DrawingCurves(oHoleF); if (oHoleCurves.Count > 0) { oFeatureHoleTable.HoleTableRows.Add(oHoleCurves[1]); } } }