Esempio n. 1
0
        public void TestCutBySketch(ErrorCodes errorCode, Obj3dType extrusionType, Direction_Type directionType)
        {
            var appTest = new KompasApplicationTest();
            var app     = appTest.CreateKompasApplication();
            var sketch  = CreateSketchWithCirle(app);

            var extrusionParameters = new KompasExtrusionParameters(app.ScrewPart, Obj3dType.o3d_baseExtrusion, sketch, directionType, 10);
            var extrusion           = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

            Assert.AreEqual(extrusion.LastErrorCode, errorCode);

            Direction_Type cutExtrusionDirection = Direction_Type.dtBoth;

            if (directionType == Direction_Type.dtNormal)
            {
                cutExtrusionDirection = Direction_Type.dtReverse;
            }
            else if (directionType == Direction_Type.dtReverse)
            {
                cutExtrusionDirection = Direction_Type.dtNormal;
            }

            extrusionParameters = new KompasExtrusionParameters(app.ScrewPart, extrusionType, sketch, cutExtrusionDirection, 10);
            var cutExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

            Assert.AreEqual(cutExtrusion.LastErrorCode, errorCode);
        }
Esempio n. 2
0
        public void CutBySketchUnsupportedDirection(ErrorCodes errorCode, Obj3dType extrusionType, Direction_Type directionType)
        {
            var appTest = new KompasApplicationTest();
            var app     = appTest.CreateKompasApplication();
            var sketch  = CreateSketchWithCirle(app);

            var extrusionParameters = new KompasExtrusionParameters(app.ScrewPart, Obj3dType.o3d_baseExtrusion, sketch, directionType, 10);
            var extrusion           = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

            Assert.AreEqual(extrusion.LastErrorCode, errorCode);
        }
Esempio n. 3
0
        /// <summary>
        /// Create thread of base of screw
        /// </summary>
        /// <returns>true if operation successful; false in case of error</returns>
        private bool CreateThread(ksEntity[] carvingEntities)
        {
            var coef     = 0.7;
            var gostspin = 0.037;
            var endX     = _kompasApp.Parameters[2] + _kompasApp.Parameters[3]
                           + (_kompasApp.Parameters[4] * 0.86);
            var startY = -(_kompasApp.Parameters[0] * coef / 2.0);
            var endY   = -(3.0 / 4.0 * _kompasApp.Parameters[0] * coef) / 2.0;

            var spinParameters = new SpinParameters
            {
                Document3DPart    = _kompasApp.ScrewPart,
                BeginSpinFace     = carvingEntities[1],
                EndSpinFace       = carvingEntities[0],
                SpinLocationPoint = new KompasPoint2D(0, 0),
                DiameterSize      = _kompasApp.Parameters[0] * coef,
                SpinStep          = _kompasApp.Parameters[3] * gostspin
            };

            var screwThreadSpin = new Spin(spinParameters);
            var step            = screwThreadSpin.SpinStep;

            var screwThreadSketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeXOZ);
            var screwThreadEdit   = screwThreadSketch.BeginEntityEdit();

            screwThreadEdit.ksLineSeg(endX - step, endY, endX, endY, 1);
            screwThreadEdit.ksLineSeg(endX, endY, endX - step / 2.0, startY, 1);
            screwThreadEdit.ksLineSeg(endX - step / 2.0, startY, endX - step, endY, 1);

            screwThreadSketch.EndEntityEdit();

            var spinCollection = (ksEntityCollection)_kompasApp.ScrewPart.EntityCollection(
                (short)Obj3dType.o3d_cylindricSpiral);

            spinCollection.Clear();
            spinCollection.Add(screwThreadSpin.Entity);
            spinCollection.refresh();

            if (spinCollection.GetCount() != 1)
            {
                LastErrorCode = ErrorCodes.EntityCollectionWrong;
            }

            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart,
                                                                    Obj3dType.o3d_baseEvolution, screwThreadSketch.Entity, spinCollection);
            var screwThreadExtrusion = new KompasExtrusion(
                extrusionParameters, ExtrusionType.BySketchesCollection);

            return(true);
        }
