示例#1
0
        //Создание эл-та кручение
        public RevolveFeature Create_Revolve(PlanarSketch sketch, PartFeatureOperationEnum enumer)
        {
            Profile        profile = sketch.Profiles.AddForSolid();
            RevolveFeature revolve = partCompDef.Features.RevolveFeatures.AddFull(profile, center_line, enumer);

            return(revolve);
        }
示例#2
0
    protected override void OnMouseDown(Vector3 pos, ICADObject sko)
    {
        if (sko == null)
        {
            return;
        }
        var entity = sko as IEntity;

        if (entity == null)
        {
            return;
        }
        if (p == null)
        {
            if (entity.type == IEntityType.Point)
            {
                p = entity;
            }
        }
        else if (axis == null)
        {
            if (entity.type == IEntityType.Line)
            {
                axis = entity;
                StopTool();
                editor.PushUndo();
                var feature = new RevolveFeature();
                DetailEditor.instance.AddFeature(feature);
                feature.axis   = axis;
                feature.origin = p;
                feature.source = DetailEditor.instance.activeFeature;
                DetailEditor.instance.ActivateFeature(feature);
            }
        }
    }
示例#3
0
        public override void CreateModule(ParameterBase Parameter)
        {
            parCylineDoor = Parameter as ParCylinderDoor;
            if (parCylineDoor == null)
            {
                return;
            }
            init();
            PartDocument            part    = InventorTool.CreatePart();
            PartComponentDefinition partDef = part.ComponentDefinition;
            PlanarSketch            osketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
            SketchEllipticalArc     Arc1    = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, parCylineDoor.DoorRadius, parCylineDoor.InRadius, 0, Math.PI / 2);
            SketchEllipticalArc     Arc2    = osketch.SketchEllipticalArcs.Add(InventorTool.Origin, InventorTool.Left, parCylineDoor.DoorRadius + parCylineDoor.Thickness, parCylineDoor.InRadius + parCylineDoor.Thickness, 0, Math.PI / 2);

            osketch.GeometricConstraints.AddConcentric((SketchEntity)Arc1, (SketchEntity)Arc2);
            SketchLine Line1 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, Arc2.StartSketchPoint);
            SketchLine Line2 = osketch.SketchLines.AddByTwoPoints(Arc1.EndSketchPoint, Arc2.EndSketchPoint);

            osketch.GeometricConstraints.AddHorizontalAlign(Arc1.StartSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddVerticalAlign(Arc1.EndSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line1);
            osketch.GeometricConstraints.AddVertical((SketchEntity)Line2);
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylineDoor.DoorRadius / 2, 0));
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylineDoor.InRadius / 2));

            Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2 + 1, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);

            osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            Profile        profile = osketch.Profiles.AddForSolid();
            RevolveFeature revolve = partDef.Features.RevolveFeatures.AddFull(profile, Line1, PartFeatureOperationEnum.kNewBodyOperation);
        }
示例#4
0
        //Массив по кругу
        public void Create_Circular_Array(RevolveFeature revolve)
        {
            ObjectCollection obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();

            obj_collection.Add(revolve);
            WorkAxis XAxis = partCompDef.WorkAxes[1];
            CircularPatternFeature pattern = partCompDef.Features.CircularPatternFeatures.Add(obj_collection, XAxis, false, 10, "360 grad", false, PatternComputeTypeEnum.kIdenticalCompute);
        }
示例#5
0
        public static void Build(InventorAPI api, string formName)
        {
            PlanarSketch[]   sketch  = new PlanarSketch[4];
            Profile[]        profile = new Profile[4];
            SketchPoint[]    point   = new SketchPoint[4];
            SketchLine[]     line    = new SketchLine[4];
            RevolveFeature[] revolve = new RevolveFeature[4];
            // Создание цилиндра
            sketch[0]  = api.Sketch(api.GetCompDef().WorkPlanes[3]);
            point[0]   = api.Point(sketch[0], 0, 0);
            point[1]   = api.Point(sketch[0], 0, H / 10);
            point[2]   = api.Point(sketch[0], D1 / 10 / 2, H / 10);
            point[3]   = api.Point(sketch[0], D1 / 10 / 2, 0);
            line[0]    = api.Line(sketch[0], point[0], point[1]);
            line[1]    = api.Line(sketch[0], point[1], point[2]);
            line[2]    = api.Line(sketch[0], point[2], point[3]);
            line[3]    = api.Line(sketch[0], point[3], point[0]);
            profile[0] = api.Profile(sketch[0]);
            revolve[0] = api.Revolve(profile[0], line[0], 0);
            // Создание пружины
            sketch[1]  = api.Sketch(api.GetCompDef().WorkPlanes[3]);
            point[0]   = api.Point(sketch[1], D1 / 10 / 2, 0);
            point[1]   = api.Point(sketch[1], D / 10 / 2, 0);
            point[3]   = api.Point(sketch[1], D1 / 10 / 2, T / 10);
            line[0]    = api.Line(sketch[1], point[0], point[1]);
            line[1]    = api.Line(sketch[1], point[1], point[3]);
            line[2]    = api.Line(sketch[1], point[3], point[0]);
            profile[1] = api.Profile(sketch[1]);
            var coil = api.GetCompDef().Features.CoilFeatures.AddByPitchAndHeight(profile[1], api.GetCompDef().WorkAxes[2], H1 / 10, H2 / 10, PartFeatureOperationEnum.kJoinOperation, false, false, 0, false, 0, 0, true);

            // Верхняя граница пружины
            sketch[2]  = api.Sketch(api.GetCompDef().WorkPlanes[3]);
            point[0]   = api.Point(sketch[2], 0, H2 / 10);
            point[1]   = api.Point(sketch[2], 0, H2 / 10 + T / 10);
            point[2]   = api.Point(sketch[2], D / 10 / 2, H2 / 10 + T / 10);
            point[3]   = api.Point(sketch[2], D / 10 / 2, H2 / 10);
            line[0]    = api.Line(sketch[2], point[0], point[1]);
            line[1]    = api.Line(sketch[2], point[1], point[2]);
            line[2]    = api.Line(sketch[2], point[2], point[3]);
            line[3]    = api.Line(sketch[2], point[3], point[0]);
            profile[2] = api.Profile(sketch[2]);
            revolve[2] = api.Revolve(profile[2], line[0], 0);
            // Крепление
            sketch[3]  = api.Sketch(api.GetCompDef().WorkPlanes[3]);
            point[0]   = api.Point(sketch[3], 0, H3 / 10);
            point[1]   = api.Point(sketch[3], 0, H3 / 10 + A / 10);
            point[2]   = api.Point(sketch[3], D / 10 / 2, H3 / 10 + A / 10);
            point[3]   = api.Point(sketch[3], D / 10 / 2, H3 / 10);
            line[0]    = api.Line(sketch[3], point[0], point[1]);
            line[1]    = api.Line(sketch[3], point[1], point[2]);
            line[2]    = api.Line(sketch[3], point[2], point[3]);
            line[3]    = api.Line(sketch[3], point[3], point[0]);
            profile[3] = api.Profile(sketch[3]);
            revolve[3] = api.Revolve(profile[3], line[0], 0);
            System.Windows.Forms.MessageBox.Show(formName + " завершено.", formName);
        }
