/// <summary> /// метод создания скетча для шляпки винта /// </summary> /// <returns></returns> private ksEntity DrawScrewHat() { var screwHat = new KompasSketch(_kompasApp.ScrewPart, Obj3dType.o3d_planeYOZ); DrawScrew(screwHat, new KompasPoint2D(0, 0), _kompasApp.Parameters[0] / 2); return(ExtrusionScrew(screwHat, Direction_Type.dtReverse, _kompasApp.Parameters[4] * 0.84)); }
public void CreateOnNull(ErrorCodes errorCode, ksEntity entity) { var appTest = new KompasApplicationTest(); var app = appTest.CreateKompasApplication(); var sketch = new KompasSketch(app.ScrewPart, entity); Assert.AreEqual(sketch.LastErrorCode, errorCode); }
public void CreateOnBasePlaneAxis(ErrorCodes errorCode, Obj3dType basePlaneAxis) { var appTest = new KompasApplicationTest(); var app = appTest.CreateKompasApplication(); var sketch = new KompasSketch(app.ScrewPart, basePlaneAxis); Assert.AreEqual(sketch.LastErrorCode, errorCode); }
/// <summary> /// Create kompas sketch with circle inside /// </summary> /// <param name="app">Kompas application</param> /// <returns>Kompas sketch with circle</returns> public ksEntity CreateSketchWithCirle(KompasApplication app, int circleRadius = 10) { var sketch = new KompasSketch(app.ScrewPart, Obj3dType.o3d_planeXOY); var sketchEdit = sketch.BeginEntityEdit(); sketchEdit.ksCircle(0.0, 0.0, circleRadius, 1); sketch.EndEntityEdit(); return(sketch.Entity); }
/// <summary> /// Метод отрисовки скетчей основных частей винта /// гладкой и основы под резьбу /// </summary> /// <param name="screwBase"></param> /// <param name="screwBasePoint"> установка базовых точек для скетча</param> /// <param name="extrusionHeight">длинв на которую будет производиться выдавливание</param> /// <param name="LineStyle">стиль линии</param> /// <returns></returns> private bool DrawScrew(KompasSketch screwBase, KompasPoint2D screwBasePoint, Double extrusionHeight, Int32 LineStyle = 1) { var screwSketchEdit = screwBase.BeginEntityEdit(); if (screwSketchEdit.ksCircle(screwBasePoint.X, screwBasePoint.Y, extrusionHeight, LineStyle) == 0) { LastErrorCode = ErrorCodes.Document2DCircleCreatingError; return(false); } screwBase.EndEntityEdit(); return(true); }
/// <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); }
public void TestRectangleParameterNormal(ErrorCodes errorCode, double width, double height) { var appTest = new KompasApplicationTest(); var app = appTest.CreateKompasApplication(); var sketch = new KompasSketch(app.ScrewPart, Obj3dType.o3d_planeXOZ); var sketchEdit = sketch.BeginEntityEdit(); var rectangleParam = new RectangleParameter(app, width, height, new KompasPoint2D(0.0, 0.0)); sketchEdit.ksRectangle(rectangleParam.FigureParam); sketch.EndEntityEdit(); Assert.AreEqual(rectangleParam.LastErrorCode, errorCode); }
public void TestRegPolyParameterNormal(ErrorCodes errorCode, int anglesCount, double inscribedCircleRadius) { var appTest = new KompasApplicationTest(); var app = appTest.CreateKompasApplication(); var sketch = new KompasSketch(app.ScrewPart, Obj3dType.o3d_planeXOZ); var sketchEdit = sketch.BeginEntityEdit(); var rectangleParam = new RegularPolygonParameter(app, anglesCount, inscribedCircleRadius, new KompasPoint2D(0.0, 0.0)); sketchEdit.ksRectangle(rectangleParam.FigureParam); sketch.EndEntityEdit(); Assert.AreEqual(rectangleParam.LastErrorCode, errorCode); }
/// <summary> /// Create screw base with extrusion operation /// </summary> /// Width of screw base cylinder is 0.7 * D /// <param name="basePlaneofHat">Base plane of hat of screw</param> /// <returns> /// Carving entities: smooth part end and thread part end /// </returns> private ksEntity[] CreateBase(ksEntity basePlaneOfHat) { double coef = (_kompasApp.Parameters[0] * 0.700) / 2.0; double gostbase = (_kompasApp.Parameters[0] * 0.525) / 2.0; var screwBase = new KompasSketch(_kompasApp.ScrewPart, basePlaneOfHat); DrawScrew(screwBase, new KompasPoint2D(0, 0), coef); var extruded1 = ExtrusionScrew(screwBase, Direction_Type.dtNormal, _kompasApp.Parameters[2]); var screwCarving = new KompasSketch(_kompasApp.ScrewPart, extruded1); DrawScrew(screwCarving, new KompasPoint2D(0, 0), gostbase); var extruded2 = ExtrusionScrew(screwCarving, Direction_Type.dtNormal, _kompasApp.Parameters[3]); return(new ksEntity[2] { extruded1, extruded2 }); }
/// <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); }
/// <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); }
/// <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 }); }
/// <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); }
/// <summary> /// Строит часть модели. /// </summary> /// <param name="document3D">3D документ.</param> /// <param name="parameters">Параметры модели.</param> public void Create(ksDocument3D document3D, Dictionary <Parameter, ParameterData> parameters) { var isNightStand = (int)parameters[Parameter.IsNightStand].Value; if (isNightStand == 1) { return; } var isCut = (int)parameters[Parameter.IsCut].Value; #region - Построение подоконника - var bodyWidth = parameters[Parameter.BodyWidth].Value; // Ширина окна var bodyHeight = parameters[Parameter.BodyHeight].Value; // Ширина окна var bodyLength = parameters[Parameter.BodyLength].Value; // Глубина окна var thickness = parameters[Parameter.NightStandThic].Value; // Толщина стенки var nightStandHeight = parameters[Parameter.NightStandHeight].Value; //Вылет подоконника var part = (ksPart)document3D.GetPart((short)Part_Type.pNew_Part); if (part != null) { var sketchProperty = new KompasSketch { Shape = ShapeType.Line, // Чем рисовать Plane = PlaneType.PlaneXOY, // Плоскость для рисования NormalValue = nightStandHeight, Operation = OperationType.BaseExtrusion, DirectionType = Direction_Type.dtNormal, OperationColor = Color.Cornsilk }; sketchProperty.PointsList.Add(new PointF(-bodyWidth, 0)); sketchProperty.PointsList.Add(new PointF(-bodyWidth, -thickness)); sketchProperty.PointsList.Add(new PointF(30, -thickness)); sketchProperty.PointsList.Add(new PointF(30, 0)); sketchProperty.SketchName = "Подоконник"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = nightStandHeight; sketchProperty.PlaneDirectionUp = true; sketchProperty.NormalValue = thickness * 2; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF(-bodyWidth, 0)); sketchProperty.PointsList.Add(new PointF(-bodyWidth, -thickness * 2)); sketchProperty.PointsList.Add(new PointF(30, -thickness * 2)); sketchProperty.PointsList.Add(new PointF(30, 0)); sketchProperty.SketchName = "ПодоконникБортик"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion //Построение стекла в левой части - if (isCut != 1) { #region - Построение сечения - sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 5; sketchProperty.NormalValue = 30; sketchProperty.DirectionType = Direction_Type.dtBoth; sketchProperty.Operation = OperationType.BaseCutExtrusion; sketchProperty.PointsList.Add(new PointF(-bodyWidth, bodyHeight)); sketchProperty.PointsList.Add(new PointF(-bodyWidth, bodyHeight / 2)); sketchProperty.PointsList.Add(new PointF(30, bodyHeight / 2)); sketchProperty.PointsList.Add(new PointF(30, bodyHeight)); sketchProperty.SketchName = "Секущая"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Построение сечения - } } }
/// <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 }); }
/// <summary> /// Create rounded chamfers inside nut /// </summary> /// <param name="nutBasePoint">Nut base point</param> /// <param name="regPolyParam">Regular polygon parameters</param> /// <param name="nutBaseEntities">Nut base entities: sketch and extrusion</param> /// <returns>Chamfers entities from left and right sides of nut</returns> private ksEntity[] CreateNutChamferEntities(KompasPoint3D nutBasePoint, RegularPolygonParameter regPolyParam, ksEntity[] nutBaseEntities) { // 1.3 Nut rounded chamfers creation: // 1.3.1 Right rounded chamfer var rightChamferPoint = new KompasPoint2D(Math.Abs(nutBasePoint.Y), Math.Abs(nutBasePoint.Z)); // Nut width is equal to W3 (screw hat width) var rightChamferRegPoly = new RegularPolygonParameter(_kompasApp, 6, _kompasApp.Parameters[0] / 2.0, rightChamferPoint); if (rightChamferRegPoly == null) { LastErrorCode = rightChamferRegPoly.LastErrorCode; return(null); } var rightChamferSketch = new KompasSketch(_kompasApp.NutPart, nutBaseEntities[1]); if (rightChamferSketch.LastErrorCode != ErrorCodes.OK) { LastErrorCode = rightChamferSketch.LastErrorCode; return(null); } var rightChamferParameters = new RoundedChamferParameters(); rightChamferParameters.Document3DPart = _kompasApp.NutPart; rightChamferParameters.RegularPolygonSketch = rightChamferSketch.Entity; rightChamferParameters.RegularPolygonParameters = rightChamferRegPoly; rightChamferParameters.BasePlanePoint = rightChamferPoint; rightChamferParameters.Direction = Direction_Type.dtNormal; var rightChamferManager = new RoundedChamfer(_kompasApp, rightChamferParameters); if (!rightChamferManager.CreateDetail()) { LastErrorCode = rightChamferManager.LastErrorCode; return(null); } if (rightChamferManager.LastErrorCode != ErrorCodes.OK) { LastErrorCode = rightChamferManager.LastErrorCode; return(null); } var rightChamferEntity = rightChamferManager.Entity; if (rightChamferEntity == null) { LastErrorCode = rightChamferManager.LastErrorCode; return(null); } // 1.3.2 Left rounded chamfer var leftChamferParameters = new RoundedChamferParameters(); leftChamferParameters.Document3DPart = _kompasApp.NutPart; leftChamferParameters.RegularPolygonSketch = nutBaseEntities[0]; leftChamferParameters.RegularPolygonParameters = regPolyParam; leftChamferParameters.BasePlanePoint = new KompasPoint2D(nutBasePoint.Y, nutBasePoint.Z); leftChamferParameters.Direction = Direction_Type.dtNormal; var leftChamferManager = new RoundedChamfer(_kompasApp, leftChamferParameters); if (!leftChamferManager.CreateDetail()) { LastErrorCode = leftChamferManager.LastErrorCode; return(null); } if (leftChamferManager.LastErrorCode != ErrorCodes.OK) { LastErrorCode = leftChamferManager.LastErrorCode; return(null); } var leftChamferEntity = leftChamferManager.Entity; if (leftChamferEntity == null) { LastErrorCode = leftChamferManager.LastErrorCode; return(null); } return(new ksEntity[2] { leftChamferEntity, rightChamferEntity }); }
/// <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); }
/// <summary> /// Строит часть модели. /// </summary> /// <param name="document3D">3D документ.</param> /// <param name="parameters">Параметры модели.</param> public void Create(ksDocument3D document3D, Dictionary <Parameter, ParameterData> parameters) { var isShelfs = (int)parameters[Parameter.IsShelf].Value; var isHanger = (int)parameters[Parameter.IsHanger].Value; var GlassCount = parameters[Parameter.GlassCount].Value; // Ширина окна var bodyWidth = parameters[Parameter.BodyWidth].Value; // Ширина окна var bodyHeight = parameters[Parameter.BodyHeight].Value; // Высота окна var bodyLength = parameters[Parameter.BodyLength].Value; // Глубина окна var thickness = parameters[Parameter.WallThickness].Value; // Толщина стенки var additional = 0.5f; // Толщина рамки стопора if (isShelfs != 1) { var part = (ksPart)document3D.GetPart((short)Part_Type.pNew_Part); if (part != null) { var sketchProperty = new KompasSketch { Shape = ShapeType.Line, Plane = PlaneType.PlaneXOY, NormalValue = bodyLength, Operation = OperationType.BaseExtrusion, DirectionType = Direction_Type.dtNormal, OperationColor = Color.Cornsilk }; #region - Построение стекла в правой части - if (isHanger != 1) { if (GlassCount == 1) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional; sketchProperty.NormalValue = bodyLength - 3 * additional + 0.25f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Стекло правое"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } if (GlassCount == 2) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Стекло правое"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength - 0.3f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Стекло правое"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } if (GlassCount == 3) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Стекло правое"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength - 0.3f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Стекло правое"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional + bodyLength / 2 - 0.2f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Стекло правое"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } } else { if (GlassCount == 1) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = bodyLength - 2 * additional; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } if (GlassCount == 2) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength - additional - 0.15f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } if (GlassCount == 3) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength / 2 - 0.075f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength - additional - 0.15f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } } #endregion // Построение стекла в правой части #region - Построение стекла в левой части - if (GlassCount == 1) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = bodyLength - 2 * additional; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } if (GlassCount == 2) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength - additional - 0.15f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } if (GlassCount == 3) { sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength / 2 - 0.075f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.LightSkyBlue; sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength - additional - 0.15f; sketchProperty.NormalValue = 0.15f; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.SketchName = "Стекло"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); } #endregion // Построение стекла в левой части } } }
/// <summary> /// Строит часть модели. /// </summary> /// <param name="document3D">3D документ.</param> /// <param name="parameters">Параметры модели.</param> public void Create(ksDocument3D document3D, Dictionary <Parameter, ParameterData> parameters) { var OpenDirection = (int)parameters[Parameter.OpenDirection].Value; var bodyWidth = parameters[Parameter.BodyWidth].Value; // Ширина окна var bodyHeight = parameters[Parameter.BodyHeight].Value; // Высота окна var bodyLength = parameters[Parameter.BodyLength].Value; // Глубина окна var thickness = parameters[Parameter.WallThickness].Value; // Толщина стенки var additional = 0.5f; // Толщина рамки стопора var isHanger = (int)parameters[Parameter.IsHanger].Value; var part = (ksPart)document3D.GetPart((short)Part_Type.pNew_Part); if (part != null) { var sketchProperty = new KompasSketch { Shape = ShapeType.Line, Plane = PlaneType.PlaneXOY, NormalValue = bodyLength, Operation = OperationType.BaseExtrusion, DirectionType = Direction_Type.dtNormal, OperationColor = Color.Cornsilk }; if (isHanger != 1) { #region - Правая открывающаяся створка- sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = bodyLength - 0.4f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - thickness, bodyHeight - thickness - thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - thickness - thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, thickness + thickness)); sketchProperty.SketchName = "Створка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(30 - thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, thickness + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, thickness + thickness)); sketchProperty.SketchName = "Створка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Правая открывающаяся створка #region - Нахлёст на створку- sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = bodyLength + 0.1f; sketchProperty.NormalValue = 0.15f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * 2 * thickness + thickness + additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - 0.4f, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - 0.4f, bodyHeight - thickness + 0.4f)); sketchProperty.PointsList.Add(new PointF(30 - thickness + 0.4f, bodyHeight - thickness + 0.4f)); sketchProperty.PointsList.Add(new PointF(30 - thickness + 0.4f, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - thickness, bodyHeight - thickness - thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - thickness - thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, thickness + thickness)); sketchProperty.SketchName = "Створка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(30 - thickness + 0.4f, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - 0.4f, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - 0.4f, thickness + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness + 0.4f, thickness + thickness)); sketchProperty.SketchName = "Створка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Нахлёст на створку #region - Внешняя рамка для створки- sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = additional; sketchProperty.OperationColor = Color.DarkRed; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness + additional)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness + additional, 2 * thickness + additional)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness + additional, bodyHeight - 2 * thickness - additional)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness - additional, bodyHeight - 2 * thickness - additional)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness - additional, 2 * thickness + additional)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Рамка внешняя 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); // Первая точка для стекла sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness + additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * 2 * thickness, 2 * thickness + additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * 2 * thickness, 2 * thickness)); sketchProperty.SketchName = "Рамка внешняя 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Внешняя рамка для створки #region - Внешняя рамка для створки- sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional + bodyLength - 2 * additional + 0.25f; sketchProperty.NormalValue = additional; sketchProperty.OperationColor = Color.DarkRed; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, 2 * thickness + additional)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness + additional, 2 * thickness + additional)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness + additional, bodyHeight - 2 * thickness - additional)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness - additional, bodyHeight - 2 * thickness - additional)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness - additional, 2 * thickness + additional)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, bodyHeight - 2 * thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness, bodyHeight - 2 * thickness)); sketchProperty.SketchName = "Рамка внешняя 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness)); // Первая точка для стекла sketchProperty.PointsList.Add(new PointF(30 - 2 * thickness, 2 * thickness + additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * 2 * thickness, 2 * thickness + additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * 2 * thickness, 2 * thickness)); sketchProperty.SketchName = "Рамка внешняя 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Внешняя рамка для створки if (OpenDirection == 0) { #region - Построение ручки и навесов при правом открывании- sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = (2 * additional + bodyLength - 2 * additional + 0.25f); sketchProperty.NormalValue = 0.25f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 + 0.4f, bodyHeight / 2 + 0.7f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 + 0.4f, bodyHeight / 2 - 0.7f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 - 0.4f, bodyHeight / 2 - 0.7f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 - 0.4f, bodyHeight / 2 + 0.7f)); sketchProperty.SketchName = "Ручка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = (2 * additional + bodyLength - 2 * additional + 0.5f); sketchProperty.NormalValue = 0.5f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 + 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 + 0.3f, bodyHeight / 2 - 0.3f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 - 0.3f, bodyHeight / 2 - 0.3f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 - 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.SketchName = "Ручка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = (2 * additional + bodyLength - 2 * additional + 1); sketchProperty.NormalValue = 0.3f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 + 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 + 0.3f, bodyHeight / 2 - 3)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 - 0.3f, bodyHeight / 2 - 3)); sketchProperty.PointsList.Add( new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + thickness / 2 - 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.SketchName = "Ручка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); // Навесы sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional + bodyLength - 2 * additional + 0.1f; sketchProperty.NormalValue = 0.5f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f + 0.3f, bodyHeight - bodyHeight / 4 + 0.9f)); sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f + 0.3f, bodyHeight - bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f - 0.3f, bodyHeight - bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f - 0.3f, bodyHeight - bodyHeight / 4 + 0.9f)); sketchProperty.SketchName = "Навес 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional + bodyLength - 2 * additional + 0.1f; sketchProperty.NormalValue = 0.5f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f + 0.3f, 0 + bodyHeight / 4 + 0.9f)); sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f + 0.3f, 0 + bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f - 0.3f, 0 + bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF(30 - thickness / 2 - 0.5f - 0.3f, 0 + bodyHeight / 4 + 0.9f)); sketchProperty.SketchName = "Навес 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion } else { #region - Построение ручки и навесов при левом открывании- sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = (2 * additional + bodyLength - 2 * additional + 0.25f); sketchProperty.NormalValue = 0.25f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness + 0.4f, bodyHeight / 2 + 0.7f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness + 0.4f, bodyHeight / 2 - 0.7f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness - 0.4f, bodyHeight / 2 - 0.7f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness - 0.4f, bodyHeight / 2 + 0.7f)); sketchProperty.SketchName = "Ручка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = (2 * additional + bodyLength - 2 * additional + 0.5f); sketchProperty.NormalValue = 0.5f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness + 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness + 0.3f, bodyHeight / 2 - 0.3f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness - 0.3f, bodyHeight / 2 - 0.3f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness - 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.SketchName = "Ручка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = (2 * additional + bodyLength - 2 * additional + 1); sketchProperty.NormalValue = 0.3f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness + 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness + 0.3f, bodyHeight / 2 - 3)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness - 0.3f, bodyHeight / 2 - 3)); sketchProperty.PointsList.Add(new PointF(30 - 1.5f * thickness - 0.3f, bodyHeight / 2 + 0.3f)); sketchProperty.SketchName = "Ручка"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); // Навесы sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional + bodyLength - 2 * additional + 0.1f; sketchProperty.NormalValue = 0.5f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness + 0.3f, bodyHeight - bodyHeight / 4 + 0.9f)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness + 0.3f, bodyHeight - bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness - 0.3f, bodyHeight - bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness - 0.3f, bodyHeight - bodyHeight / 4 + 0.9f)); sketchProperty.SketchName = "Навес 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 2 * additional + bodyLength - 2 * additional + 0.1f; sketchProperty.NormalValue = 0.5f; sketchProperty.OperationColor = Color.Cornsilk; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness + 0.3f, 0 + bodyHeight / 4 + 0.9f)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness + 0.3f, 0 + bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness - 0.3f, 0 + bodyHeight / 4 - 0.9f)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.3f * thickness - 0.3f, 0 + bodyHeight / 4 + 0.9f)); sketchProperty.SketchName = "Навес 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion } } if (isHanger != 0) { #region - Построение внешнего бортика у правой половины - sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional + (bodyLength - 2 * additional); sketchProperty.NormalValue = additional; sketchProperty.PlaneDirectionUp = true; sketchProperty.OperationColor = Color.DarkRed; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + additional, thickness + additional)); sketchProperty.SketchName = "Рамка внешняя 9"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - additional, thickness + additional)); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, thickness + additional)); sketchProperty.SketchName = "Рамка внешняя 10"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Построение внешнего бортика у левой половины } } }
/// <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); }
/// <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); }
/// <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); }
/// <summary> /// Строит часть модели. /// </summary> /// <param name="document3D">3D документ.</param> /// <param name="parameters">Параметры модели.</param> public void Create(ksDocument3D document3D, Dictionary <Parameter, ParameterData> parameters) { var OpenDirection = (int)parameters[Parameter.OpenDirection].Value; var bodyWidth = parameters[Parameter.BodyWidth].Value; // Ширина окна var bodyHeight = parameters[Parameter.BodyHeight].Value; // Высота окна var bodyLength = parameters[Parameter.BodyLength].Value; // Глубина окна var thickness = parameters[Parameter.WallThickness].Value; // Толщина стенки var additional = 0.5f; // Толщина рамки стопора var isHanger = (int)parameters[Parameter.IsHanger].Value; var part = (ksPart)document3D.GetPart((short)Part_Type.pNew_Part); if (part != null) { var sketchProperty = new KompasSketch { Shape = ShapeType.Line, Plane = PlaneType.PlaneXOY, NormalValue = bodyLength, Operation = OperationType.BaseExtrusion, DirectionType = Direction_Type.dtNormal, OperationColor = Color.Cornsilk }; #region - Построение основоной рамы с одной перегородкой - sketchProperty.PointsList.Add(new PointF(-bodyWidth, 0)); sketchProperty.PointsList.Add(new PointF(-bodyWidth, bodyHeight)); sketchProperty.PointsList.Add(new PointF(30, bodyHeight)); sketchProperty.PointsList.Add(new PointF(30, 0)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0)); sketchProperty.SketchName = "Несущая конструкция 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0)); sketchProperty.SketchName = "Несущая конструкция 2"; sketchProperty.CreateNewSketch(part); #endregion // Построение основоной рамы с одной перегородкой #region - Построение внешнего бортика у левой половины - sketchProperty.PointsList.Clear(); sketchProperty.OperationColor = Color.DarkRed; sketchProperty.OffsetPlaneValue = additional; sketchProperty.NormalValue = additional; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness + additional)); sketchProperty.SketchName = "Рамка внешняя 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness + additional)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, thickness + additional)); sketchProperty.SketchName = "Рамка внешняя 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Построение внешнего бортика у левой половины #region - Построение внутренней рамки-стопора для стекла - sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = additional + (bodyLength - 2 * additional); sketchProperty.NormalValue = additional; sketchProperty.PlaneDirectionUp = true; sketchProperty.OperationColor = Color.DarkRed; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness + additional)); sketchProperty.SketchName = "Рамка внутренняя 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 - 0.5f * thickness - additional, thickness + additional)); sketchProperty.PointsList.Add(new PointF(-bodyWidth + thickness + additional, thickness + additional)); sketchProperty.SketchName = "Рамка внутренняя 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Построение внутренней рамки-стопора для стекла #region - Построение внешнего бортика у правой половины - sketchProperty.PointsList.Clear(); sketchProperty.IsOffsetPlane = true; sketchProperty.OffsetPlaneValue = 0; sketchProperty.NormalValue = additional; sketchProperty.OperationColor = Color.DarkRed; sketchProperty.PlaneDirectionUp = true; sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, bodyHeight - thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, 0 + thickness)); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + additional, bodyHeight - thickness - additional)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness + additional, thickness + additional)); sketchProperty.SketchName = "Рамка внешняя 1"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - additional, thickness)); sketchProperty.PointsList.Add(new PointF((30 - bodyWidth) / 2 + 0.5f * thickness - additional, thickness + additional)); sketchProperty.PointsList.Add(new PointF(30 - thickness - additional, thickness + additional)); sketchProperty.SketchName = "Рамка внешняя 2"; sketchProperty.CreateNewSketch(part); sketchProperty.PointsList.Clear(); #endregion // Построение внешнего бортика у левой половины } }