Esempio n. 4
0
        /// <summary>
        /// Delete cylinder which sets base plane of nut
        /// </summary>
        /// <param name="nutBasePlane">Base plane (see <seealso cref="CreateDetail"></seealso> for more info)</param>
        /// <param name="basePlaneCylinderDepth">Depth of cylinder of base plane (see <seealso cref="CreateDetail"></seealso> for more info)</param>
        /// <returns>true if operation successful, false in case of error</returns>
        private bool DeleteNutBasePlaneCylinder(ksEntity nutBasePlane, double basePlaneCylinderDepth)
        {
            // 1.2 Delete cylinder
            // В случае чего поменять Reverse на Normal
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.NutPart, Obj3dType.o3d_cutExtrusion, nutBasePlane, Direction_Type.dtNormal, basePlaneCylinderDepth);
            var cylinderDeletion    = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

            if (cylinderDeletion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = cylinderDeletion.LastErrorCode;
                return(false);
            }

            return(true);
        }
Esempio n. 5
0
        /// <summary>
        /// Метод выдавливания для гладкой части и резьбы
        /// </summary>
        /// <param name="screwBase"></param>
        /// <param name="type">тип выдавливания</param>
        /// <param name="extrusionHeight">высота выдавливания</param>
        /// <returns></returns>
        private ksEntity ExtrusionScrew(KompasSketch screwBase,
                                        Direction_Type type, Double extrusionHeight)
        {
            var extrusionParameters = new KompasExtrusionParameters
                                      (
                _kompasApp.ScrewPart,
                Obj3dType.o3d_baseExtrusion,
                screwBase.Entity,
                type,
                extrusionHeight
                                      );

            var screwCarvingExtrusion = new KompasExtrusion(extrusionParameters,
                                                            ExtrusionType.ByEntity);

            screwCarvingExtrusion.BaseFaceAreaState =
                KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;

            var extruded = screwCarvingExtrusion.ExtrudedEntity;

            return(extruded);
        }
Esempio n. 6
0
        /// <summary>
        /// Create nut base cut for thread of screw
        /// </summary>
        /// <param name="chamferEntities">Chamfer entities from left and right sides of nut</param>
        /// <param name="nutBasePoint">Nut base point</param>
        /// <returns>true if operation successful; false in case of error</returns>
        private bool CreateBaseCut(ksEntity[] chamferEntities, KompasPoint3D nutBasePoint)
        {
            // 1.4 Nut base cut
            var nutBaseCut = new KompasSketch(_kompasApp.NutPart, chamferEntities[0]);

            if (nutBaseCut.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = ErrorCodes.EntityCreateError;
                return(false);
            }

            var nutBaseCutEdit = nutBaseCut.BeginEntityEdit();

            if (nutBaseCutEdit == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(false);
            }
            if (nutBaseCutEdit.ksCircle(nutBasePoint.Y, nutBasePoint.Z, 0.75 * _kompasApp.Parameters[5] / 2.0, 1) == 0)               // / D /
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(false);
            }

            nutBaseCut.EndEntityEdit();

            // 1.5 Nut base cut extrusion
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.NutPart, Obj3dType.o3d_cutExtrusion, nutBaseCut.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[4]);
            var nutBaseCutExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);                // / H /

            if (nutBaseCutExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = nutBaseCutExtrusion.LastErrorCode;
                return(false);
            }

            return(true);
        }