示例#6
0
        public override void CreateModule(ParameterBase Parameter)
        {
            parCylinder = Parameter as ParCylinder;
            if (parCylinder == null)
            {
                return;
            }
            init();


            PartDocument            part = InventorTool.CreatePart();
            PartComponentDefinition partDef = part.ComponentDefinition;
            PlanarSketch            osketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
            SketchEllipticalArc     Arc1, Arc2;
            SketchLine Line1, Line2;

            CreateLines(osketch, out Arc1, out Line1, parCylinder.CapRadius, parCylinder.InRadius, parCylinder.Length);

            //SketchLine line5= offsetLine<SketchLine>(osketch, Line1, 2, true);
            //SketchOffsetSpline arc5 = (SketchOffsetSpline)offsetLine(osketch, Arc1, 2, true);
            //SketchLine Line3 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, arc5.StartSketchPoint);
            //SketchLine Line4 = osketch.SketchLines.AddByTwoPoints(Line1.EndSketchPoint, line5.EndSketchPoint);
            //osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line3);
            //osketch.GeometricConstraints.AddVertical((SketchEntity)Line4);
            //osketch.GeometricConstraints.AddEqualLength(Line3, Line4);
            //osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylinder.CapRadius / 2, 0));
            //osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylinder.InRadius / 2));
            //Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);
            //osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            //p = InventorTool.TranGeo.CreatePoint2d((Line4.StartSketchPoint.Geometry.X + Line4.EndSketchPoint.Geometry.X) / 2 + 1, (Line4.StartSketchPoint.Geometry.Y + Line4.EndSketchPoint.Geometry.Y) / 2);
            //osketch.DimensionConstraints.AddTwoPointDistance(Line4.StartSketchPoint, Line4.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);

            CreateLines(osketch, out Arc2, out Line2, parCylinder.CapRadius + parCylinder.Thickness, parCylinder.InRadius + parCylinder.Thickness, parCylinder.Length);
            SketchLine Line3 = osketch.SketchLines.AddByTwoPoints(Arc1.StartSketchPoint, Arc2.StartSketchPoint);
            SketchLine Line4 = osketch.SketchLines.AddByTwoPoints(Line1.EndSketchPoint, Line2.EndSketchPoint);

            osketch.GeometricConstraints.AddHorizontalAlign(Arc1.StartSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddVerticalAlign(Arc1.EndSketchPoint, Arc1.CenterSketchPoint);
            osketch.GeometricConstraints.AddHorizontal((SketchEntity)Line3);
            osketch.GeometricConstraints.AddVertical((SketchEntity)Line4);
            osketch.GeometricConstraints.AddEqualLength(Line3, Line4);
            osketch.GeometricConstraints.AddConcentric((SketchEntity)Arc1, (SketchEntity)Arc2);
            // osketch.GeometricConstraints.AddCoincident((SketchEntity)InventorTool.Origin, (SketchEntity)Arc1.CenterSketchPoint);
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, true, InventorTool.TranGeo.CreatePoint2d(-parCylinder.CapRadius / 2, 0));
            osketch.DimensionConstraints.AddEllipseRadius((SketchEntity)Arc1, false, InventorTool.TranGeo.CreatePoint2d(0, -parCylinder.InRadius / 2));
            Point2d p = InventorTool.TranGeo.CreatePoint2d((Line1.StartSketchPoint.Geometry.X + Line1.EndSketchPoint.Geometry.X) / 2, (Line1.StartSketchPoint.Geometry.Y + Line1.EndSketchPoint.Geometry.Y) / 2 + 1);

            osketch.DimensionConstraints.AddTwoPointDistance(Line1.StartSketchPoint, Line1.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);
            p = InventorTool.TranGeo.CreatePoint2d((Line4.StartSketchPoint.Geometry.X + Line4.EndSketchPoint.Geometry.X) / 2 + 1, (Line4.StartSketchPoint.Geometry.Y + Line4.EndSketchPoint.Geometry.Y) / 2);
            osketch.DimensionConstraints.AddTwoPointDistance(Line4.StartSketchPoint, Line4.EndSketchPoint, DimensionOrientationEnum.kAlignedDim, p);

            CreateRibs(osketch, Line2);
            Profile        profile = osketch.Profiles.AddForSolid();
            RevolveFeature revolve = partDef.Features.RevolveFeatures.AddFull(profile, Line3, PartFeatureOperationEnum.kNewBodyOperation);
        }
示例#7
0
 //creating other features
 private static void Feature()
 {
     foreach (Feature f in var_es.feature_list)
     {
         try
         {
             PlanarSketch sketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);
             f.DrawGeom(tg, ref sketch, ref var_es.lines);
             Profile        prof = sketch.Profiles.AddForSolid();
             RevolveFeature F    = partDef.Features.RevolveFeatures.AddFull(prof, partDef.WorkAxes[1], PartFeatureOperationEnum.kCutOperation);
         }
         catch (Exception e1) { MessageBox.Show(e1.ToString()); }
     }
 }
示例#8
0
        //Зеркальное отражение детали
        public void Mirror_Obj(RevolveFeature feature, PartDocument part)
        {
            PartComponentDefinition partCompDef = part.ComponentDefinition;
            PlanarSketch            sketch      = partCompDef.Sketches.Add(partCompDef.WorkPlanes[1]);

            sketch.Visible = false;
            TransientGeometry transGeom      = InventorApplication.TransientGeometry;
            SketchLine        line_1         = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(-6, -5), transGeom.CreatePoint2d(-6, 5));
            SketchLine        line_2         = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(6, -5), transGeom.CreatePoint2d(6, 5));
            WorkPlane         wp             = partCompDef.WorkPlanes.AddByTwoLines(line_1, line_2, true);
            ObjectCollection  obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();

            obj_collection.Add(feature);
            MirrorFeature mirror = partCompDef.Features.MirrorFeatures.Add(obj_collection, wp, false, PatternComputeTypeEnum.kAdjustToModelCompute);
        }
