public void addName(InsertiMateDefinition iMate, string name) { if (name != "") { iMate.Name = name; string[] names = new string[1]; names[0] = name; //iMate.MatchList = names; } }
public void imate(string str, string name, double offset, Document Doc, object edge1, object edge2, bool close = false) { try { switch (Doc.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: AsmCompDef = ((AssemblyDocument)Doc).ComponentDefinition; break; case DocumentTypeEnum.kPartDocumentObject: PartCompDef = ((PartDocument)Doc).ComponentDefinition; break; default: break; } //offset = conv(this.comboBox2.Text); if (str == "Вставка") { switch (Doc.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: insIMateDef = iMate_(edge1, AsmCompDef, offset); objs.Add(insIMateDef); insIMateDef = iMate_(edge2, AsmCompDef, offset); objs.Add(insIMateDef); //if (comboBox3.Text != "") addName(AsmCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; case DocumentTypeEnum.kPartDocumentObject: insIMateDef = iMate_(edge1, PartCompDef, offset); objs.Add(insIMateDef); insIMateDef = iMate_(edge2, PartCompDef, offset); objs.Add(insIMateDef); addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; } } else if (str == "Совмещение по оси") { switch (Doc.DocumentType) { case DocumentTypeEnum.kPartDocumentObject: iMateDef = iMate__(edge1, PartCompDef, offset); objs.Add(iMateDef); iMateDef = iMate__(edge2, PartCompDef, offset); objs.Add(iMateDef); iMateDef = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? PartCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[1], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge) : PartCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[2], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge); objs.Add(iMateDef); addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; case DocumentTypeEnum.kAssemblyDocumentObject: iMateDef = iMate__(edge1, AsmCompDef, offset); objs.Add(iMateDef); iMateDef = iMate__(edge2, AsmCompDef, offset); objs.Add(iMateDef); iMateDef = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? AsmCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[1], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge) : AsmCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[2], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge); objs.Add(iMateDef); addName(AsmCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; } } else if (str == "Овал") { switch (Doc.DocumentType) { case DocumentTypeEnum.kPartDocumentObject: Face f1; f1 = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? ((Edge)edge1).Faces[1]: ((Edge)edge1).Faces[2]; iMateDef = findAxis(PartCompDef, edge1 as Edge); objs.Add(iMateDef); iMateDef = PartCompDef.iMateDefinitions.AddMateiMateDefinition(f1, offset / 10); objs.Add(iMateDef); addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; case DocumentTypeEnum.kAssemblyDocumentObject: Face fp1 = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? ((EdgeProxy)edge1).Faces[1] : ((Edge)edge1).Faces[2]; Face fp2 = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ((Edge)edge1).Faces[1] : ((Edge)edge1).Faces[2]; iMateDef = AsmCompDef.iMateDefinitions.AddMateiMateDefinition(fp2, 0, InferredTypeEnum.kInferredLine); objs.Add(iMateDef); iMateDef = AsmCompDef.iMateDefinitions.AddMateiMateDefinition(fp1, 0); objs.Add(iMateDef); addName(AsmCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; } } else if (str == "ТЭН-резистор") { switch (Doc.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: insIMateDef = iMate_(edge1, AsmCompDef, offset); objs.Add(insIMateDef); iMateDef = iMate__(edge2, AsmCompDef, offset); objs.Add(iMateDef); addName(AsmCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; case DocumentTypeEnum.kPartDocumentObject: insIMateDef = iMate_(edge1, PartCompDef, offset); objs.Add(insIMateDef); iMateDef = iMate__(edge2, PartCompDef, offset); objs.Add(iMateDef); addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; } } else if (str == "ТЭН") { switch (Doc.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: iMateDef = iMate__(edge1, AsmCompDef, offset); objs.Add(iMateDef); iMateDef = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? PartCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[1], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge) : PartCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[2], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge); objs.Add(iMateDef); iMateDef = iMate__(edge2, AsmCompDef, offset); objs.Add(iMateDef); addName(AsmCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; case DocumentTypeEnum.kPartDocumentObject: iMateDef = iMate__(edge1, PartCompDef, offset); objs.Add(iMateDef); iMateDef = (((Edge)edge1).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? PartCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[1], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge) : PartCompDef.iMateDefinitions.AddMateiMateDefinition(((Edge)edge1).Faces[2], offset / 10, BiasPoint: ((Edge)edge1).PointOnEdge); objs.Add(iMateDef); iMateDef = iMate__(edge2, PartCompDef, offset); objs.Add(iMateDef); addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; } } // else if (str == "Шип") // { // // //edge2 = (Edge)CmdMgr.Pick(SelectionFilterEnum.kAllLinearEntities, "Выберите верхнюю часть выреза под замыкающий шип"); // switch (Doc.DocumentType) // { // case DocumentTypeEnum.kAssemblyDocumentObject: // thorn<AssemblyComponentDefinition>(edge1, AsmCompDef, ref objs); // //thorn<AssemblyComponentDefinition>(edge2, AsmCompDef, ref objs); // addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs),name); // break; // case DocumentTypeEnum.kPartDocumentObject: // thorn<PartComponentDefinition>(edge1, PartCompDef, ref objs); // //thorn<PartComponentDefinition>(edge2, PartCompDef, ref objs); // addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs),name); // break; // } // } else if (str == "Одиночная вставка" || str == "По элементу") { //edge2 = (Edge)CmdMgr.Pick(SelectionFilterEnum.kAllLinearEntities, "Выберите верхнюю часть выреза под замыкающий шип"); switch (Doc.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: insIMateDef = iMate_(edge1, AsmCompDef, offset); addName(insIMateDef, name); break; case DocumentTypeEnum.kPartDocumentObject: insIMateDef = iMate_(edge1, PartCompDef, offset); addName(insIMateDef, name); break; } } else if (str == "DIN-рейка") { switch (Doc.DocumentType) { case DocumentTypeEnum.kAssemblyDocumentObject: iMateDef = iMate__(edge1, AsmCompDef, offset, InferredTypeEnum.kInferredPoint); objs.Add(iMateDef); iMateDef = iMate__(edge2, AsmCompDef, offset, InferredTypeEnum.kInferredPoint); objs.Add(iMateDef); iMateDef = iMate__(edge2, AsmCompDef, offset, InferredTypeEnum.kNoInference); objs.Add(iMateDef); addName(AsmCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; case DocumentTypeEnum.kPartDocumentObject: iMateDef = iMateMate__(edge1, PartCompDef, InferredTypeEnum.kInferredPoint); objs.Add(iMateDef); iMateDef = iMateMate__(edge2, PartCompDef, InferredTypeEnum.kInferredPoint); objs.Add(iMateDef); iMateDef = iMateMate__(edge2, PartCompDef, InferredTypeEnum.kNoInference); objs.Add(iMateDef); addName(PartCompDef.iMateDefinitions.AddCompositeiMateDefinition(objs), name); break; } } objs.Clear(); } catch (Exception ex) { tr.End(); MessageBox.Show(ex.ToString()); this.Close(); } finally { if (close) { this.Close(); } else { this.Show(); this.button1.Focus(); } } }
/// <summary> /// Add iMate definitions using AddMateiMateDefinition and AddInsertiMateDefinition. /// </summary> /// <remarks></remarks> public void CreateiMateDefinition() { // Create a new part document, using the default part template. PartDocument oPartDoc = (PartDocument)_InvApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, _InvApplication.FileManager.GetTemplateFile(DocumentTypeEnum.kPartDocumentObject)); // Set a reference to the component definition. PartComponentDefinition oCompDef = default(PartComponentDefinition); oCompDef = oPartDoc.ComponentDefinition; // Create a new sketch on the X-Y work plane. PlanarSketch oSketch = default(PlanarSketch); oSketch = oCompDef.Sketches.Add(oCompDef.WorkPlanes[3]); // Set a reference to the transient geometry object. TransientGeometry oTransGeom = default(TransientGeometry); oTransGeom = _InvApplication.TransientGeometry; // Draw a 4cm x 3cm rectangle with the corner at (0,0) SketchEntitiesEnumerator oRectangleLines = default(SketchEntitiesEnumerator); oRectangleLines = oSketch.SketchLines.AddAsTwoPointRectangle(oTransGeom.CreatePoint2d(0, 0), oTransGeom.CreatePoint2d(4, 3)); // Create a profile. Profile oProfile = default(Profile); oProfile = oSketch.Profiles.AddForSolid(); // Create a base extrusion 1cm thick. ExtrudeDefinition oExtrudeDef = default(ExtrudeDefinition); oExtrudeDef = oCompDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(oProfile, PartFeatureOperationEnum.kNewBodyOperation); oExtrudeDef.SetDistanceExtent(1, PartFeatureExtentDirectionEnum.kNegativeExtentDirection); ExtrudeFeature oExtrude1 = default(ExtrudeFeature); oExtrude1 = oCompDef.Features.ExtrudeFeatures.Add(oExtrudeDef); // Get the top face of the extrusion to use for creating the new sketch. Face oFrontFace = default(Face); oFrontFace = oExtrude1.StartFaces[1]; // Create a new sketch on this face, but use the method that allows you to // control the orientation and orgin of the new sketch. oSketch = oCompDef.Sketches.AddWithOrientation(oFrontFace, oCompDef.WorkAxes[1], true, true, oCompDef.WorkPoints[1]); // Create a sketch circle with the center at (2, 1.5). SketchCircle oCircle = default(SketchCircle); oCircle = oSketch.SketchCircles.AddByCenterRadius(oTransGeom.CreatePoint2d(2, 1.5), 0.5); // Create a profile. oProfile = oSketch.Profiles.AddForSolid(); // Create the second extrude (a hole). ExtrudeFeature oExtrude2 = default(ExtrudeFeature); oExtrude2 = oCompDef.Features.ExtrudeFeatures.AddByThroughAllExtent(oProfile, PartFeatureExtentDirectionEnum.kNegativeExtentDirection, PartFeatureOperationEnum.kCutOperation); // Create a mate iMateDefinition on a side face of the first extrude. MateiMateDefinition oMateiMateDefinition = default(MateiMateDefinition); oMateiMateDefinition = oCompDef.iMateDefinitions.AddMateiMateDefinition(oExtrude1.SideFaces[1], 0, InferredTypeEnum.kNoInference, null, "MateA"); // Create a match list of names to use for the next iMateDefinition. string[] strMatchList = new string[3]; strMatchList[0] = "InsertA"; strMatchList[1] = "InsertB"; strMatchList[2] = "InsertC"; // Create an insert iMateDefinition on the cylindrical face of the second extrude. InsertiMateDefinition oInsertiMateDefinition = default(InsertiMateDefinition); oInsertiMateDefinition = oCompDef.iMateDefinitions.AddInsertiMateDefinition(oExtrude2.SideFaces[1], false, 0, null, "InsertA", strMatchList); }