Esempio n. 7
0
        /// <summary>
        /// Create screw hat with extrusion operation
        /// </summary>
        /// "regPoly" here is abbreviation of Regular Polygon
        /// Screw hat consists of base of hat (0.84 * H)
        /// and rounded chamfer on the top (0.16 * H)
        /// <returns>Extruded entity of hat for base part of screw</returns>
        private ksEntity CreateHat()
        {
            // 0.1 Create muffler, which base point is (W3 / 5, W3 / 5)
            var basePoint         = -(_kompasApp.Parameters[0] / 5.0);
            var mufflerParameters = new MufflerParameters();

            mufflerParameters.Document3DPart = _kompasApp.ScrewPart;
            mufflerParameters.Direction      = Direction_Type.dtNormal;
            mufflerParameters.BasePlaneAxis  = Obj3dType.o3d_planeYOZ;
            mufflerParameters.BasePlanePoint = new KompasPoint2D(basePoint, basePoint);

            var mufflerManager = new Muffler(_kompasApp, mufflerParameters);

            if (mufflerManager.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            var mufflerExtrusion = mufflerManager.Extrusion;

            if (mufflerExtrusion == null)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            // 1.1 Hat sketch
            var regPolySketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ);

            if (regPolySketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = regPolySketch.LastErrorCode;
                return(null);
            }

            var regPolySketchEdit = regPolySketch.BeginEntityEdit();

            if (regPolySketchEdit == null)
            {
                LastErrorCode = regPolySketch.LastErrorCode;
                return(null);
            }

            // Regular polygon center point
            var regPolyPoint = new KompasPoint2D(0, 0);
            // Regular polygon is base of hat
            var regPolyParam = new RegularPolygonParameter(_kompasApp, 6, _kompasApp.Parameters[0] / 2.0, regPolyPoint);              // W3

            if (regPolySketchEdit.ksRegularPolygon(regPolyParam.FigureParam, 0) == 0)
            {
                LastErrorCode = ErrorCodes.Document2DRegPolyCreatingError;
                return(null);
            }

            regPolySketch.EndEntityEdit();

            // 1.2 Hat entity extrusion
            // Screw hat height is equal to nut height
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, regPolySketch.Entity, Direction_Type.dtReverse, _kompasApp.Parameters[4] * 0.84);
            var regPolyExtrusion    = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);          // 0.84 * H

            if (regPolyExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = regPolyExtrusion.LastErrorCode;
                return(null);
            }

            /* Main base face area is lower than parallel base face
             * because of muffler partially overlaps main base face area,
             * but not overlaps parallel base face area.
             */
            regPolyExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var extruded = regPolyExtrusion.ExtrudedEntity;

            if (extruded == null)
            {
                LastErrorCode = regPolyExtrusion.LastErrorCode;
                return(null);
            }

            // 0.2 Delete muffler
            if (!mufflerManager.DeleteDetail())
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            // 1.3 Rounded chamfer in hat
            var roundedChamferParameters = new RoundedChamferParameters();

            roundedChamferParameters.Document3DPart           = _kompasApp.ScrewPart;
            roundedChamferParameters.RegularPolygonSketch     = regPolySketch.Entity;
            roundedChamferParameters.RegularPolygonParameters = regPolyParam;
            roundedChamferParameters.BasePlanePoint           = new KompasPoint2D(0.0, 0.0);
            roundedChamferParameters.Direction = Direction_Type.dtNormal;
            var roundedChamferManager = new RoundedChamfer(_kompasApp, roundedChamferParameters);

            if (!roundedChamferManager.CreateDetail())
            {
                LastErrorCode = roundedChamferManager.LastErrorCode;
                return(null);
            }

            return(extruded);
        }