示例#9
0
        } //end of method ExtrudeSketch

        private string RevolveSketch(RevolveFeature revolveFeature)
        {
            //revolving a sketch in openjscad will result in a rotation around the z-axis (y-axis in inventor)
            //so the resulting object will be orientated differently then the one in inventor (probably)

            string        objectName   = revolveFeature.Name;
            StringBuilder rotationLine = new StringBuilder();

            //var object = rotate_extrude({fn:4}, sketch);
            rotationLine.Append("\t" + "var " + objectName + " = rotate_extrude(sketch" + _numberOfSketches + ");");

            //if we could find out on which plane the sketch was orientated originally
            //we could rotate the new object so it is an the right plane again
            //rotationLine.Append("\n");
            //rotationLine.Append("\t" + objectName + " = " + objectName + RotateObject("x"));

            return(rotationLine.ToString());
        } //end of method RevolveSketch
示例#10
0
        public PlanarSketch Separator(double direction)
        {
            PlanarSketch sketch       = partCompDef.Sketches.Add(partCompDef.WorkPlanes[3]);
            SketchPoints points_      = sketch.SketchPoints;
            SketchArcs   arcs_        = sketch.SketchArcs;
            SketchLines  lines_       = sketch.SketchLines;
            Point2d      center_point = transGeom.CreatePoint2d(Dw / 2 * direction, (D / 2 - d / 2) / 2 + d / 2);
            SketchPoint  points       = sketch.SketchPoints.Add(transGeom.CreatePoint2d(Dw * direction, (D / 2 - d / 2) / 2 + d / 2));
            SketchPoint  points2      = sketch.SketchPoints.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2));

            center_line = sketch.SketchLines.AddByTwoPoints(points, points2);
            SketchArc      arc      = sketch.SketchArcs.AddByCenterStartEndPoint(center_point, points, points2, true);
            RevolveFeature revolve1 = Create_Revolve(sketch, PartFeatureOperationEnum.kNewBodyOperation);

            Create_Circular_Array(revolve1);
            sketch  = partCompDef.Sketches.Add(partCompDef.WorkPlanes[3]);
            points_ = sketch.SketchPoints;
            lines_  = sketch.SketchLines;
            points_.Add(transGeom.CreatePoint2d((Dw / 2 + 0.25) * direction, (D / 2 - d / 2) / 2 + d / 2 + 0.15));
            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2 + 0.3));
            points_.Add(transGeom.CreatePoint2d(0, (D / 2 - d / 2) / 2 + d / 2 - 0.15));
            points_.Add(transGeom.CreatePoint2d(Dw / 2 * direction, (D / 2 - d / 2) / 2 + d / 2 - 0.1));
            for (int i = 1; i < 4; i++)
            {
                lines_.AddByTwoPoints(points_[i], points_[i + 1]);
            }
            ObjectCollection obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();

            obj_collection.Add(sketch.SketchEntities[5]);
            obj_collection.Add(sketch.SketchEntities[6]);
            obj_collection.Add(sketch.SketchEntities[7]);
            sketch.OffsetSketchEntitiesUsingDistance(obj_collection, 0.1 * direction, false);
            lines_.AddByTwoPoints(sketch.SketchLines[1].StartSketchPoint, sketch.SketchLines[4].StartSketchPoint);
            lines_.AddByTwoPoints(sketch.SketchLines[3].EndSketchPoint, sketch.SketchLines[6].EndSketchPoint);
            center_line = sketch.SketchLines.AddByTwoPoints(transGeom.CreatePoint2d(-1, 0), transGeom.CreatePoint2d(1, 0));
            RevolveFeature revolve2 = Create_Revolve(sketch, PartFeatureOperationEnum.kNewBodyOperation);

            obj_collection = InventorApplication.TransientObjects.CreateObjectCollection();
            obj_collection.Add(revolve1.SurfaceBodies[1]);
            CombineFeature combine = partCompDef.Features.CombineFeatures.Add(revolve2.SurfaceBodies[1], obj_collection, PartFeatureOperationEnum.kCutOperation);

            return(sketch);
        }
        override protected void ButtonDefinition_OnExecute(NameValueMap context)
        {
            try
            {
                //MessageBox.Show("ERES UN CAPO");

                AutodeskInventorInterop AII = new AutodeskInventorInterop();

                string filename = "..\\CMUdata\\meshanid.srf";

                // Parses files into location and vertex connectivity from an SRF file
                AII.ReadFileDataToList(filename);
                //log.Info("Reading meshanid.srf");

                // Parses file for elements in riemanian metric matrix in 3D
                filename = "..\\CMUdata\\meshanid.nt3m";
                AII.ReadFileDataToList_nt3m(filename);
                // log.Info("Reading meshanid.nt3m");

                // Decomposes the Riemanian Matrix M=Q.L.Q^-1
                AII.EigenDecomp3D(AII.EigenList);
                // log.Info("EigenDecomposition");

                //  log.Info("User Coordinate System");

                Inventor.Application mApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application") as Inventor.Application;

                Inventor.PartDocument oDoc = (Inventor.PartDocument)mApp.ActiveDocument;

                PartComponentDefinition oCompDef = default(PartComponentDefinition); //Defines a part component
                oCompDef = oDoc.ComponentDefinition;

                //Used to create a Unitvector where to store MajorAxis 2D for ellipse
                TransientGeometry oTG        = mApp.TransientGeometry;
                UnitVector2d      oUniVector = oTG.CreateUnitVector2d(1, 1);

                Point2d oPoint2d = mApp.TransientGeometry.CreatePoint2d(0, 0);

                Profile oProfile = default(Profile); //Creates a profile

                //EdgeCollection oEdge = default(EdgeCollection);

                Edge[] oSideEdges = new Edge[5];

                //FilletFeature oFillet = default(FilletFeature);

                WorkPoint oWorkPoint1 = default(WorkPoint);
                WorkPoint oWorkPoint2 = default(WorkPoint);
                WorkPoint oWorkPoint3 = default(WorkPoint);

                UserCoordinateSystemDefinition oUCSDef = oCompDef.UserCoordinateSystems.CreateDefinition();

                UserCoordinateSystem oUCS = default(UserCoordinateSystem);

                EigenVectorPatternSketchPlane selectPlaneToSketch = new EigenVectorPatternSketchPlane();  //ERASE THIS NOT USEFUL

                PartComponentDefinition oDef       = oDoc.ComponentDefinition;
                PlanarSketch            oSketch    = default(PlanarSketch);
                ObjectCollection        oFitPoints = mApp.TransientObjects.CreateObjectCollection();

                Point2d             oPoint2d_a     = default(Point2d);
                SketchEllipticalArc oEllipticalArc = default(SketchEllipticalArc);
                SketchLine          oAxis          = default(SketchLine);
                RevolveFeature      oRevolve       = default(RevolveFeature);

                //  WorkPlane oWPain = default(WorkPlane);

                #region "This is my life"
                /****************************************** COMMENT ***********************************************/
                // Philippe Leefsma : [email protected]
                // Here is where all the pain happens
                // thank you for your help in advance.
                // Here is where I create a User defined coordinate system per each one of the features shown
                // I do not know if there is a way of making this faster?
                /****************************************** COMMENT ***********************************************/

                for (int i = 0; i < AII.VertexLocation.Count; i++)
                {
                    oWorkPoint1 = oCompDef.WorkPoints.AddFixed(
                        oTG.CreatePoint(
                            (double)AII.VertexLocation[i].origen.X,
                            (double)AII.VertexLocation[i].origen.Y,
                            (double)AII.VertexLocation[i].origen.Z)
                        );

                    //Change here u1/10 this is to make it closer to the mm value check if needs to be chage to in
                    oWorkPoint2 = oCompDef.WorkPoints.AddFixed(
                        oTG.CreatePoint(
                            (double)AII.EigenVectorValue[i].evc.u1 + (double)AII.VertexLocation[i].origen.X,
                            (double)AII.EigenVectorValue[i].evc.u2 + (double)AII.VertexLocation[i].origen.Y,
                            (double)AII.EigenVectorValue[i].evc.u3 + (double)AII.VertexLocation[i].origen.Z)
                        );
                    //Check here maybe this is why my rotations are screwd up, instead of v1 maybe is w1
                    //If w is use I have a cool effect with the protution coming out of the screen
                    oWorkPoint3 = oCompDef.WorkPoints.AddFixed(
                        oTG.CreatePoint(
                            (double)AII.EigenVectorValue[i].evc.v1 + (double)AII.VertexLocation[i].origen.X,
                            (double)AII.EigenVectorValue[i].evc.v2 + (double)AII.VertexLocation[i].origen.Y,
                            (double)AII.EigenVectorValue[i].evc.v3 + (double)AII.VertexLocation[i].origen.Z)
                        );


                    //User Define Coordinate

                    oUCSDef.SetByThreePoints(oWorkPoint1, oWorkPoint2, oWorkPoint3);


                    oUCS = oCompDef.UserCoordinateSystems.Add(oUCSDef);

                    oPoint2d.X = 0;
                    oPoint2d.Y = 0;

                    double l1 = AII.EigenVectorValue[i].evl.l1;
                    double l2 = AII.EigenVectorValue[i].evl.l2; //Here maybe we can reduece time by pre-working these numbers

                    double h1 = (1 / Math.Sqrt(l1));            //Check here
                    double h2 = (1 / Math.Sqrt(l2));

                    //Change here to add alfa angle
                    oUniVector.X = 1; // Math.Abs(AII.EigenVectorValue[i].evc.u1); //CHNAGE HERE 0 ,1 //if this is negative changes the direction
                    oUniVector.Y = 0; // Math.Abs(AII.EigenVectorValue[i].evc.u2);


                    oSketch = selectPlaneToSketch.SelectPlane(oDoc, oUCS);



                    //Candidates for config file
                    oWorkPoint1.Visible = false;
                    oWorkPoint2.Visible = false;
                    oWorkPoint3.Visible = false;
                    oUCS.Visible        = false;



                    double PI                = Math.Atan(1) * 4.0;
                    double duoPI             = 2 * PI;
                    double sizeBubbleInverse = 3.5; //this changes the sizes in the features contracts the bubbles "SIZING METRIC"

                    #region "Revolve and Join"
                    oPoint2d_a = mApp.TransientGeometry.CreatePoint2d(0, 0);

                    //Create Elliptical Arc
                    oEllipticalArc = oSketch.SketchEllipticalArcs.Add(oPoint2d_a, oUniVector, h1 / (sizeBubbleInverse), h2 / (sizeBubbleInverse), 0, PI);

                    oAxis = oSketch.SketchLines.AddByTwoPoints(
                        oEllipticalArc.StartSketchPoint,
                        oEllipticalArc.EndSketchPoint);

                    oProfile = oSketch.Profiles.AddForSolid();

                    oRevolve = oDoc.ComponentDefinition.Features.RevolveFeatures.AddFull
                                   (oProfile, oAxis, PartFeatureOperationEnum.kJoinOperation);
                    #endregion
                }

                #endregion
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
示例#12
0
 public RevolvedPointEntity(PointEntity e, RevolveFeature f)
 {
     entity  = e;
     feature = f;
 }
示例#13
0
 public RevolvedEntity(Entity e, RevolveFeature f, long i)
 {
     entity  = e;
     feature = f;
     index   = i;
 }
示例#14
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                ThisApplication = (Inventor.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application");
                if (ThisApplication != null)
                {
                    label1.Text = "Inventor запущен.";
                }
            }
            catch
            {
                MessageBox.Show("Запустите Inventor!");
                return;
            }

            //Перевод мм в см
            D /= 10; d /= 10; B /= 10; r /= 10; r1 /= 10;

            //Sketch..
            New_document_Name("Подшипник");
            oPartDoc["Подшипник"].DisplayName = "Подшипник";
            PlanarSketch oSketch = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);

            SketchPoint[]  point      = new SketchPoint[101];
            SketchArc[]    arc        = new SketchArc[101];
            SketchPoint[]  center_arc = new SketchPoint[101];
            SketchLine[]   lines      = new SketchLine[101];
            SketchCircle[] circles    = new SketchCircle[101];

            //Координаты точек вершин прямоугольника
            point[0] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2));
            point[1] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, d / 2));
            point[2] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, d / 2));
            point[3] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2));
            point[4] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (D / 2 - d / 2) / 3 + d / 2));
            point[5] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (D / 2 - d / 2) * 2 / 3 + d / 2));
            point[6] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, (D / 2 - d / 2) / 3 + d / 2));
            point[7] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, (D / 2 - d / 2) * 2 / 3 + d / 2));

            //Соединение верхнего прямоугольника
            lines[0] = oSketch.SketchLines.AddByTwoPoints(point[0], point[5]);
            lines[1] = oSketch.SketchLines.AddByTwoPoints(point[3], point[7]);
            lines[2] = oSketch.SketchLines.AddByTwoPoints(point[0], point[3]);
            lines[3] = oSketch.SketchLines.AddByTwoPoints(point[5], point[7]);

            //Содинение вершин нижнего прямоугольника
            lines[4] = oSketch.SketchLines.AddByTwoPoints(point[4], point[1]);
            lines[5] = oSketch.SketchLines.AddByTwoPoints(point[1], point[2]);
            lines[6] = oSketch.SketchLines.AddByTwoPoints(point[4], point[6]);
            lines[7] = oSketch.SketchLines.AddByTwoPoints(point[6], point[2]);

            //Ось вращения двух прямоугольников
            point[8] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[9] = oSketch.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0));
            lines[8] = oSketch.SketchLines.AddByTwoPoints(point[8], point[9]);

            //Closing the sketch
            oTrans["Подшипник"].End();

            //Вращение
            Profile oProfile = default(Profile);

            oProfile = (Profile)oSketch.Profiles.AddForSolid();
            RevolveFeature revolvefeature = default(RevolveFeature);

            revolvefeature = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile, lines[8], PartFeatureOperationEnum.kJoinOperation);



            /*
             * Новый скетч 1
             */



            //Новый sketch с окружностями
            PlanarSketch oSketch1 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans1  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Окружности
            point[10]  = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, (D / 2 + d / 2) / 2));
            point[11]  = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, (D / 2 + d / 2) / 2));
            circles[0] = oSketch1.SketchCircles.AddByCenterRadius(point[10], (D / 2 - d / 2) / 3.6);
            circles[1] = oSketch1.SketchCircles.AddByCenterRadius(point[11], (D / 2 - d / 2) / 3.6);

            //Ось вращения подшипника
            point[12] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[13] = oSketch1.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0));
            lines[9]  = oSketch1.SketchLines.AddByTwoPoints(point[12], point[13]);

            //Closing the sketch 1
            oTrans1.End();

            //Выдавливание выемки
            Profile oProfile1 = default(Profile);

            oProfile1 = (Profile)oSketch1.Profiles.AddForSolid();
            RevolveFeature revolvefeature1 = default(RevolveFeature);

            revolvefeature1 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile1, lines[9], PartFeatureOperationEnum.kCutOperation);

            /*
             * New sketch 4
             */

            //New sketch 4
            PlanarSketch oSketch4 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans4  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Четырехугольник для вычетания выдавливания по краям подшипнника (слева)
            point[20] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2 * 0.7916875 - 0.1));
            point[21] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, D / 2 * 0.9275625));
            point[22] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * 0.861125));
            point[23] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * 0.7916875 - 0.1));
            lines[12] = oSketch4.SketchLines.AddByTwoPoints(point[20], point[21]);
            lines[13] = oSketch4.SketchLines.AddByTwoPoints(point[20], point[23]);
            lines[14] = oSketch4.SketchLines.AddByTwoPoints(point[21], point[22]);
            lines[15] = oSketch4.SketchLines.AddByTwoPoints(point[22], point[23]);

            point[26] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2 * 0.7916875 - 0.1));
            point[27] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, D / 2 * 0.9275625));
            point[28] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * 0.861125));
            point[29] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * 0.7916875 - 0.1));
            lines[17] = oSketch4.SketchLines.AddByTwoPoints(point[26], point[27]);
            lines[18] = oSketch4.SketchLines.AddByTwoPoints(point[27], point[28]);
            lines[19] = oSketch4.SketchLines.AddByTwoPoints(point[28], point[29]);
            lines[20] = oSketch4.SketchLines.AddByTwoPoints(point[29], point[26]);

            //ось
            point[24] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[25] = oSketch4.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B, 0));
            lines[16] = oSketch4.SketchLines.AddByTwoPoints(point[24], point[25]);

            //Closing the sketch 4
            oTrans4.End();

            //Вычетание началось (слева)
            Profile oProfile4 = default(Profile);

            oProfile4 = (Profile)oSketch4.Profiles.AddForSolid();
            RevolveFeature revolveFeature4 = default(RevolveFeature);

            revolveFeature4 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile4, lines[16], PartFeatureOperationEnum.kCutOperation);



            /*
             * New sketch 2
             */



            //Новый sketch с окружностями
            PlanarSketch oSketch2 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans2  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Задаю полуокружность!
            point[14] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * n));
            point[15] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, D / 2 * m));
            lines[10] = oSketch2.SketchLines.AddByTwoPoints(point[14], point[15]);
            point[16] = oSketch2.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B / 4, (D / 2 + d / 2) / 2));
            arc[0]    = oSketch2.SketchArcs.AddByCenterStartEndPoint(point[16], point[15], point[14], false);


            //Closing the sketch 2
            oTrans2.End();


            //Выдавливание окружности 1
            Profile oProfile2 = default(Profile);

            oProfile2 = (Profile)oSketch2.Profiles.AddForSolid();
            RevolveFeature revolveFeature2 = default(RevolveFeature);

            revolveFeature2 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile2, lines[10], PartFeatureOperationEnum.kJoinOperation);

            //New sketch 3
            PlanarSketch oSketch3 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans3  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Задаю окружность второго шарика
            point[17] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * n));
            point[18] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, D / 2 * m));
            lines[11] = oSketch3.SketchLines.AddByTwoPoints(point[17], point[18]);
            point[19] = oSketch3.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(B * 3 / 4, (D / 2 + d / 2) / 2));
            arc[1]    = oSketch3.SketchArcs.AddByCenterStartEndPoint(point[19], point[17], point[18], false);

            //Closing the sketch 3
            oTrans3.End();

            //Вращение шарика
            Profile oProfile3 = default(Profile);

            oProfile3 = (Profile)oSketch3.Profiles.AddForSolid();
            RevolveFeature revolveFeature3 = default(RevolveFeature);

            revolveFeature3 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile3, lines[11], PartFeatureOperationEnum.kJoinOperation);

            WorkAxis         oAxis          = oCompDef["Подшипник"].WorkAxes[1];
            ObjectCollection oObjCollection = ThisApplication.TransientObjects.CreateObjectCollection();

            oObjCollection.Add(revolveFeature3);
            CircularPatternFeature CircularPatternFeature = oCompDef["Подшипник"].Features.CircularPatternFeatures.Add(oObjCollection, oAxis, true, count, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute);

            WorkAxis         oAxis1          = oCompDef["Подшипник"].WorkAxes[1];
            ObjectCollection oObjCollection1 = ThisApplication.TransientObjects.CreateObjectCollection();

            oObjCollection1.Add(revolveFeature2);
            CircularPatternFeature oCircularPatternFeature1 = oCompDef["Подшипник"].Features.CircularPatternFeatures.Add(oObjCollection1, oAxis1, true, count, "360 degree", true, PatternComputeTypeEnum.kIdenticalCompute);



            /*НАЧАЛО ВАЛА
             * НАЧАЛО ВАЛА
             * НАЧАЛО ВАЛА
             * НАЧАЛО ВАЛА
             */



            //New sketch 5
            PlanarSketch oSketch5 = oCompDef["Подшипник"].Sketches.Add(oCompDef["Подшипник"].WorkPlanes[3]);
            Transaction  oTrans5  = ThisApplication.TransactionManager.StartTransaction(ThisApplication.ActiveDocument, "Create Sample");

            //Ось вала
            point[30] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, 0));
            point[31] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0.7, 0));
            lines[16] = oSketch5.SketchLines.AddByTwoPoints(point[30], point[31]);

            //Эскиз вала
            point[32] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, (((D / 2 - d / 2) / 3 + d / 2) + d / 2) / 2));
            point[33] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(0, d / 2));
            lines[17] = oSketch5.SketchLines.AddByTwoPoints(point[32], point[33]);
            point[34] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(-0.1 * k, (((D / 2 - d / 2) / 3 + d / 2) + d / 2) / 2));
            lines[18] = oSketch5.SketchLines.AddByTwoPoints(point[32], point[34]);
            point[35] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d(-0.1 * k, 0));
            lines[19] = oSketch5.SketchLines.AddByTwoPoints(point[34], point[35]);
            point[36] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k, d / 2));
            lines[20] = oSketch5.SketchLines.AddByTwoPoints(point[33], point[36]);
            point[37] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k, 0.4 * k));
            lines[21] = oSketch5.SketchLines.AddByTwoPoints(point[36], point[37]);
            point[38] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k + 0.3 * k, 0.4 * k));
            lines[22] = oSketch5.SketchLines.AddByTwoPoints(point[37], point[38]);
            point[39] = oSketch5.SketchPoints.Add(oTransGeom["Подшипник"].CreatePoint2d((B + 0.15) * k + 0.3 * k, 0));
            lines[23] = oSketch5.SketchLines.AddByTwoPoints(point[38], point[39]);
            lines[24] = oSketch5.SketchLines.AddByTwoPoints(point[39], point[35]);

            //Closing
            oTrans5.End();

            //Вращение вала
            Profile oProfile5 = default(Profile);

            oProfile5 = (Profile)oSketch5.Profiles.AddForSolid();
            RevolveFeature revolveFeature5 = default(RevolveFeature);

            revolveFeature5 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile5, lines[16], PartFeatureOperationEnum.kJoinOperation);

            //Вращение вала

            /*Profile oProfile5 = default(Profile);
             * oProfile5 = (Profile)oSketch5.Profiles.AddForSolid();
             * RevolveFeature revolveFeature5 = default(RevolveFeature);
             * revolveFeature5 = oCompDef["Подшипник"].Features.RevolveFeatures.AddFull(oProfile5, lines[16], PartFeatureOperationEnum.kJoinOperation);*/



            //см в мм
            D *= 10; d *= 10; B *= 10; r *= 10; r1 *= 10;
        }
