Ejemplo n.º 1
0
        public Inventor.MateiMateDefinition iMate__(object oEdge, AssemblyComponentDefinition compDef, double offset = 0, InferredTypeEnum inf = InferredTypeEnum.kInferredLine)
        {
            MateiMateDefinition oImate = null; Inventor.Face oFace; Inventor.Point pt;

            switch (inf)
            {
            case InferredTypeEnum.kInferredLine:
                oFace = (((Edge)oEdge).Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ((Edge)oEdge).Faces[1] : ((Edge)oEdge).Faces[2];
                if (((Edge)oEdge).TangentiallyConnectedEdges.Count == 1)
                {
                    oImate = compDef.iMateDefinitions.AddMateiMateDefinition(oFace, offset, inf, oFace.PointOnFace);
                }
                break;

            case InferredTypeEnum.kInferredPoint:
                pt     = (((Edge)oEdge).Geometry as Circle).Center;
                oImate = compDef.iMateDefinitions.AddMateiMateDefinition(oEdge, offset, inf);
                break;

            case InferredTypeEnum.kNoInference:
                oFace  = (((Edge)oEdge).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? ((Edge)oEdge).Faces[1] : ((Edge)oEdge).Faces[2];
                oImate = compDef.iMateDefinitions.AddMateiMateDefinition(oFace, offset, inf);
                break;

            default:
                break;
            }
            return(oImate);
        }
Ejemplo n.º 2
0
        public Inventor.MateiMateDefinition iMate__(object oEdge, PartComponentDefinition compDef, double offset = 0)
        {
            MateiMateDefinition oImate = null; Inventor.Face oFace; WorkPoint wp; WorkAxis wa;
            SketchArc           sa1, sa2; SketchLine lin; MidpointConstraint mpc; SketchPoint sp; object a = 0.0;

            oFace = (((Edge)oEdge).Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface)? ((Edge)oEdge).Faces[1] : ((Edge)oEdge).Faces[2];
            if (((Edge)oEdge).TangentiallyConnectedEdges.Count == 1)
            {
                /*oFace = oEdge.Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface ? oEdge.Faces[1] : oEdge.Faces[2];*/
//                                 wa = compDef.WorkAxes.AddByRevolvedFace(oFace);
//                                 wa.Visible = false;
                oImate = compDef.iMateDefinitions.AddMateiMateDefinition(oFace, 0, InferredTypeEnum.kInferredLine, oFace.PointOnFace);
            }

            else if (((Edge)oEdge).TangentiallyConnectedEdges.Count == 4 || ((Edge)oEdge).TangentiallyConnectedEdges.Count == 3)
            {
                ps = (((Edge)oEdge).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface)? compDef.Sketches.Add(((Edge)oEdge).Faces[1]): compDef.Sketches.Add(((Edge)oEdge).Faces[2]);
                switch (((Edge)((Edge)oEdge).TangentiallyConnectedEdges[1]).GeometryType)
                {
                case CurveTypeEnum.kCircularArcCurve:
                    sa1 = (SketchArc)ps.AddByProjectingEntity(((Edge)oEdge).TangentiallyConnectedEdges[1]);
                    sa2 = (SketchArc)ps.AddByProjectingEntity(((Edge)oEdge).TangentiallyConnectedEdges[3]);
                    break;

                default:
                    sa1 = (SketchArc)ps.AddByProjectingEntity(((Edge)oEdge).TangentiallyConnectedEdges[2]);
                    sa2 = (SketchArc)ps.AddByProjectingEntity(((Edge)oEdge).TangentiallyConnectedEdges[4]);
                    break;
                }
                oFace      = (((Edge)oEdge).Faces[1].SurfaceType == SurfaceTypeEnum.kCylinderSurface) ? ((Edge)oEdge).Faces[2] : ((Edge)oEdge).Faces[1];
                lin        = ps.SketchLines.AddByTwoPoints(sa1.CenterSketchPoint, sa2.CenterSketchPoint);
                sp         = ps.SketchPoints.Add(invApp.TransientGeometry.CreatePoint2d());
                mpc        = ps.GeometricConstraints.AddMidpoint(sp, lin);
                ps.Visible = false;
                wp         = compDef.WorkPoints.AddByPoint(sp);
                wa         = compDef.WorkAxes.AddByNormalToSurface(oFace, wp);
                wp.Visible = false; wa.Visible = false;
                oImate     = compDef.iMateDefinitions.AddMateiMateDefinition(wa, a, InferredTypeEnum.kInferredLine, oFace.PointOnFace);
            }
            return(oImate);
        }
Ejemplo n.º 3
0
        public Inventor.MateiMateDefinition iMateMate__(object oEdge, PartComponentDefinition compDef, InferredTypeEnum inf = InferredTypeEnum.kInferredPoint)
        {
            MateiMateDefinition def = null; Inventor.Face oFace;

            switch (inf)
            {
            case InferredTypeEnum.kInferredLine:
                break;

            case InferredTypeEnum.kInferredPoint:
                def = compDef.iMateDefinitions.AddMateiMateDefinition(oEdge, 0, inf);
                break;

            case InferredTypeEnum.kNoInference:
                oFace = (((Edge)oEdge).Faces[1].SurfaceType == SurfaceTypeEnum.kPlaneSurface) ? ((Edge)oEdge).Faces[1] : ((Edge)oEdge).Faces[2];
                def   = compDef.iMateDefinitions.AddMateiMateDefinition(oFace, 0, inf);
                break;

            default:
                break;
            }
            return(def);
        }
Ejemplo n.º 4
0
        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();
                }
            }
        }
Ejemplo n.º 5
0
        /// <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);
        }