コード例 #1
0
        /// <summary>
        /// Create base of rounded chamfer
        /// </summary>
        /// <param name="figureParameters">Parameters of rounded chamfer</param>
        /// <returns>Extruded entity of base of rounded chamfer</returns>
        private ksEntity CreateBase(RoundedChamferParameters figureParameters)
        {
            // 1.1 Base of rounded chamfer
            var innerCircleSketch = new KompasSketch(figureParameters.Document3DPart, figureParameters.RegularPolygonSketch);

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

            var innerCircleEdit = innerCircleSketch.BeginEntityEdit();

            if (innerCircleEdit == null)
            {
                LastErrorCode = innerCircleSketch.LastErrorCode;
                return(null);
            }

            if (innerCircleEdit.ksCircle(figureParameters.BasePlanePoint.X, figureParameters.BasePlanePoint.Y, _kompasApp.Parameters[1] / 2.0, 1) == 0)             // d
            {
                LastErrorCode = ErrorCodes.Document2DCircleCreatingError;
                return(null);
            }

            innerCircleSketch.EndEntityEdit();

            // 1.2 Hat rounded chamfer base extrusion
            var extrusionParameters  = new KompasExtrusionParameters(figureParameters.Document3DPart, Obj3dType.o3d_baseExtrusion, innerCircleSketch.Entity, figureParameters.Direction, _kompasApp.Parameters[4] * 0.16);
            var innerCircleExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.ByEntity);             // Height of chamfer is 0.16 * H

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

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

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

            return(extruded);
        }
コード例 #2
0
        /// <summary>
        /// Draws the word "XYZ" on plane.
        /// This function is using for debugging other functions
        /// which are working with sketches.
        /// </summary>
        /// <param name="_doc3DPart">Kompas part of 3D document</param>
        /// <param name="plane">Selected plane</param>
        public static void DrawXyzOnPlane(ksPart _doc3DPart, ksEntity plane)
        {
            var xyz = new KompasSketch(_doc3DPart, plane);

            var xyzEdit = xyz.BeginEntityEdit();

            // Draw X
            xyzEdit.ksLineSeg(0, 0, -5, -10, 1);                        // "/"
            xyzEdit.ksLineSeg(0, -10, -5, 0, 1);                        // "\"

            // Draw Y
            xyzEdit.ksLineSeg(-7, 0, -13, -10, 1);                      // "/"
            xyzEdit.ksLineSeg(-7, -10, -10, -5, 1);                     // top half of "\"

            // Draw Z
            xyzEdit.ksLineSeg(-15, -10, -20, -10, 1);                   // top "--"
            xyzEdit.ksLineSeg(-20, -10, -15, 0, 1);                     // "/"
            xyzEdit.ksLineSeg(-15, 0, -20, 0, 1);                       // bottom "--"

            xyz.EndEntityEdit();
        }
コード例 #3
0
        /// <summary>
        /// Create section operation of rounded chamfer
        /// </summary>
        /// <returns>true if operation successful; false in case of error</returns>
        private bool CreateSection(RoundedChamferParameters figureParameters, ksEntity baseOfChamfer)
        {
            // 1.3 Hat rounded chamfer sketches for section operation:
            // 1.3.1 Extra inner circle
            var extraInnerCircleSketch = new KompasSketch(figureParameters.Document3DPart, baseOfChamfer);

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

            var extraInnerCircleEdit = extraInnerCircleSketch.BeginEntityEdit();

            if (extraInnerCircleEdit == null)
            {
                LastErrorCode = extraInnerCircleSketch.LastErrorCode;
                return(false);
            }

            if (extraInnerCircleEdit.ksCircle(figureParameters.BasePlanePoint.X, figureParameters.BasePlanePoint.Y, _kompasApp.Parameters[1] / 2.0, 1) == 0)             // d
            {
                LastErrorCode = extraInnerCircleSketch.LastErrorCode;
                return(false);
            }

            extraInnerCircleSketch.EndEntityEdit();

            // 1.3.3.2 Extra regular polygon
            var extraRegPolySketch = new KompasSketch(figureParameters.Document3DPart, figureParameters.RegularPolygonSketch);

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

            var extraRegPolyEdit = extraRegPolySketch.BeginEntityEdit();

            if (extraRegPolyEdit == null)
            {
                LastErrorCode = extraRegPolySketch.LastErrorCode;
                return(false);
            }

            if (extraRegPolyEdit.ksRegularPolygon(figureParameters.RegularPolygonParameters.FigureParam, 0) == 0)
            {
                LastErrorCode = extraRegPolySketch.LastErrorCode;
                return(false);
            }

            extraRegPolySketch.EndEntityEdit();

            // 1.3.4 Hat rounded chamfer section operation
            var screwChamferSketches = (ksEntityCollection)_kompasApp.Document3D.EntityCollection((short)Obj3dType.o3d_sketch);

            screwChamferSketches.Clear();
            screwChamferSketches.Add(extraInnerCircleSketch.Entity);
            screwChamferSketches.Add(extraRegPolySketch.Entity);
            screwChamferSketches.refresh();

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

            var extrusionParameters   = new KompasExtrusionParameters(figureParameters.Document3DPart, Obj3dType.o3d_baseLoft, null, screwChamferSketches);
            var screwChamferExtrusion = new KompasExtrusion(extrusionParameters, ExtrusionType.BySketchesCollection);

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

            if (extraInnerCircleSketch.Entity == null)
            {
                LastErrorCode = ErrorCodes.ArgumentNull;
                return(false);
            }

            Entity = extraInnerCircleSketch.Entity;

            return(true);
        }