示例#15
0
        //creating shaft
        internal static void Revolve()
        {
            Profile profile;

            try
            {
                var_es.lines = new List <SketchLine>();

                if (var_es.part_doc_def.Features.RevolveFeatures.Count != 0)
                {
                    //partDef.Features.RevolveFeatures[1].Delete();
                    foreach (RevolveFeature s in var_es.part_doc_def.Features.RevolveFeatures)
                    {
                        s.Delete();
                    }
                }

                if (var_es.part_doc_def.Sketches.Count != 0)
                {
                    foreach (Sketch s in var_es.part_doc_def.Sketches)
                    {
                        s.Delete();
                    }
                }

                partDef = var_es.part_doc.ComponentDefinition;

                tg     = var_es.InventorApp.TransientGeometry;
                sketch = partDef.Sketches.Add(partDef.WorkPlanes[3]);

                if (var_es.lines.Count > 0)
                {
                    var_es.lines.RemoveAt(var_es.lines.Count - 1);
                    sketch.SketchLines[sketch.SketchLines.Count].Delete();
                }


                foreach (Section obj in var_es._list)
                {
                    obj.DrawGeom(tg, ref sketch, ref var_es.lines);
                }


                var_es.lines.Add(sketch.SketchLines.AddByTwoPoints(var_es.lines[0].StartSketchPoint, var_es.lines[var_es.lines.Count - 1].EndSketchPoint));
                var_es.lines[var_es.lines.Count - 1].Centerline = true;

                profile = sketch.Profiles.AddForSolid();

                RevolveFeature ex = partDef.Features.RevolveFeatures.AddFull(profile, var_es.lines[var_es.lines.Count - 1], PartFeatureOperationEnum.kNewBodyOperation);



                //assinging all faces to each section
                Assign_all_faces();

                Assign_All_Faces();
            }
            catch { }


            //Chamfers and Fillets creation

            Chamfer_creation();

            #region Polygon creation
            try
            {
                //polyon creation by cutting out unneeded parts
                foreach (Section obj in var_es._list)
                {
                    if (obj.GetType().ToString() == "InvAddIn.Pol")
                    {
                        PlanarSketch sketch;
                        //getting sketch
                        try
                        {
                            sketch = partDef.Sketches.Add(obj.Start_face);
                        }
                        catch
                        {
                            sketch = partDef.Sketches.Add(obj.End_face);
                        }

                        sketch.Name = "Pol" + obj.Position;

                        //creatin points for sketchline, this line is polygon`s side, wich determines what should be cut off
                        Point2d first = tg.CreatePoint2d(), second = tg.CreatePoint2d();
                        var     k = (360 / obj.Number_of_Edges) / 2;
                        first.X  = Math.Cos(k * Math.PI / 180) * var_es._list[obj.Position].Radius;
                        first.Y  = Math.Sin(k * Math.PI / 180) * var_es._list[obj.Position].Radius;
                        second.X = first.X;
                        second.Y = first.Y * -1;

                        sketch.SketchLines.AddByTwoPoints(first, second);
                        //Arc to connect start and end point of polygon`s side , and mid-point is point on the the outside circle
                        sketch.SketchArcs.AddByThreePoints(sketch.SketchLines[1].StartSketchPoint, tg.CreatePoint2d(var_es._list[obj.Position].Radius), sketch.SketchLines[1].EndSketchPoint);
                        profile = sketch.Profiles.AddForSolid();

                        //adding extrude definition
                        ExtrudeDefinition extrude = partDef.Features.ExtrudeFeatures.CreateExtrudeDefinition(profile, PartFeatureOperationEnum.kCutOperation);
                        extrude.SetDistanceExtent(var_es._list[obj.Position].Length, PartFeatureExtentDirectionEnum.kNegativeExtentDirection);
                        ExtrudeFeature extrudeFeature = partDef.Features.ExtrudeFeatures.Add(extrude);

                        //creating circle array of features to make polygon
                        ObjectCollection OBJ_colection = var_es.InventorApp.TransientObjects.CreateObjectCollection();
                        OBJ_colection.Add(partDef.Features.ExtrudeFeatures[partDef.Features.ExtrudeFeatures.Count] as Object);
                        partDef.Features.CircularPatternFeatures.Add(OBJ_colection, partDef.WorkAxes[1], false, obj.Number_of_Edges + " ul", 360 + " deg", true, PatternComputeTypeEnum.kIdenticalCompute);
                    }
                }
            }
            catch (Exception e5)
            {
                MessageBox.Show(e5.ToString());
            }
            #endregion

            //All features creating

            try
            {
                Feature();
            }
            catch (Exception e113) { MessageBox.Show(e113.ToString()); }
        }