Esempio n. 8
0
        /// <summary>
        /// Create thread of base of screw
        /// </summary>
        /// <returns>true if operation successful; false in case of error</returns>
        private bool CreateThread(ksEntity[] carvingEntities)
        {
            // 1.5 Screw base thread spin
            // Spin step by russian GOST is equal to 0.037 (i.e. 3.7%) of spin height
            var spinParameters = new SpinParameters();

            spinParameters.Document3DPart    = _kompasApp.ScrewPart;
            spinParameters.BeginSpinFace     = carvingEntities[1];
            spinParameters.EndSpinFace       = carvingEntities[0];
            spinParameters.SpinLocationPoint = new KompasPoint2D(0, 0);
            spinParameters.DiameterSize      = _kompasApp.Parameters[0] * 0.7;      // 0.7 W3
            spinParameters.SpinStep          = _kompasApp.Parameters[3] * 0.037;    //  0.037 W2

            var screwThreadSpin = new Spin(spinParameters);

            if (screwThreadSpin.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwThreadSpin.LastErrorCode;
                return(false);
            }

            ThreadStep = screwThreadSpin.SpinStep;
            if (!DoubleValidator.Validate(ThreadStep))
            {
                LastErrorCode = ErrorCodes.DoubleValueValidationError;
                return(false);
            }

            // 1.6 Screw base thread sketch
            var screwThreadSketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeXOZ);

            if (screwThreadSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwThreadSketch.LastErrorCode;
                return(false);
            }

            var screwThreadEdit = screwThreadSketch.BeginEntityEdit();

            if (screwThreadEdit == null)
            {
                LastErrorCode = screwThreadSketch.LastErrorCode;
                return(false);
            }

            var step = screwThreadSpin.SpinStep;
            // W1 + W2 + 3 thread steps - 0.86 * W3 (because part with 0.16 * W3 is in coordinates which are less than zero of XOZ)
            var endX = _kompasApp.Parameters[2] + _kompasApp.Parameters[3] + _kompasApp.Parameters[4] * 0.86;

            var startY = -(_kompasApp.Parameters[0] * 0.7 / 2.0);               // 0.7 * W3
            var endY   = -(3.0 / 4.0 * _kompasApp.Parameters[0] * 0.7) / 2.0;   // 0.7 * W3 on end of base

            //	Draw triangle: the base of thread.
            screwThreadEdit.ksLineSeg(endX - step, endY, endX, endY, 1);
            screwThreadEdit.ksLineSeg(endX, endY, endX - step / 2.0, startY, 1);
            screwThreadEdit.ksLineSeg(endX - step / 2.0, startY, endX - step, endY, 1);

            screwThreadSketch.EndEntityEdit();

            // 1.7 Screw base thread extrusion
            var spinCollection = (ksEntityCollection)_kompasApp.ScrewPart.EntityCollection((short)Obj3dType.o3d_cylindricSpiral);

            if (spinCollection == null)
            {
                LastErrorCode = ErrorCodes.EntityCollectionCreateError;
                return(false);
            }
            spinCollection.Clear();

            spinCollection.Add(screwThreadSpin.Entity);
            spinCollection.refresh();

            if (spinCollection.GetCount() != 1)
            {
                LastErrorCode = ErrorCodes.EntityCollectionWrong;
            }

            var extrusionParameters  = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseEvolution, screwThreadSketch.Entity, spinCollection);
            var screwThreadExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.BySketchesCollection);

            if (screwThreadExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = ErrorCodes.EntityCreateError;
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        /// <summary>
        /// Create screw base with extrusion operation
        /// </summary>
        /// Width of screw base cylinder is 0.7 * W3
        /// <param name="basePlaneofHat">Base plane of hat of screw</param>
        /// <returns>
        /// Carving entities: smooth part end and thread part end,
        /// these ones need for thread operation
        /// </returns>
        private ksEntity[] CreateBase(ksEntity basePlaneOfHat)
        {
            // 1. Screw base creation
            // 1.1 Screw base entity
            var screwBase = new KompasSketch(_kompasApp.ScrewPart, basePlaneOfHat);

            if (screwBase.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwBase.LastErrorCode;
                return(null);
            }

            var screwBasePoint = new KompasPoint2D(0, 0);

            if (screwBasePoint.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwBasePoint.LastErrorCode;
                return(null);
            }

            var screwBaseSketchEdit = screwBase.BeginEntityEdit();

            if (screwBaseSketchEdit == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(null);
            }
            if (screwBaseSketchEdit.ksCircle(screwBasePoint.X, screwBasePoint.Y, _kompasApp.Parameters[0] * 0.7 / 2.0, 1) == 0)             // / 0.7 * W3 /
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(null);
            }
            screwBase.EndEntityEdit();

            // 1.2 Screw base extrusion
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, screwBase.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[2]);
            var screwBaseExtrusion  = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);            // W1

            if (screwBaseExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwBaseExtrusion.LastErrorCode;
                return(null);
            }

            screwBaseExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var extruded = screwBaseExtrusion.ExtrudedEntity;

            if (extruded == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(null);
            }

            // 1.3 Screw base carving
            var screwCarving = new KompasSketch(_kompasApp.ScrewPart, screwBaseExtrusion.ExtrudedEntity);             // Last entity in last extrusion

            if (screwCarving.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwCarving.LastErrorCode;
                return(null);
            }

            var screwCarvingSketchEdit = screwCarving.BeginEntityEdit();

            if (screwCarvingSketchEdit == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(null);
            }
            // Carving is 1/4 of 70 % (i.e. is 0.525) of W3
            if (screwCarvingSketchEdit.ksCircle(0, 0, (_kompasApp.Parameters[0] * 0.525 / 2.0), 1) == 0)               // / W1 thread /
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(null);
            }
            screwCarving.EndEntityEdit();

            // 1.4 Screw base carving extrusion
            extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, screwCarving.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[3]);
            var screwCarvingExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);                //  / W2 /

            if (screwCarvingExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwCarvingExtrusion.LastErrorCode;
                return(null);
            }

            screwCarvingExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            extruded = screwCarvingExtrusion.ExtrudedEntity;
            if (extruded == null)
            {
                LastErrorCode = screwCarvingExtrusion.LastErrorCode;
                return(null);
            }

            return(new ksEntity[2] {
                screwCarving.Entity, extruded
            });
        }
