public void CreateSpout(ksPart iPart, KompasObject _kompas, TeaPotParams teaPotParams) { double spout = (teaPotParams.TeaPotDiameter / 5); double offset = teaPotParams.TeaPotHeight - spout * 1.5; double width = spout; // spoutWidth double height = spout; // spoutHeigth ksEntity iSketch; ksSketchDefinition iDefinitionSketch; CreateSketch(out iSketch, out iDefinitionSketch, offset); // Интерфейс для рисования = на скетче; ksDocument2D iDocument2D = (ksDocument2D)iDefinitionSketch.BeginEdit(); // Построить прямоугольник (x1,y1, x2,y2, style) ksRectangleParam par1 = (ksRectangleParam)_kompas.GetParamStruct((short)StructType2DEnum.ko_RectangleParam); par1.x = (teaPotParams.TeaPotDiameter / 2) - 5; par1.height = width; // spoutWidth. par1.y = -(par1.height / 2); par1.width = teaPotParams.TeaPotSpoutLength; //spoutLength par1.style = 1; // При нуле не видно деталь. iDocument2D.ksRectangle(par1); // Закончить редактировать эскиз iDefinitionSketch.EndEdit(); int X = Convert.ToInt32(teaPotParams.TeaPotHandleColor); ExctrusionSketch(iPart, iSketch, height, true, X); Fillet(iPart, 7, width / 2, teaPotParams); }
/// <summary> /// Создане выреза крепления /// </summary> /// <param name="diameterBracing">Диаметр крепления</param> /// <param name="lengthBracing">Длина крепления</param> /// <param name="lengthLeg">Длина ножки</param> /// <param name="lengthHead">Длина головки</param> private void BuildBracingCut(double diameterBracing, double lengthBracing, double lengthLeg, double lengthHead) { #region Константы для выреза крепления const int part = -1; const int sketch = 5; const int planeXOY = 1; const int planeOffset = 14; const int rectangleParam = 91; const int shaded = 3; const int etBlind = 0; const int cutExtrusion = 26; #endregion _part = _doc3D.GetPart(part); ksEntity EntityPlane = _part.GetDefaultEntity(planeXOY); //Смещение плоскости ksEntity PlaneOffSet = _part.NewEntity(planeOffset); ksPlaneOffsetDefinition planeOffDefinition = PlaneOffSet.GetDefinition(); planeOffDefinition.direction = true; planeOffDefinition.offset = lengthLeg + lengthHead + lengthBracing; planeOffDefinition.SetPlane(EntityPlane); PlaneOffSet.Create(); //Эскиз ksEntity EntityRectangle = _part.NewEntity(sketch); ksSketchDefinition sketchDefinitionRectangle = EntityRectangle.GetDefinition(); sketchDefinitionRectangle.SetPlane(PlaneOffSet); EntityRectangle.Create(); ksDocument2D Document2 = sketchDefinitionRectangle.BeginEdit(); ksRectangleParam _par; _par = _kompas.GetParamStruct(rectangleParam); _par.height = diameterBracing / 2; _par.width = diameterBracing; _par.x = -(diameterBracing / 2); _par.y = -(diameterBracing / 4); _par.ang = 0; _par.style = 1; Document2.ksRectangle(_par, 0); sketchDefinitionRectangle.EndEdit(); //Вырезание ksEntity EntityCutExtrusion = _part.NewEntity(cutExtrusion); ksCutExtrusionDefinition CutExtrusionDefinition = EntityCutExtrusion.GetDefinition(); CutExtrusionDefinition.cut = true; CutExtrusionDefinition.directionType = 0; CutExtrusionDefinition.SetSideParam(true, etBlind, lengthBracing / 2, 0, false); CutExtrusionDefinition.SetSketch(EntityRectangle); EntityCutExtrusion.Create(); _doc3D.drawMode = shaded; _doc3D.shadedWireframe = true; }
/// <summary> /// Рисование прямоугольника /// </summary> /// <param name="doc2D"></param> /// <param name="xStart"></param> /// <param name="yStart"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="ang"></param> private void DrawRectangle(ksDocument2D doc2D, double xStart, double yStart, double width, double height, double?ang) { var param = (ksRectangleParam)Kompas3D.GetParamStruct((short) StructType2DEnum.ko_RectangleParam); param.x = xStart; param.y = yStart; param.width = width; param.height = height; if (ang != null) { param.ang = (double)ang; } param.style = 1; doc2D.ksRectangle(param); }
// Работа с документом private void WorkDocument() { doc = (ksDocument2D)kompas.Document2D(); ksDocumentParam docPar = (ksDocumentParam)kompas.GetParamStruct((short)StructType2DEnum.ko_DocumentParam); ksDocumentParam docPar1 = (ksDocumentParam)kompas.GetParamStruct((short)StructType2DEnum.ko_DocumentParam); if ((docPar != null) & (docPar1 != null)) { /*docPar.fileName = @"c:\2.cdw"; * docPar.comment = "Create document"; * docPar.author = "User";*/ docPar.regime = 0; docPar.type = (short)DocType.lt_DocFragment; /*ksSheetPar shPar = (ksSheetPar)docPar.GetLayoutParam(); * if (shPar != null) * { * shPar.shtType = 1; * shPar.layoutName = string.Empty; * ksStandartSheet stPar = (ksStandartSheet)shPar.GetSheetParam(); * }*/ // Создали документ: лист, формат А4, горизонтально расположенный // и с системным штампом 1 doc.ksCreateDocument(docPar); //int number = 0; ksViewParam par = (ksViewParam)kompas.GetParamStruct((short)StructType2DEnum.ko_ViewParam); ksRectangleParam par1 = (ksRectangleParam)kompas.GetParamStruct((short)StructType2DEnum.ko_RectangleParam); if (par != null) { /*number = 2; * par.Init(); * par.x = 0; * par.y = 0; * //par.scale_ = 0.5; * //par.angle = 45; * par.color = Color.FromArgb(10, 20, 10).ToArgb(); * par.state = ldefin2d.stACTIVE; * //par.name = "User view"; * // У документа создадим вид с номером 2, масштабом 0.5, под углом 45 гр * doc.ksCreateSheetView(par, ref number); * * // Создадим слой с номером 5 * //doc.ksLayer(5);*/ par1.x = 0; par1.y = 0; par1.height = 100; par1.width = 200; doc.ksRectangle(par1); doc.ksLineSeg(20, 10, 40, 10, 1); doc.ksLineSeg(40, 10, 40, 30, 1); doc.ksLineSeg(40, 30, 20, 30, 1); doc.ksLineSeg(20, 30, 20, 10, 1); /*kompas.ksMessage("Нарисовали"); * * Получить параметры документа * doc.ksGetObjParam(doc.reference, docPar1, ldefin2d.ALLPARAM); * ksSheetPar shPar1 = (ksSheetPar)docPar1.GetLayoutParam(); * if (shPar1 != null) * { * ksStandartSheet stPar1 = (ksStandartSheet)shPar.GetSheetParam(); * if (stPar1 != null) * { * short direct = 0; * if (stPar1.direct) * direct = 1; * string buf = string.Format("Type = {0}, f = {1}, m = {2}, d = {3}", docPar1.type, stPar1.format, stPar1.multiply, direct); * kompas.ksMessage(buf); * } * } * * kompas.ksMessage(docPar1.fileName); * kompas.ksMessage(docPar1.comment); * kompas.ksMessage(docPar1.author); * * // Cохраним документ * doc.ksSaveDocument(string.Empty); * //Закрыть документ * doc.ksCloseDocument();*/ } } }
public void CreateHandle(ksPart iPart, KompasObject _kompas, TeaPotParams teaPotParams) { double spout = (teaPotParams.TeaPotDiameter / 5); double offset = teaPotParams.TeaPotHeight - spout * 1.5; // Offset double width = spout; // spoutWidth double height = spout; // spoutHeigth ksEntity iSketch; ksSketchDefinition iDefinitionSketch; CreateSketch(out iSketch, out iDefinitionSketch, offset); // Интерфейс для рисования = на скетче; ksDocument2D iDocument2D = (ksDocument2D)iDefinitionSketch.BeginEdit(); // Построить прямоугольник (x1,y1, x2,y2, style) ksRectangleParam par2 = (ksRectangleParam)_kompas.GetParamStruct((short)StructType2DEnum.ko_RectangleParam); par2.width = 40; //spoutLength par2.height = width; // spoutWidth. par2.x = -(teaPotParams.TeaPotDiameter / 2) - 10 - (par2.width / 2); par2.y = -(par2.height / 2); par2.style = 1; // При нуле не видно деталь. iDocument2D.ksRectangle(par2); // Закончить редактировать эскиз iDefinitionSketch.EndEdit(); int X = Convert.ToInt32(teaPotParams.TeaPotHandleColor); ExctrusionSketch(iPart, iSketch, height, true, X); //PART 2 double offset2 = teaPotParams.TeaPotHeight - teaPotParams.TeaPotHandleSize; // Offset 25 double width2 = spout; // spoutWidth double height2 = teaPotParams.TeaPotHeight - offset2 - spout / 2; // spoutHeigth ksEntity iSketch2; ksSketchDefinition iDefinitionSketch2; CreateSketch(out iSketch2, out iDefinitionSketch2, offset2); // Интерфейс для рисования = на скетче; ksDocument2D iDocument2D2 = (ksDocument2D)iDefinitionSketch2.BeginEdit(); // Построить прямоугольник (x1,y1, x2,y2, style) ksRectangleParam par3 = (ksRectangleParam)_kompas.GetParamStruct((short)StructType2DEnum.ko_RectangleParam); par3.width = spout; //spoutLength par3.height = width2; // spoutWidth. par3.x = -(teaPotParams.TeaPotDiameter / 2) - 10 - par3.width - (par3.width / 2); par3.y = -(par3.height / 2); par3.style = 1; // При нуле не видно деталь. iDocument2D2.ksRectangle(par3); // Закончить редактировать эскиз iDefinitionSketch2.EndEdit(); int X1 = Convert.ToInt32(teaPotParams.TeaPotHandleColor); ExctrusionSketch(iPart, iSketch2, height2, true, X1); Fillet(iPart, 10, spout / 4, teaPotParams); Fillet(iPart, 11, spout / 4, teaPotParams); Fillet(iPart, 12, 0.1, teaPotParams); Fillet(iPart, 13, spout / 2, teaPotParams); Fillet(iPart, 14, spout / 2, teaPotParams); }