示例#16
0
        /////////////////////////////////////////////////////////////
        // Use: Creates new solid bodies affected by the future
        //      CoilFeature for Tapered Thread.
        /////////////////////////////////////////////////////////////
        private static bool CreateCoilBodyTapered(PartDocument doc,
                                                  ThreadInfo threadInfo,
                                                  Face threadedFace,
                                                  double depth,
                                                  bool isInteriorFace)
        {
            try
            {
                PartComponentDefinition compDef =
                    doc.ComponentDefinition;

                Vector direction = threadInfo.ThreadDirection;

                Point basePoint =
                    threadInfo.ThreadBasePoints[1] as Point;

                Point endPoint = _Tg.CreatePoint(
                    basePoint.X + direction.X,
                    basePoint.Y + direction.Y,
                    basePoint.Z + direction.Z);

                UnitVector yAxis = direction.AsUnitVector();

                UnitVector xAxis = Toolkit.GetOrthoVector(yAxis);

                WorkPoint wpt = compDef.WorkPoints.AddFixed(basePoint,
                                                            _ConstructionWorkFeature);

                WorkPlane wpl = compDef.WorkPlanes.AddFixed(basePoint,
                                                            xAxis, yAxis, _ConstructionWorkFeature);

                WorkAxis xWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         xAxis, _ConstructionWorkFeature);

                WorkAxis yWa = compDef.WorkAxes.AddFixed(basePoint,
                                                         yAxis, _ConstructionWorkFeature);

                PlanarSketch sketch =
                    compDef.Sketches.AddWithOrientation(wpl,
                                                        xWa, true, true, wpt, false);

                Cone cone = threadedFace.Geometry as Cone;

                double revDepth =
                    depth / Math.Cos(cone.HalfAngle) *
                    (isInteriorFace ? -1.0 : 1.0);

                Line l1 = Toolkit.GetFaceSideDirection(threadedFace, xAxis);

                Line l2 = _Tg.CreateLine(basePoint, xAxis.AsVector());

                Line l3 = _Tg.CreateLine(endPoint, xAxis.AsVector());

                Point p1 = l1.IntersectWithCurve(l2, 0.0001)[1] as Point;
                Point p2 = l1.IntersectWithCurve(l3, 0.0001)[1] as Point;

                Point p3 = _Tg.CreatePoint(
                    p2.X - xAxis.X * revDepth,
                    p2.Y - xAxis.Y * revDepth,
                    p2.Z - xAxis.Z * revDepth);

                Point p4 = _Tg.CreatePoint(
                    p1.X - xAxis.X * revDepth,
                    p1.Y - xAxis.Y * revDepth,
                    p1.Z - xAxis.Z * revDepth);

                SketchPoint skp1 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p1), false);

                SketchPoint skp2 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p2), false);

                SketchPoint skp3 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p3), false);

                SketchPoint skp4 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p4), false);

                sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                Profile profile = sketch.Profiles.AddForSolid(true,
                                                              null, null);

                RevolveFeature rev1 =
                    compDef.Features.RevolveFeatures.AddFull(
                        profile,
                        yWa,
                        PartFeatureOperationEnum.kCutOperation);

                sketch = compDef.Sketches.AddWithOrientation(wpl,
                                                             xWa, true, true, wpt, false);

                skp1 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p1), false);

                skp2 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p2), false);

                skp3 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p3), false);

                skp4 = sketch.SketchPoints.Add(
                    sketch.ModelToSketchSpace(p4), false);

                sketch.SketchLines.AddByTwoPoints(skp1, skp2);
                sketch.SketchLines.AddByTwoPoints(skp2, skp3);
                sketch.SketchLines.AddByTwoPoints(skp3, skp4);
                sketch.SketchLines.AddByTwoPoints(skp4, skp1);

                profile = sketch.Profiles.AddForSolid(true, null, null);

                RevolveFeature rev2 =
                    compDef.Features.RevolveFeatures.AddFull(
                        profile,
                        yWa,
                        PartFeatureOperationEnum.kNewBodyOperation);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#17