Esempio n. 10
0
        /// <summary>
        /// Создание шляпки винта с методом выдавливания
        /// </summary>
        /// <returns>Выдавленная шляпки винта для базовой части винта</returns>
        private ksEntity CreateHat()
        {
            // 0.1 Create muffler, which base point is (D / 5, D / 5)
            var basePoint         = -(_kompasApp.Parameters[0] / 5.0);
            var mufflerParameters = new MufflerParameters
            {
                Document3DPart = _kompasApp.ScrewPart,
                Direction      = Direction_Type.dtNormal,
                BasePlaneAxis  = Obj3dType.o3d_planeYOZ,
                BasePlanePoint = new KompasPoint2D(basePoint, basePoint)
            };

            var mufflerManager = new Muffler(_kompasApp, mufflerParameters);

            if (mufflerManager.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            var mufflerExtrusion = mufflerManager.Extrusion;

            if (mufflerExtrusion == null)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            // 1.1 Create hat
            var screwHat = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ);

            if (screwHat.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwHat.LastErrorCode;
                return(null);
            }

            var screwHatSketchEdit = screwHat.BeginEntityEdit();

            if (screwHatSketchEdit == null)
            {
                LastErrorCode = screwHat.LastErrorCode;
                return(null);
            }

            var screwHatPoint = new KompasPoint2D(0, 0);

            if (screwHatSketchEdit.ksCircle(screwHatPoint.X, screwHatPoint.Y, _kompasApp.Parameters[0] / 2, 1) == 0)
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(null);
            }
            screwHat.EndEntityEdit();

            // 1.2 Screw base extrusion
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_baseExtrusion, screwHat.Entity, Direction_Type.dtReverse, _kompasApp.Parameters[4] * 0.84);
            var screwHatExtrusion   = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity); // H

            if (screwHatExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = screwHatExtrusion.LastErrorCode;
                return(null);
            }

            screwHatExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var extruded = screwHatExtrusion.ExtrudedEntity;

            if (extruded == null)
            {
                LastErrorCode =
                    screwHatExtrusion.LastErrorCode;
                return(null);
            }
            // 0.2 Delete muffler
            if (!mufflerManager.DeleteDetail())
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }



            //Create slot
            var rectangleSketch = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ);

            if (rectangleSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = rectangleSketch.LastErrorCode;
                return(null);
            }

            var rectangleSketchEdit = rectangleSketch.BeginEntityEdit();

            if (rectangleSketchEdit == null)
            {
                LastErrorCode = rectangleSketch.LastErrorCode;
                return(null);
            }
            var rectanglePoint = new KompasPoint2D(-_kompasApp.Parameters[0], -_kompasApp.Parameters[5] / 2);
            var rectangleParam = new RectangleParameter(_kompasApp, _kompasApp.Parameters[0] * 2, _kompasApp.Parameters[5], rectanglePoint);

            if (rectangleSketchEdit.ksRectangle(rectangleParam.FigureParam, 0) == 0)
            {
                LastErrorCode = ErrorCodes.EntityDefinitionNull;
                return(null);
            }
            rectangleSketch.EndEntityEdit();

            extrusionParameters = new KompasExtrusionParameters(_kompasApp.ScrewPart, Obj3dType.o3d_cutExtrusion, rectangleSketch.Entity, Direction_Type.dtNormal, _kompasApp.Parameters[1] * 0.84);
            var rectangleExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity); // m; выдавливание шлица методом вырезания на глубину m

            if (rectangleExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = rectangleExtrusion.LastErrorCode;
                return(null);
            }



            return(extruded);
        }
Esempio n. 11
0
        /// <summary>
        /// Create nut thread
        /// </summary>
        /// Creating inner thread tooth:
        ///				  endZZ
        ///			A------=------B	•–→X
        ///			|\	   |	 /|	↓
        ///			| \	   |	/ |	Z
        ///			|  \   |   /  |
        ///	startX	|	\  |  /	  | endX
        ///			|	 \ | /	  |
        ///			|     \|/	  |
        ///			|------C------|
        ///				 startZ
        ///
        ///
        ///		Here offsetX is (W1 + W2 + H + 0.1*W1*W2 (i.e. _basePlaneCylinderDepth) - 0.68 * H (i.e. nut height minus heights of right and left chamfers)
        ///		(chamfer is 0.16 of neight of nut)
        ///
        ///		threadStartX = offsetX - step;
        ///		threadEndX = offsetX;
        ///
        ///		threadEndZ = 1/2 * (0.7 * W3)
        ///		threadStartZ = 1/2 * (3/4 * 0.7 * W3)
        ///
        ///		A = (threadStartX; threadEndZ);
        ///		B = (threadEndX; threadEndZ);
        ///		C = (threadStartX + step/2; threadStartZ);
        /// <param name="chamferEntities">Chamfer entities from left and right sides of nut</param>
        /// <param name="nutBasePoint">Nut base point</param>
        /// <param name="basePlaneCylinderDepth">Depth of cylinder of base plane (see <seealso cref="CreateDetail"></seealso> for more info)</param>
        /// <returns>true if operation successful; false in case of error</returns>
        private bool CreateNutThread(ksEntity[] chamferEntities, KompasPoint3D nutBasePoint, double basePlaneCylinderDepth)
        {
            // 1.6 Nut base thread spin
            var spinParameters = new SpinParameters();

            spinParameters.Document3DPart    = _kompasApp.NutPart;
            spinParameters.BeginSpinFace     = chamferEntities[1];
            spinParameters.EndSpinFace       = chamferEntities[0];
            spinParameters.SpinLocationPoint = new KompasPoint2D(nutBasePoint.Y, nutBasePoint.Z);
            spinParameters.DiameterSize      = _kompasApp.Parameters[5];
            spinParameters.SpinStep          = _kompasApp.ThreadStep;

            var nutThreadSpin = new Spin(spinParameters);             // D

            if (nutThreadSpin.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = nutThreadSpin.LastErrorCode;
                return(false);
            }

            // 1.7 Nut base thread sketch
            var nutThreadSketch = new KompasSketch(_kompasApp.NutPart, Obj3dType.o3d_planeXOZ);

            if (nutThreadSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = nutThreadSketch.LastErrorCode;
                return(false);
            }

            var nutThreadEdit = nutThreadSketch.BeginEntityEdit();

            // See comment on top of the function
            // 0.18 is 0.16 plus some extra space: 0.02.
            var offsetX = basePlaneCylinderDepth + _kompasApp.Parameters[4] * 0.18;
            var step    = _kompasApp.ThreadStep;

            var threadStartX = offsetX - step;
            var threadEndX   = offsetX;

            var threadStartZ = 1.0 / 2.0 * (_kompasApp.Parameters[0] * 0.7);                            // 1/2 * (0.7 * W3)
            var threadEndZ   = 1.0 / 2.0 * (_kompasApp.Parameters[0] * 0.7 * (3.0 / 4.0));              // 1/2 * (3/4 * 0.7 * W3)

            //	A = (threadStartX; threadEndZ);
            //	B = (threadEndX; threadEndZ);
            //	C = (threadStartX + step/2; threadStartZ);
            nutThreadEdit.ksLineSeg(threadStartX, threadEndZ, threadEndX, threadEndZ, 1);                                       // AB
            nutThreadEdit.ksLineSeg(threadStartX, threadEndZ, threadStartX + step / 2.0, threadStartZ, 1);                      // AC
            nutThreadEdit.ksLineSeg(threadStartX + step / 2.0, threadStartZ, threadEndX, threadEndZ, 1);                        // CB

            nutThreadSketch.EndEntityEdit();

            // 1.8 Nut base spin creation
            var spinCollection = (ksEntityCollection)_kompasApp.ScrewPart.EntityCollection((short)Obj3dType.o3d_cylindricSpiral);

            spinCollection.Clear();
            spinCollection.Add(nutThreadSpin.Entity);
            spinCollection.refresh();

            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.NutPart, Obj3dType.o3d_cutEvolution, nutThreadSketch.Entity, spinCollection);
            var nutBaseSpin         = new KompasExtrusion(extrusionParameters, ExtrusionType.BySketchesCollection);

            if (nutBaseSpin.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = nutBaseSpin.LastErrorCode;
                return(false);
            }

            return(true);
        }