0
        private void ButtonBuild_Click(object sender, EventArgs e)
        {
            if (FalseWrite)
            {
                MessageBox.Show("Неправильно заданы входные параметры\nИсправьте красные поля");
                return;
            }

            string docName = "Первая деталь";

            CreateDoc(docName);

            // Создание эскиза на YX
            PlanarSketch Sketch = CompDef[docName].Sketches.Add(CompDef[docName].WorkPlanes[3]);    // 1 - YZ ; 2 - ZX; 3 - XY

            // Создание массивов Точек, Линий, Дуг, Окружностей
            List <SketchPoint>  points  = new List <SketchPoint>();  // Точки
            List <SketchLine>   lines   = new List <SketchLine>();   // Линии
            List <SketchArc>    arcs    = new List <SketchArc>();    // Дуги
            List <SketchCircle> circles = new List <SketchCircle>(); // Окружности

            /////////////////////////////////////////////////////////// Выдавливание

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 0), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 5.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 10.0 / 10), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 15.0 / 10), false));
            arcs.Add(Sketch.SketchArcs.AddByCenterStartEndPoint(points[points.Count - 2], points[points.Count - 3], points[points.Count - 1], true));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(0, 20.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(20.0 / 10, 20.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(20.0 / 10, 0), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[0], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(10.0 / 10, 10.0 / 10), false));
            circles.Add(Sketch.SketchCircles.AddByCenterRadius(points[points.Count - 1], 4.0 / 10));

            Profile ProfileMain = (Profile)Sketch.Profiles.AddForSolid();

            ExtrudeFeature ExtrudeDef = CompDef[docName].Features.ExtrudeFeatures.AddByDistanceExtent(
                /*Эскиз*/ ProfileMain,
                /*Длина в см*/ 10.0 / 10,
                /*Направление вдоль оси*/ PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                /*Операция*/ PartFeatureOperationEnum.kJoinOperation,
                /*Эскиз*/ ProfileMain);

            /////////////////////////////////////////////////////////// Вращение

            WorkPlane WorkinPlace = CompDef[docName].WorkPlanes.AddByPlaneAndOffset(
                CompDef[docName].WorkPlanes[2], 20.0 / 10);

            WorkinPlace.Visible = false;
            Sketch = CompDef[docName].Sketches.Add(WorkinPlace);

            SketchLine line_axis;

            points.Clear();
            lines.Clear();

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-(10.0 - 5) / 10, 0), false));
            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-(10.0 - 5) / 10, 10.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-10.0 / 10, 10.0 / 10), false));
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(-10.0 / 10, 0), false));
            line_axis = Sketch.SketchLines.AddByTwoPoints(points[points.Count - 2], points[points.Count - 1]);

            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[0], points[points.Count - 1]));

            Profile        ProfileExternal = (Profile)Sketch.Profiles.AddForSolid();
            RevolveFeature revolvefeature  = CompDef[docName].Features.RevolveFeatures.AddFull(
                ProfileExternal,
                line_axis,
                PartFeatureOperationEnum.kCutOperation);

            Trans[docName].End();

            /////////////////////////////////////////////////////////// Вторая деталь

            docName = "Вторая деталь";
            CreateDoc(docName);

            Sketch = CompDef[docName].Sketches.Add(CompDef[docName].WorkPlanes[3]);

            points.Clear();
            lines.Clear();

            ///////////////////////////////////////////////// Шестиугольник

            double R = 2 * (4.0 / 10) / Math.Sqrt(3), Angle;

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(
                                                   1.65 * Math.Cos(((double)210 / 180) * Math.PI),
                                                   1.65 * Math.Sin(((double)210 / 180) * Math.PI)), true));

            points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(points[0].Geometry.X + R, points[0].Geometry.Y), true));
            for (int i = 2; i < 7; i++)
            {
                Angle = ((((double)i - 2) * 60 + 120) / 180);
                points.Add(Sketch.SketchPoints.Add(TransGeom[docName].CreatePoint2d(
                                                       points[i - 1].Geometry.X + R * Math.Cos(Angle * Math.PI),
                                                       points[i - 1].Geometry.Y + R * Math.Sin(Angle * Math.PI)), true));

                lines.Add(Sketch.SketchLines.AddByTwoPoints(points[i - 1], points[i]));
            }
            lines.Add(Sketch.SketchLines.AddByTwoPoints(points[6], points[1]));

            ProfileMain = (Profile)Sketch.Profiles.AddForSolid();

            ExtrudeDef = CompDef[docName].Features.ExtrudeFeatures.AddByDistanceExtent(
                /*Эскиз*/ ProfileMain,
                /*Длина*/ 10.0 / 10,
                /*Направление вдоль оси*/ PartFeatureExtentDirectionEnum.kPositiveExtentDirection,
                /*Операция*/ PartFeatureOperationEnum.kJoinOperation,
                /*Эскиз*/ ProfileMain);

            ///////////////////////////////////////////////// Фаска
            ChamferFeature Fillet;

            EdgeCollection Edges = ThisApplication.TransientObjects.CreateEdgeCollection();

            int k = 0;

            foreach (SurfaceBody SurfBody in PartDoc[docName].ComponentDefinition.SurfaceBodies)
            {
                foreach (Edge Edge in SurfBody.Edges)
                {
                    if (k == 2)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 5)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 8)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 11)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 14)
                    {
                        Edges.Add(Edge);
                    }
                    if (k == 17)
                    {
                        Edges.Add(Edge);
                    }
                    k++;
                }
            }

            Fillet = CompDef[docName].Features.ChamferFeatures.AddUsingDistance(Edges, 2.0 / 10);

            ///////////////////////////////////////////////// СОПРЯЖЕНИЕ
            FilletFeature Fillet1;

            Edges.Clear();

            int n = 0;

            foreach (SurfaceBody SurfBody in PartDoc[docName].ComponentDefinition.SurfaceBodies)
            {
                foreach (Edge Edge in SurfBody.Edges)
                {
                    if (n == 18)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 20)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 21)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 23)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 26)
                    {
                        Edges.Add(Edge);
                    }
                    if (n == 27)
                    {
                        Edges.Add(Edge);
                    }

                    n++;
                }
            }

            Fillet1 = CompDef[docName].Features.FilletFeatures.AddSimple(Edges, /*Радиус*/ 1.0 / 10);

            // Заврешение транзакции
            Trans[docName].End();
        }