Esempio n. 12
0
        /// <summary>
        /// Create nut base extrusion and sketch entities
        /// </summary>
        /// <param name="nutBasePlane">Base plane (see <seealso cref="CreateDetail"></seealso> for more info)</param>
        /// <param name="nutBasePoint">Nut base point</param>
        /// <param name="regPolyParam">Regular polygon parameters</param>
        /// <returns>
        /// An array of nut base sketch and extrusion entities
        /// or null in case of error during creation
        /// </returns>
        private ksEntity[] CreateNutBase(ksEntity nutBasePlane, KompasPoint3D nutBasePoint, RegularPolygonParameter regPolyParam)
        {
            // 1.1 Nut base sketch
            var nutBaseSketch = new KompasSketch(_kompasApp.NutPart, nutBasePlane);

            if (nutBaseSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = nutBaseSketch.LastErrorCode;
                return(null);
            }

            var nutBaseEdit = nutBaseSketch.BeginEntityEdit();

            if (nutBaseEdit == null)
            {
                LastErrorCode = nutBaseSketch.LastErrorCode;
                return(null);
            }

            // Nut width is equal to W3 (screw hat width)
            if (nutBaseEdit.ksRegularPolygon(regPolyParam.FigureParam, 1) == 0)
            {
                LastErrorCode = ErrorCodes.Document2DRegPolyCreatingError;
                return(null);
            }

            nutBaseSketch.EndEntityEdit();

            // 1.2 Nut base extrusion
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.NutPart, Obj3dType.o3d_baseExtrusion, nutBaseSketch.Entity, Direction_Type.dtReverse, _kompasApp.Parameters[4] / 2.0);
            var nutBaseExtrusion    = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);           // / H /

            if (nutBaseExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = nutBaseExtrusion.LastErrorCode;
                return(null);
            }

            // 0.1 Create muffler
            var mufflerParameters = new MufflerParameters();

            mufflerParameters.Document3DPart = _kompasApp.NutPart;
            mufflerParameters.Direction      = Direction_Type.dtNormal;
            mufflerParameters.BasePlaneAxis  = Obj3dType.o3d_planeXOZ;
            mufflerParameters.BasePlanePoint = new KompasPoint2D(nutBasePoint.Y, nutBasePoint.Z);

            var muffler = new Muffler(_kompasApp, mufflerParameters, nutBaseSketch.Entity);

            if (muffler.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = muffler.LastErrorCode;
                return(null);
            }

            // 1.3 Get base plane
            nutBaseExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var nutBaseExtrudedEntity = nutBaseExtrusion.ExtrudedEntity;

            if (nutBaseExtrudedEntity == null)
            {
                LastErrorCode = nutBaseExtrusion.LastErrorCode;
                return(null);
            }

            // 0.2 Delete muffler
            if (!muffler.DeleteDetail())
            {
                LastErrorCode = muffler.LastErrorCode;
                return(null);
            }

            return(new ksEntity[2] {
                nutBaseSketch.Entity, nutBaseExtrudedEntity
            });
        }
Esempio n. 13
0
        /// <summary>
        /// Create base plane cylinder extrusion for nut
        /// </summary>
        /// <param name="basePlaneCylinderDepth">Depth of cylinder of base plane (see <seealso cref="CreateDetail"></seealso> for more info)</param>
        /// <param name="nutBasePoint">Nut base point</param>
        /// <returns>Nut base cylinder extruded entity or null in case of error during creation</returns>
        private ksEntity CreateNutBasePlaneCylinder(KompasPoint3D nutBasePoint, double basePlaneCylinderDepth)
        {
            // 1. Create plane in global coordinates.
            // We are using small cylinder with diameter 0.1*W3 in base plane YOZ
            // and extrude him in length: W1 + W2 + H + 0.1*W1*W2.
            // Extruded plane is plane in global coordinates.
            // After this we can simply delete the cylinder.

            // 1.1 Cylinder sketch
            var basePlaneCylinderSketch = new KompasSketch(_kompasApp.NutPart, Obj3dType.o3d_planeYOZ);

            if (basePlaneCylinderSketch.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = basePlaneCylinderSketch.LastErrorCode;
                return(null);
            }

            var cylinderSketchEdit = basePlaneCylinderSketch.BeginEntityEdit();

            if (cylinderSketchEdit.ksCircle(nutBasePoint.Y, nutBasePoint.Z, _kompasApp.Parameters[0] * 0.1, 1) == 0)
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(null);
            }

            basePlaneCylinderSketch.EndEntityEdit();


            // 1.2 Cylinder extrusion
            var extrusionParameters = new KompasExtrusionParameters(_kompasApp.NutPart, Obj3dType.o3d_baseExtrusion, basePlaneCylinderSketch.Entity, Direction_Type.dtReverse, basePlaneCylinderDepth);
            var cylinderExtrusion   = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);

            if (cylinderExtrusion.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = cylinderExtrusion.LastErrorCode;
                return(null);
            }

            // 0.1 Muffler creation
            var mufflerParameters = new MufflerParameters();

            mufflerParameters.Document3DPart = _kompasApp.NutPart;
            mufflerParameters.Direction      = Direction_Type.dtNormal;
            mufflerParameters.BasePlaneAxis  = Obj3dType.o3d_planeYOZ;
            mufflerParameters.BasePlanePoint = new KompasPoint2D(nutBasePoint.Y, nutBasePoint.Z);

            var mufflerManager = new Muffler(_kompasApp, mufflerParameters);

            if (mufflerManager.LastErrorCode != ErrorCodes.OK)
            {
                LastErrorCode = mufflerManager.LastErrorCode;
                return(null);
            }

            var mufflerExtrusion = mufflerManager.Extrusion;

            if (mufflerExtrusion == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(null);
            }

            // 1.3 Get nut base plane
            cylinderExtrusion.BaseFaceAreaState = KompasFaces.BaseFaceAreaState.BaseFaceAreaLower;
            var nutBasePlane = cylinderExtrusion.ExtrudedEntity;

            if (nutBasePlane == null)
            {
                LastErrorCode = cylinderExtrusion.LastErrorCode;
                return(null);
            }

            // 0.2 Muffler deletion
            if (!mufflerManager.DeleteDetail())
            {
                return(null);
            }

            return(nutBasePlane);
        }