/// <summary> /// ремешок с перфорацие /// </summary> /// <param name="WatchData">информация о часах</param> /// <returns>Модель часов</returns> public Solid3d BuildStrapWithPerforations(WatchData WatchData) { //модель ремешка с перфор. Solid3d StrapWithPerforations = new Solid3d(); StrapWithPerforations.CreateBox(Length / 2, Width, 3); //сглаживаем углы. Solid3d StrapSmoother = new Solid3d(); StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]); StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(Length / 4, 0, 0))); StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d); StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]); StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(-Length / 4, 0, 0))); StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d); //проделываем перфорации Solid3d HoleMaker = new Solid3d(); for (int i = 0; i < NumberOfPerforations; i++) { HoleMaker.CreateFrustum(3, PerforationRadius, PerforationRadius, PerforationRadius); HoleMaker.TransformBy(Matrix3d.Displacement(new Vector3d((Length / 4 - 10) - (Length / 3) / NumberOfPerforations * i, 0, 0))); StrapWithPerforations.BooleanOperation(BooleanOperationType.BoolSubtract, HoleMaker.Clone() as Solid3d); } StrapWithPerforations.TransformBy(Matrix3d.Displacement(new Vector3d(WatchData.BodyDiameter + WatchData.BootstrapLength + (Length / 4) - 0.5, 0, 0))); return(StrapWithPerforations); }
// 由布尔操作类型和两个三维实体创建旋转体的函数. public static void AddBoolSolid(BooleanOperationType boolType, ObjectId solid3dId1, ObjectId solid3dId2) { Database db = HostApplicationServices.WorkingDatabase; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { Entity ent1 = (Entity)trans.GetObject(solid3dId1, OpenMode.ForWrite); Entity ent2 = (Entity)trans.GetObject(solid3dId2, OpenMode.ForWrite); if (ent1 is Solid3d & ent2 is Solid3d) { Solid3d solid3dEnt1 = (Solid3d)ent1; Solid3d solid3dEnt2 = (Solid3d)ent2; solid3dEnt1.BooleanOperation(boolType, solid3dEnt2); ent2.Erase(); } if (ent1 is Region & ent2 is Region) { Region regionEnt1 = (Region)ent1; Region regionEnt2 = (Region)ent2; regionEnt1.BooleanOperation(boolType, regionEnt2); ent2.Erase(); } } catch { // 此处无需要操作. } trans.Commit(); } }
/// <summary> /// ремешок с замком /// </summary> /// <param name="WatchData">информация о часах</param> /// <returns>модель ремешка</returns> public Solid3d BuildStrapWithLocker(WatchData WatchData) { //модель ремешка с замком Solid3d StrapWithLocker = new Solid3d(); StrapWithLocker.CreateBox(Length / _params[ParNames.StrapTransformByX], Width, 3); //сглаживания ремешка Solid3d StrapSmoother = new Solid3d(); StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByY]); StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.StrapTransformByX], new Vector3d(1, 0, 0), Point3d.Origin)); StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(Length / 4, 0, 0))); StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d); StrapSmoother.CreateFrustum(Width, _params[ParNames.StrapTransformByY], _params[ParNames.StrapTransformByX], _params[ParNames.StrapTransformByY]); StrapSmoother.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.StrapTransformByX], new Vector3d(1, 0, 0), Point3d.Origin)); StrapSmoother.TransformBy(Matrix3d.Displacement(new Vector3d(-Length / 4, 0, 0))); StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, StrapSmoother.Clone() as Solid3d); //замок ремешка Solid3d Locker = new Solid3d(); Locker.CreateBox(20, Width + _params[ParNames.StrapTransformByX], 4); Solid3d LockerHole = new Solid3d(); LockerHole.CreateBox(18, Width, 4); LockerHole.TransformBy(Matrix3d.Displacement(new Vector3d(4, 0, 0))); Locker.BooleanOperation(BooleanOperationType.BoolSubtract, LockerHole.Clone() as Solid3d); //Дерджатель на замке Solid3d LockerPin = new Solid3d(); LockerPin.CreateBox(20, WatchData.StrapPerforationRadius, _params[ParNames.StrapTransformByX]); Locker.BooleanOperation(BooleanOperationType.BoolUnite, LockerPin.Clone() as Solid3d); //передвигаем ремешок Locker.TransformBy(Matrix3d.Displacement(new Vector3d((-Length / 4) - 5, 0, 0))); StrapWithLocker.BooleanOperation(BooleanOperationType.BoolUnite, Locker.Clone() as Solid3d); StrapWithLocker.TransformBy(Matrix3d.Displacement(new Vector3d(-(WatchData.BodyDiameter + WatchData.BootstrapLength + (Length / 4) - 0.5), 0, 0))); //возвращаем модель ремешка return(StrapWithLocker); }
/// <summary> /// Построить 3д солид-модель /// </summary> /// <param name="WatchData">Параметры часов</param> /// <returns>3Д - солид модель</returns> public Solid3d BuildCrown(WatchData WatchData) { //заводная головка Solid3d CrownPart = new Solid3d(); CrownPart.CreateFrustum(Height, Diameter, Diameter, Diameter); //низ заводной головки Solid3d CrownBottom = new Solid3d(); CrownBottom.CreateFrustum(1, Diameter, Diameter, Diameter - _pararameters[ParNames.CrownBottomHeight]); CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _pararameters[ParNames.CrownTransformByZ] + _pararameters[ParNames.CrownTopHeight]) - Point3d.Origin)); CrownPart.BooleanOperation(BooleanOperationType.BoolUnite, CrownBottom.Clone() as Solid3d); //вверх зав.головки Solid3d CrownTop = new Solid3d(); CrownBottom.CreateFrustum(_pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter); CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -Height / _pararameters[ParNames.CrownTransformByZ] - 0.25) - Point3d.Origin)); CrownPart.BooleanOperation(BooleanOperationType.BoolUnite, CrownBottom.Clone() as Solid3d); CrownBottom.CreateFrustum(_pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - _pararameters[ParNames.CrownTopHeight], Diameter - 1); CrownBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -Height / _pararameters[ParNames.CrownTransformByZ] - _pararameters[ParNames.CrownTopHeight]) - Point3d.Origin)); CrownPart.BooleanOperation(BooleanOperationType.BoolSubtract, CrownBottom.Clone() as Solid3d); //вырезаем цилиндры по радиусу зав. головки Solid3d CrownCutter = new Solid3d(); CrownCutter.CreateFrustum(Height + _pararameters[ParNames.CrownBottomHeight], Diameter / _pararameters[ParNames.CrownCutterCount], Diameter / _pararameters[ParNames.CrownCutterCount], Diameter / _pararameters[ParNames.CrownCutterCount]); for (int i = 0; i < _pararameters[ParNames.CrownCutterCylinder]; i++) { CrownCutter.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter * Math.Cos(Math.PI / 12 * i), Diameter * Math.Sin(Math.PI / 12 * i), 0))); CrownPart.BooleanOperation(BooleanOperationType.BoolSubtract, CrownCutter.Clone() as Solid3d); CrownCutter.TransformBy(Matrix3d.Displacement(new Vector3d(-Diameter * Math.Cos(Math.PI / 12 * i), -Diameter * Math.Sin(Math.PI / 12 * i), 0))); } CrownPart.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); CrownPart.TransformBy(Matrix3d.Displacement(new Vector3d(0, WatchData.BodyDiameter + Height / _pararameters[ParNames.CrownTransformByZ] + _pararameters[ParNames.CrownBottomHeight], 0))); return(CrownPart); }
public void CreateBoolSolid() { // 在内存中创建旋转截面对象. Solid3d ent1 = new Solid3d(); Solid3d ent2 = new Solid3d(); ent1.CreateBox(100, 60, 40); ent2.CreateFrustum(90, 20, 20, 20); // 差集操作. ent1.BooleanOperation(BooleanOperationType.BoolSubtract, ent2); ModelSpace.AppendEntity(ent1); }
/// <summary> /// Строим стрелки /// </summary> /// <param name="WatchData">Информация о часах</param> /// <returns>модель стрелок</returns> private Solid3d BuildArrows(WatchData WatchData) { //стрелки Solid3d Arrows = new Solid3d(); //база Solid3d Base = new Solid3d(); //первая часть базы Base.CreateFrustum(_params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByZ], _params[ParNames.BodyTransformByZ], _params[ParNames.BodyTransformByZ]); Base.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4))); Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Base.Clone() as Solid3d); //вторая часть бызы Base.CreateFrustum(_params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByY]); Base.TransformBy(Matrix3d.Displacement(new Vector3d(0, 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4 * 3))); Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Base.Clone() as Solid3d); //часовая стрелка Solid3d Arrow = new Solid3d(); Arrow.CreateBox(Diameter / 2, _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / 4); Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / 4), 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4))); double TrueHour = System.DateTime.Now.Hour + ((double)System.DateTime.Now.Minute / 60); Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 6 * TrueHour), new Vector3d(0, 0, 1), Point3d.Origin)); Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d); //минутная стрелка Arrow.CreateBox(Diameter / 2 + _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTransformByX] + _params[ParNames.BodyTransformByX] / 5, _params[ParNames.BodyTransformByX] / 5); Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / 4), 0, Height / 2 + _params[ParNames.BodyTransformByX] / 4 * 3))); Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 30 * System.DateTime.Now.Minute), new Vector3d(0, 0, 1), Point3d.Origin)); Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d); //секундная стрелка Arrow.CreateBox(Diameter / 2 + _params[ParNames.BodyBottomHeight], _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 5); Arrow.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter / _params[ParNames.BodyTopTransformByX]), 0, Height / 2 + _params[ParNames.BodyTransformByX] + _params[ParNames.BodyTransformByX] / 10))); Arrow.TransformBy(Matrix3d.Rotation(-(Math.PI / 30 * System.DateTime.Now.Second), new Vector3d(0, 0, 1), Point3d.Origin)); Arrows.BooleanOperation(BooleanOperationType.BoolUnite, Arrow.Clone() as Solid3d); return(Arrows); }
/// <summary> /// 由布尔操作函数创建三维实体 /// </summary> /// <param name="boolType">布尔操作类型</param> /// <param name="solid3dId1">参与操作的三维实体的Id</param> /// <param name="solid3dId2">参与操作的三维实体的Id</param> /// <returns>返回创建的三维实体的Id</returns> public static bool BoolSolid3dRegion(BooleanOperationType boolType, ObjectId solid3dId1, ObjectId solid3dId2) { Database db = HostApplicationServices.WorkingDatabase; Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { Entity ent1 = trans.GetObject(solid3dId1, OpenMode.ForWrite) as Entity; Entity ent2 = trans.GetObject(solid3dId2, OpenMode.ForWrite) as Entity; if (ent1 == null || ent2 == null) { ed.WriteMessage("\n布尔操作失败!"); return(false); } if (ent1 is Solid3d & ent2 is Solid3d) { Solid3d solid3dEnt1 = (Solid3d)ent1; Solid3d solid3dEnt2 = (Solid3d)ent2; solid3dEnt1.BooleanOperation(boolType, solid3dEnt2); ent2.Dispose(); } if (ent1 is Region & ent2 is Region) { Region regionEnt1 = (Region)ent1; Region regionEnt2 = (Region)ent2; regionEnt1.BooleanOperation(boolType, regionEnt2); ent2.Dispose(); } } catch { ed.WriteMessage("\n布尔操作失败!"); return(false); } trans.Commit(); return(true); } }
/// <summary> /// Функция отрисовки портов вывода /// </summary> /// <param name="database">База данныйх</param> /// <param name="Trans">Транцакция</param> /// <param name="parameters">Класс с параметрами построения мотора</param> /// <param name="positionPort">Позиция отверстия</param> /// <param name="Figure">Обьект класса</param> /// <param name="x">Позиция центра по координате Х</param> /// <param name="y">Позиция центра по координате Y</param> /// <param name="z">Позиция центра по координате Z</param> private void Ports(Database database, Transaction trans, MotorParameters parameters, int positionPort, Solid3d figure, double x, double y, double z) { // Открываем таблицу блоков для чтения BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; // Открываем таблицу блоков модели для записи BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Создаем 3D обьект - прямоугольник Solid3d port = new Solid3d(); port.SetDatabaseDefaults(); port.CreateFrustum(_widthFindings * (parameters.CountPorts - positionPort), _diameretPorts / 2, _diameretPorts / 2, _diameretPorts / 2); port.ColorIndex = 4; // Перемещение и и поворот port.TransformBy(Matrix3d.Displacement(new Point3d(x, y, z) - Point3d.Origin)); Vector3d vRotPort = new Point3d(0, 0, 0).GetVectorTo(new Point3d(0, 1, 0)); port.TransformBy(Matrix3d.Rotation(Math.PI / 2, vRotPort, new Point3d(x, y, z))); blockTableRecord.AppendEntity(port); trans.AddNewlyCreatedDBObject(port, true); figure.BooleanOperation(BooleanOperationType.BoolSubtract, port); }
/// <summary> /// Функция построения коробки выводов /// </summary> /// <param name="database">База данный объектов </param> /// <param name="Trans">Транзакции</param> /// <param name="parameters">Класс с параметрами построения мотора</param> public void Build(Database database, Transaction trans, MotorParameters parameters) { int widthFindings = _widthFindings; int lenFindings = _lenFindings; int heightFindings = _heightFindings; int countPorts = _countPorts; int diameretPorts = _diameretPorts; int lenBox = parameters.LenBox; int diameretBox = parameters.DiameretBox; // Коэффициенты трансформации double transformationFactorLen = 1.2; double transformationFactorHeight = 0.1; // Открываем таблицу блоков для чтения BlockTable blockTable = trans.GetObject(database.BlockTableId, OpenMode.ForRead) as BlockTable; // Открываем таблицу блоков модели для записи BlockTableRecord blockTableRecord = trans.GetObject(blockTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Создаем 3D обьект - прямоугольник Solid3d findings = new Solid3d(); findings.SetDatabaseDefaults(); findings.CreateBox(widthFindings, lenFindings, heightFindings); findings.ColorIndex = 7; // Задаем позицию центра 3D обьекта findings.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 + transformationFactorLen * lenFindings / 2, diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings) - Point3d.Origin)); // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию blockTableRecord.AppendEntity(findings); trans.AddNewlyCreatedDBObject(findings, true); // Параметры double cavityWidth = widthFindings * 0.8; double cavityLen = lenFindings * 0.9; double cavityHeight = heightFindings * 0.8; // Создать новую фигуру Solid3d cavity = new Solid3d(); cavity.SetDatabaseDefaults(); cavity.CreateBox(cavityWidth, cavityLen, cavityHeight); cavity.TransformBy(Matrix3d.Displacement(new Point3d(0, -lenBox / 2 + transformationFactorLen * lenFindings / 2, diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings) - Point3d.Origin)); // Добавляем новый обьект в таблицу блоков и отправляем на транзакцию blockTableRecord.AppendEntity(cavity); trans.AddNewlyCreatedDBObject(cavity, true); findings.BooleanOperation(BooleanOperationType.BoolSubtract, cavity); double coordZ = diameretBox / 2 + heightFindings / 2 - transformationFactorHeight * heightFindings; double coordX = widthFindings / 3; if (countPorts >= 1) { double y1 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2 + lenFindings / 3); Ports(database, trans, parameters, 0, findings, coordX, y1, coordZ); } if (countPorts > 2) { double y2 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2); Ports(database, trans, parameters, 2, findings, coordX, y2, coordZ); } if (countPorts > 4) { double y3 = -lenBox / 2 + (transformationFactorLen * lenFindings / 2 - lenFindings / 3); Ports(database, trans, parameters, 4, findings, -coordX, y3, coordZ); } }
// draw the 3-D drawing // nFlag: dimension control private void DrawSolidProfile(Plate pl, Point3d p0, int nFlag) { // Create Container for the curve, the region (face) DBObjectCollection curves = new DBObjectCollection(); // - Collection for the regions DBObjectCollection regions = new DBObjectCollection(); // Solid3d objects Solid3d plateSolid = new Solid3d(); Solid3d rectHole = new Solid3d(); // Rectangular Hole in the Center Point3d[] pt = new Point3d[26]; // geometry helpers Line[] ln = new Line[26]; // database objects // create points pt[0] = p0; pt[1] = new Point3d(p0.X + (pl.dW - pl.R1), p0.Y, p0.Z); pt[2] = new Point3d(p0.X + pl.dW, pl.R1, p0.Z); pt[3] = new Point3d(pt[1].X, pt[2].Y, p0.Z); pt[4] = new Point3d(pt[3].X, pt[3].Y + pl.L9, p0.Z); pt[5] = new Point3d(pt[4].X + pl.L2, pt[4].Y + pl.L8, p0.Z); pt[6] = new Point3d(pt[5].X, pt[5].Y + pl.L7, p0.Z); pt[7] = new Point3d(pt[4].X, pt[6].Y + pl.L6, p0.Z); pt[8] = new Point3d(pt[7].X, pt[7].Y + pl.L5, p0.Z); pt[9] = new Point3d(p0.X + pl.L3, pt[8].Y + pl.L4, p0.Z); pt[10] = new Point3d(p0.X, pt[9].Y, p0.Z); // symmetry - create points on negative x-axis int k = 9; for (int i = 11; i < 20; i++) { pt[i] = new Point3d(-pt[k].X, pt[k].Y, pt[k].Z); k--; } // create lines and store them into the database for (int i = 0; i < 20; i++) { if (i != 1 & i != 18) { ln[i] = new Line(pt[i], pt[(i + 1)]); ln[i].ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(ln[i]); } else if (i == 1) { double st_angle0 = 270 * (Math.PI / 180); double end_angle0 = 0; Arc a0 = new Arc(pt[3], pl.R1, st_angle0, end_angle0); a0.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a0); } else if (i == 18) { double st_angle1 = 180 * (Math.PI / 180); double end_angle1 = 270 * (Math.PI / 180); Arc a1 = new Arc(pt[17], pl.R1, st_angle1, end_angle1); a1.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a1); } else { continue; } } // Create the Region from the curves regions = Region.CreateFromCurves(curves); plateSolid.ColorIndex = pl.nColor[CONTOUR]; // Create the plate without the hole plateSolid.Extrude((Region)regions[0], pl.dT, 0.0); // draw points for centre hole curves.Clear(); pt[20] = new Point3d(p0.X + pl.R2, pt[3].Y + pl.R2, 0.0); pt[21] = new Point3d(pt[20].X, pt[7].Y - pl.R2, 0.0); pt[22] = new Point3d(-pt[20].X, pt[7].Y - pl.R2, 0.0); pt[23] = new Point3d(-(p0.X + pl.R2), pt[3].Y + pl.R2, 0.0); pt[24] = new Point3d(p0.X, pt[20].Y, 0.0); pt[25] = new Point3d(p0.X, pt[21].Y, 0.0); // draw lines for centre hole for (int i = 20; i < 24; i++) { if (i != 21 & i != 23) { ln[i] = new Line(pt[i], pt[(i + 1)]); ln[i].ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(ln[i]); } else if (i == 21) { double st_angle2 = 0; double end_angle2 = 180 * (Math.PI / 180); Arc a2 = new Arc(pt[25], pl.R2, st_angle2, end_angle2); a2.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a2); } else if (i == 23) { double st_angle3 = 180 * (Math.PI / 180); double end_angle3 = 0; Arc a3 = new Arc(pt[24], pl.R2, st_angle3, end_angle3); a3.ColorIndex = pl.nColor[CONTOUR]; // 0:index curves.Add(a3); } else { continue; } } // Create the Region from the curves (Rectangular Hole) regions = Region.CreateFromCurves(curves); rectHole.Extrude((Region)regions[0], pl.dT, 0.0); rectHole.ColorIndex = pl.nColor[HIDDEN]; // Substract the Hole Solid from the Rectangle plateSolid.BooleanOperation(BooleanOperationType.BoolSubtract, rectHole); // Add Solids into the Database AcTrans.Add(plateSolid); }
public void KojtoCAD_3D_TrimPick_up_tr_() { if (container.Triangles.Count > 0) { Pair <int, PromptStatus> pa = GlobalFunctions.GetInt(1, "\ntriangle numer:"); if ((pa.Second != PromptStatus.OK) || (pa.First < 1)) { return; } int num = pa.First - 1; Triangle TR = container.Triangles[num]; Pair <int, PromptStatus> pa1 = GlobalFunctions.GetInt(1, "\nNode numer:"); if ((pa1.Second != PromptStatus.OK) || (pa1.First < 1)) { return; } double x1 = 65.0; Pair <double, PromptStatus> pa2 = GlobalFunctions.GetDouble(x1, "\ndistance:"); if (pa2.Second != PromptStatus.OK) { return; } x1 = pa2.First; //foreach (WorkClasses.Triangle TR in container.Triangles) { int[] nodes = TR.GetNodesNumers(); List <int> temp = new List <int>(); if (nodes[0] != (pa1.First - 1)) { temp.Add(nodes[0]); } if (nodes[1] != (pa1.First - 1)) { temp.Add(nodes[1]); } if (nodes[2] != (pa1.First - 1)) { temp.Add(nodes[2]); } if (temp.Count != 2) { MessageBox.Show("Node E R R O R !", "E R R O R"); return; } //quaternion Q0 = container.Nodes[nodes[0]].Position; quaternion Q0 = container.Nodes[pa1.First - 1].Position; quaternion Q1 = container.Nodes[temp[0]].Position; quaternion Q2 = container.Nodes[temp[1]].Position; double[] angles = new double[3]; double[] anglesDegree = new double[3]; angles[0] = (Q1 - Q0).angTo(Q2 - Q0); anglesDegree[0] = angles[0] * 180.0 / Math.PI; List <ObjectId> ids = new List <ObjectId>(); ids.Add(TrimPickUP(pa1.First - 1, TR.GetNumer(), x1, anglesDegree[0])); if (ids.Count > 0) { using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { Solid3d ent = tr.GetObject(GlobalFunctions.GetObjectId(TR.upSolidHandle.Second), OpenMode.ForWrite) as Solid3d; try { Solid3d sol = tr.GetObject(ids[0], OpenMode.ForWrite) as Solid3d; for (int i = 1; i < ids.Count; i++) { Solid3d sol_i = tr.GetObject(ids[i], OpenMode.ForWrite) as Solid3d; sol.BooleanOperation(BooleanOperationType.BoolUnite, sol_i); } ent.BooleanOperation(BooleanOperationType.BoolSubtract, sol); } catch { } tr.Commit(); } } } } else { MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void MyCommand() { if (!this.ShowDialog()) { return; } double num1 = 1.0; double num2 = 0.25; double num3 = this.m * (double)this.z; double da = (2.0 * num1 + (double)this.z) * this.m; double df = ((double)this.z - 2.0 * num1 - 2.0 * num2) * this.m; double db = num3 * Math.Cos(this.a * Math.PI / 180.0); Point3d point = this.GetPoint(); DateTime now1 = DateTime.Now; Circle circle1 = new Circle(point, Vector3d.get_ZAxis(), db / 2.0); Circle cir1 = new Circle(point, Vector3d.get_ZAxis(), da / 2.0); Circle circle2 = new Circle(point, Vector3d.get_ZAxis(), df / 2.0); Circle pitchCircle = new Circle(point, Vector3d.get_ZAxis(), num3 / 2.0); Point3dCollection point3dCollection = new Point3dCollection(); Polyline3d evolent1 = this.CreatEvolent(point, da, db, cir1); Polyline3d evolent2 = this.MirrorEvolent(evolent1, pitchCircle, point); Arc arc = this.CreatArc(point, evolent1, evolent2); Line line1 = new Line(point, ((Curve)evolent1).get_StartPoint()); Line line2 = new Line(point, ((Curve)evolent2).get_StartPoint()); DBObjectCollection objectCollection1 = new DBObjectCollection(); objectCollection1.Add((DBObject)evolent1); objectCollection1.Add((DBObject)evolent2); objectCollection1.Add((DBObject)line2); objectCollection1.Add((DBObject)line1); objectCollection1.Add((DBObject)arc); DBObjectCollection objectCollection2 = new DBObjectCollection(); Entity[] entityArray = this.ArrayPolar((Entity)(Region.CreateFromCurves(objectCollection1).get_Item(0) as Region), point, this.z, 2.0 * Math.PI); objectCollection1.Clear(); objectCollection1.Add((DBObject)circle2); Region region1 = Region.CreateFromCurves(objectCollection1).get_Item(0) as Region; foreach (Entity entity in entityArray) { Region region2 = entity as Region; if (DisposableWrapper.op_Inequality((DisposableWrapper)region2, (DisposableWrapper)null)) { region1.BooleanOperation((BooleanOperationType)0, region2); } } objectCollection1.Clear(); Circle circle3 = new Circle(point, Vector3d.get_ZAxis(), 0.15 * (df - 10.0)); objectCollection1.Add((DBObject)circle3); DBObjectCollection fromCurves = Region.CreateFromCurves(objectCollection1); region1.BooleanOperation((BooleanOperationType)2, fromCurves.get_Item(0) as Region); Solid3d solid3d = new Solid3d(); solid3d.Extrude(region1, this.h, 0.0); solid3d.BooleanOperation((BooleanOperationType)2, this.NewBox(point, this.h, df)); if (this.doDemo == "Y") { this.AddEntityToModelSpace((Entity)evolent1); this.AddEntityToModelSpace((Entity)evolent2); this.AddEntityToModelSpace((Entity)arc); this.AddEntityToModelSpace((Entity)line1); this.AddEntityToModelSpace((Entity)line2); this.AddEntityToModelSpace((Entity)(((RXObject)region1).Clone() as Region)); Thread.Sleep(this.delay * 5); } this.ZoomToEntity((Entity)solid3d); this.AddEntityToModelSpace((Entity)solid3d); DateTime now2 = DateTime.Now; this.ed.WriteMessage("\n耗时{0}。", new object[1] { (object)this.Elapsed(now1, now2) }); }
/// <summary> /// Построить модель корпуса /// </summary> /// <param name="WatchData">параметры часов</param> /// <returns>3д модель корпуса</returns> private Solid3d BuildBody(WatchData WatchData) { //корпус часов Solid3d Body = new Solid3d(); Body.CreateFrustum(Height, Diameter, Diameter, Diameter); //Верхняя часть корпуса Solid3d BodyTop = new Solid3d(); BodyTop.CreateFrustum(_params[ParNames.BodyTransformByY], Diameter, Diameter, Diameter - _params[ParNames.BodyTransformByZ]); BodyTop.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByX]) - Point3d.Origin)); Body.BooleanOperation(BooleanOperationType.BoolUnite, BodyTop.Clone() as Solid3d); //Нижняя часть корпуса Solid3d BodyBottom = new Solid3d(); BodyBottom.CreateFrustum(_params[ParNames.BodyTransformByX], Diameter - _params[ParNames.BodyTopTransformByY], Diameter - _params[ParNames.BodyTopTransformByY], Diameter - _params[ParNames.BodyTransformByY]); BodyBottom.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, -(Height / 2 + _params[ParNames.BodyTransformByX] / 2)) - Point3d.Origin)); Body.BooleanOperation(BooleanOperationType.BoolUnite, BodyBottom.Clone() as Solid3d); //Вырез на корпусе, сверху BodyTop = new Solid3d(); BodyTop.CreateFrustum(_params[ParNames.BodyTransformByY], Diameter - _params[ParNames.BodyBottomTransformByX], Diameter - _params[ParNames.BodyBottomTransformByX], Diameter - _params[ParNames.BodyTopTransformByY]); BodyTop.TransformBy(Matrix3d.Displacement(new Point3d(0, 0, Height / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByX]) - Point3d.Origin)); Body.BooleanOperation(BooleanOperationType.BoolSubtract, BodyTop.Clone() as Solid3d); //ушки на корпусе Solid3d Bootstrap = new Solid3d(); Bootstrap.CreateBox(BootstrapLength * _params[ParNames.BodyTransformByY] + Diameter * _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]); Vector3d BootsrapPosition; Solid3d ArcPart = new Solid3d(); ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2); ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, 0, 0))); //Держатели на ушках Solid3d StrapHolder = new Solid3d(); StrapHolder.CreateFrustum(WatchData.StrapWidth + _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTransformByX] / _params[ParNames.BodyTransformByY]); StrapHolder.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin)); StrapHolder.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, -WatchData.StrapWidth / 2 - _params[ParNames.BodyTransformByY], 0))); ArcPart.BooleanOperation(BooleanOperationType.BoolUnite, StrapHolder.Clone() as Solid3d); Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d); //сглаженные углы на ушках ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / 2); ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin)); ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), 0, 0))); StrapHolder.CreateFrustum(WatchData.StrapWidth + _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 2, _params[ParNames.BodyTransformByX] / 2); StrapHolder.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); StrapHolder.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), -WatchData.StrapWidth / 2 - _params[ParNames.BodyTransformByY], 0))); ArcPart.BooleanOperation(BooleanOperationType.BoolUnite, StrapHolder.Clone() as Solid3d); Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d); BootsrapPosition = new Vector3d(0, WatchData.StrapWidth / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByZ], 0); Bootstrap.TransformBy(Matrix3d.Displacement(BootsrapPosition)); Body.BooleanOperation(BooleanOperationType.BoolUnite, Bootstrap.Clone() as Solid3d); Bootstrap = new Solid3d(); Bootstrap.CreateBox(BootstrapLength * _params[ParNames.BodyTransformByY] + Diameter * _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]); ArcPart = new Solid3d(); ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY]); ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin)); ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(Diameter + BootstrapLength, 0, 0))); Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d); ArcPart.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY], _params[ParNames.BodyTopTransformByY] / 2, _params[ParNames.BodyTopTransformByY] / _params[ParNames.BodyTransformByY]); ArcPart.TransformBy(Matrix3d.Rotation(Math.PI / _params[ParNames.BodyTransformByY], new Vector3d(1, 0, 0), Point3d.Origin)); ArcPart.TransformBy(Matrix3d.Displacement(new Vector3d(-(Diameter + BootstrapLength), 0, 0))); Bootstrap.BooleanOperation(BooleanOperationType.BoolUnite, ArcPart.Clone() as Solid3d); BootsrapPosition = new Vector3d(0, -(WatchData.StrapWidth / _params[ParNames.BodyTransformByY] + _params[ParNames.BodyTransformByZ]), 0); Bootstrap.TransformBy(Matrix3d.Displacement(BootsrapPosition)); //соеденяем все вместе Body.BooleanOperation(BooleanOperationType.BoolUnite, Bootstrap.Clone() as Solid3d); //если есть хронограф, то выполняем if (HasChronograph) { //первая кнопка хронографа Solid3d ChronoButtonTop = new Solid3d(); ChronoButtonTop.CreateFrustum(_params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX], _params[ParNames.BodyTopTransformByX]); ChronoButtonTop.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); ChronoButtonTop.TransformBy(Matrix3d.Displacement(new Vector3d(0, Diameter, 0))); ChronoButtonTop.TransformBy(Matrix3d.Rotation(Math.PI / 6, new Vector3d(0, 0, 1), Point3d.Origin)); Body.BooleanOperation(BooleanOperationType.BoolUnite, ChronoButtonTop.Clone() as Solid3d); //вторая кнопка хронографа Solid3d ChronoButtonBottom = new Solid3d(); ChronoButtonBottom.CreateFrustum(_params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY], _params[ParNames.BodyTopTransformByY]); ChronoButtonBottom.TransformBy(Matrix3d.Rotation(Math.PI / 2, new Vector3d(1, 0, 0), Point3d.Origin)); ChronoButtonBottom.TransformBy(Matrix3d.Displacement(new Vector3d(0, Diameter, 0))); ChronoButtonBottom.TransformBy(Matrix3d.Rotation(-Math.PI / 6, new Vector3d(0, 0, 1), Point3d.Origin)); Body.BooleanOperation(BooleanOperationType.BoolUnite, ChronoButtonBottom.Clone() as Solid3d); } return(Body); }
public void Test() { Document acDoc = Application.DocumentManager.MdiActiveDocument; Database acCurDb = acDoc.Database; Editor acEd = acDoc.Editor; using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()) { var blkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; var mdlSpc = acTrans.GetObject(blkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; /* var ent3dArray = Enumerable.Range(0, 8).Select(i => new Solid3d()).ToArray(); * var box = ent3dArray[0]; * box.CreateBox(1, 2, 3); * //圆锥/圆柱 * var fru = ent3dArray[1]; * fru.CreateFrustum(3, 1, 1, 0); * * //台体 * var pyr = ent3dArray[2]; * pyr.CreatePyramid(3, 5, 2, 1); * * var sph = ent3dArray[3]; * sph.CreateSphere(2); * * var tor = ent3dArray[4]; * tor.CreateTorus(2, 0.5); * * var wdg = ent3dArray[5]; * wdg.CreateWedge(1, 2, 3); * * var poly = new Polyline(); * * poly.AddVertexAt(poly.NumberOfVertices, Point2d.Origin - Vector2d.XAxis, 0, 0, 0); * poly.AddVertexAt(poly.NumberOfVertices, Point2d.Origin + Vector2d.XAxis, 0, 0, 0); * poly.AddVertexAt(poly.NumberOfVertices, Point2d.Origin + Vector2d.YAxis, 0, 0, 0); * poly.Closed = true; * * var reg=Region.CreateFromCurves(new DBObjectCollection() { poly })[0] as Region; * * var ext1 = ent3dArray[6]; * ext1.Extrude(reg, 6, 0); * * var ext2 = ent3dArray[7]; * ext2.Revolve(reg, Point3d.Origin + Vector3d.XAxis, Vector3d.YAxis, Math.PI * 2); * * foreach (var i in Enumerable.Range(0,8)) * { * * var ent3d = ent3dArray[i]; * * ent3d.TransformBy(Matrix3d.Displacement((Vector3d.XAxis * 10).RotateBy(i * Math.PI / 4, Vector3d.ZAxis))); * * mdlSpc.AppendEntity(ent3d); * acTrans.AddNewlyCreatedDBObject(ent3d, true); * * * }*/ var unit0 = new Solid3d(); unit0.CreateBox(2, 2, 0.2); unit0.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 0.1)); using (var unit1 = new Solid3d()) { unit1.CreateFrustum(3, 0.9, 0.9, 0); unit1.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 1.7)); unit0.BooleanOperation(BooleanOperationType.BoolUnite, unit1); } using (var unit2 = new Solid3d()) { unit2.CreateFrustum(3, 0.9, 0.9, 0); unit2.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 1.5)); unit0.BooleanOperation(BooleanOperationType.BoolSubtract, unit2); } using (var unit3 = new Solid3d()) { unit3.CreateFrustum(2, 0.6, 0.6, 0); unit3.TransformBy(Matrix3d.Displacement(Vector3d.ZAxis * 1)); unit0.BooleanOperation(BooleanOperationType.BoolUnite, unit3); } var brep = new Brep(unit0); acEd.WriteMessage(string.Join("\n", new[] { $"Complex:{brep.Complexes.Count()}", $"Shell:{brep.Shells.Count()}", $"Face:{brep.Faces.Count()}", $"Edged:{brep.Edges.Count()}", $"Vertex:{brep.Vertices.Count()}" } )); mdlSpc.AppendEntity(unit0); acTrans.AddNewlyCreatedDBObject(unit0, true); acTrans.Commit(); } }
public void interferenceSolids() { Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; using (Transaction trans = db.TransactionManager.StartTransaction()) { try { BlockTable blkTable = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable; if (blkTable == null) { trans.Abort(); return; } BlockTableRecord blkTableRecord = trans.GetObject(blkTable[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; if (blkTableRecord == null) { return; } using (Solid3d solid3DBox = new Solid3d()) { // 3D Solid Box. solid3DBox.CreateBox(5, 7, 10); solid3DBox.ColorIndex = 7; // Position of the center of solid3DBox at (5, 5, 0) solid3DBox.TransformBy(Matrix3d.Displacement(new Point3d(5, 5, 0) - Point3d.Origin)); //blkTableRecord.AppendEntity(solid3DBox); //trans.AddNewlyCreatedDBObject(solid3DBox, true); // 3D Solid Cylinder. using (Solid3d solid3DCylinder = new Solid3d()) { solid3DCylinder.CreateFrustum(20, 5, 5, 5); solid3DCylinder.ColorIndex = 4; //blkTableRecord.AppendEntity(solid3DCylinder); //trans.AddNewlyCreatedDBObject(solid3DCylinder, true); // Create 3D solid from the interference of the box and cylinder. //Solid3d solid3dCopy = solid3DCylinder.Clone() as Solid3d; //if (solid3dCopy.CheckInterference(solid3DBox) == true) //{ // solid3dCopy.BooleanOperation(BooleanOperationType.BoolSubtract, solid3DBox.Clone() as Solid3d); // solid3dCopy.ColorIndex = 1; //} //// add solid3dCopy to the block table record. //blkTableRecord.AppendEntity(solid3dCopy); //trans.AddNewlyCreatedDBObject(solid3dCopy, true); Solid3d solid3dCopyCylinder = solid3DCylinder.Clone() as Solid3d; if (solid3dCopyCylinder.CheckInterference(solid3DBox) == true) { solid3dCopyCylinder.BooleanOperation(BooleanOperationType.BoolIntersect, solid3DBox); solid3dCopyCylinder.ColorIndex = 3; } blkTableRecord.AppendEntity(solid3dCopyCylinder); trans.AddNewlyCreatedDBObject(solid3dCopyCylinder, true); } } trans.Commit(); } catch (System.Exception) { trans.Abort(); throw; } } }
public static Point3d DistFromPointToSolid( ref Document doc, ref Solid3d solid, Point3d point, double start, double step, ref double off, bool line) { var rez = new Point3d(); using (var acTrans = doc.Database.TransactionManager.StartTransaction()) { var acBlkTbl = (BlockTable)acTrans.GetObject(doc.Database.BlockTableId, OpenMode.ForWrite); var acBlkTblRec = (BlockTableRecord)acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite); var SOLID = (Solid3d)solid.Clone(); SOLID.SetDatabaseDefaults(); acBlkTblRec.AppendEntity(SOLID); acTrans.AddNewlyCreatedDBObject(SOLID, true); var startR = start <= 0 ? step : start; var sphere = new Solid3d(); sphere.SetDatabaseDefaults(); sphere.CreateSphere(startR); sphere.TransformBy(Matrix3d.Displacement(Point3d.Origin.GetVectorTo(point))); sphere.SetDatabaseDefaults(); acBlkTblRec.AppendEntity(sphere); acTrans.AddNewlyCreatedDBObject(sphere, true); while (sphere.CheckInterference(solid) == false) { try { sphere.OffsetBody(step); off += step; } catch { } } if (line) { var counter = 0; sphere.BooleanOperation(BooleanOperationType.BoolIntersect, SOLID); var dbo = new DBObjectCollection(); sphere.Explode(dbo); var coll = new Point3dCollection(); var curvesColl = new DBObjectCollection(); var ent = dbo[0] as Entity; if (ent.GetType().ToString().IndexOf("Surface") > 0) { var surf = ent as Surface; var ns = surf.ConvertToNurbSurface(); foreach (var nurb in ns) { double ustart = nurb.UKnots.StartParameter, uend = nurb.UKnots.EndParameter, uinc = (uend - ustart) / nurb.UKnots.Count, vstart = nurb.VKnots.StartParameter, vend = nurb.VKnots.EndParameter, vinc = (vend - vstart) / nurb.VKnots.Count; for (var u = ustart; u <= uend; u += uinc) { for (var v = vstart; v <= vend; v += vinc) { coll.Add(nurb.Evaluate(u, v)); counter++; } } } if (counter < 1) { var sub = new DBObjectCollection(); surf.Explode(sub); foreach (Entity entt in sub) { acBlkTblRec.AppendEntity(entt); acTrans.AddNewlyCreatedDBObject(entt, true); curvesColl.Add(entt); } } } else { var surf = (Region)ent; var p1 = surf.GeometricExtents.MaxPoint; var p2 = surf.GeometricExtents.MinPoint; var p = new Point3d((p1.X + p2.X) / 2.0, (p1.Y + p2.Y) / 2.0, (p1.Z + p2.Z) / 2.0); coll.Add(p); coll.Add(p); var sub = new DBObjectCollection(); surf.Explode(sub); foreach (Entity entt in sub) { acBlkTblRec.AppendEntity(entt); acTrans.AddNewlyCreatedDBObject(entt, true); curvesColl.Add(entt); } } foreach (DBObject ob in curvesColl) { var curve = (Curve)acTrans.GetObject(ob.Id, OpenMode.ForRead); var p1 = curve.StartPoint; var p2 = curve.EndPoint; var p = new Point3d((p1.X + p2.X) / 2.0, (p1.Y + p2.Y) / 2.0, (p1.Z + p2.Z) / 2.0); coll.Add(p); coll.Add(p1); coll.Add(p2); } if (coll.Count > 0) { rez = coll[0]; foreach (Point3d p in coll) { if (p.DistanceTo(point) < rez.DistanceTo(point)) { rez = p; } } } else { rez = point; } } // acTrans.Commit(); } return(rez); }
/// <summary> /// 三维实体布尔运算 /// </summary> /// <param name="solid1"></param> /// <param name="solid2"></param> /// <param name="type"></param> public static Solid3d BooleanOper(Solid3d solid1, Solid3d solid2, BooleanOperationType type) { solid1.BooleanOperation(type, solid2); return(solid1); }
public void KojtoCAD_3D_TrimPick_up_tr() { if (container.Triangles.Count > 0) { Pair <int, PromptStatus> pa = GlobalFunctions.GetInt(1, "\ntriangle numer:"); if ((pa.Second != PromptStatus.OK) || (pa.First < 1)) { return; } int num = pa.First - 1; Triangle TR = container.Triangles[num]; double x1 = 65.0; double x2 = 33.0; double x3 = 12.0; double x4 = 8.0; GetDistances(ref x1, ref x2, ref x3, ref x4); //foreach (WorkClasses.Triangle TR in container.Triangles) { int[] nodes = TR.GetNodesNumers(); quaternion Q0 = container.Nodes[nodes[0]].Position; quaternion Q1 = container.Nodes[nodes[1]].Position; quaternion Q2 = container.Nodes[nodes[2]].Position; double[] angles = new double[3]; double[] anglesDegree = new double[3]; angles[0] = (Q1 - Q0).angTo(Q2 - Q0); anglesDegree[0] = angles[0] * 180.0 / Math.PI; angles[1] = (Q0 - Q1).angTo(Q2 - Q1); anglesDegree[1] = angles[1] * 180.0 / Math.PI; angles[2] = (Q0 - Q2).angTo(Q1 - Q2); anglesDegree[2] = angles[2] * 180.0 / Math.PI; List <ObjectId> ids = new List <ObjectId>(); if (anglesDegree[0] <= 12.5) { ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x1, anglesDegree[0])); } if ((anglesDegree[0] > 12.5) && (anglesDegree[0] <= 20.0)) { ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x2, anglesDegree[0])); } if ((anglesDegree[0] > 20.0) && (anglesDegree[0] <= 35.0)) { ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x3, anglesDegree[0])); } if ((anglesDegree[0] > 35.0) && (anglesDegree[0] <= 45.0)) { ids.Add(TrimPickUP(nodes[0], TR.GetNumer(), x4, anglesDegree[0])); } if (anglesDegree[1] <= 12.5) { ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x1, anglesDegree[1])); } if ((anglesDegree[1] > 12.5) && (anglesDegree[1] <= 20.0)) { ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x2, anglesDegree[1])); } if ((anglesDegree[1] > 20.0) && (anglesDegree[1] <= 35.0)) { ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x3, anglesDegree[1])); } if ((anglesDegree[1] > 35.0) && (anglesDegree[1] <= 45.0)) { ids.Add(TrimPickUP(nodes[1], TR.GetNumer(), x4, anglesDegree[1])); } if (anglesDegree[2] <= 12.5) { ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x1, anglesDegree[2])); } if ((anglesDegree[2] > 12.5) && (anglesDegree[2] <= 20.0)) { ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x2, anglesDegree[2])); } if ((anglesDegree[2] > 20.0) && (anglesDegree[2] <= 35.0)) { ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x3, anglesDegree[2])); } if ((anglesDegree[2] > 35.0) && (anglesDegree[2] <= 45.0)) { ids.Add(TrimPickUP(nodes[2], TR.GetNumer(), x4, anglesDegree[2])); } if (ids.Count > 0) { using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction()) { Solid3d ent = tr.GetObject(GlobalFunctions.GetObjectId(TR.upSolidHandle.Second), OpenMode.ForWrite) as Solid3d; try { Solid3d sol = tr.GetObject(ids[0], OpenMode.ForWrite) as Solid3d; for (int i = 1; i < ids.Count; i++) { Solid3d sol_i = tr.GetObject(ids[i], OpenMode.ForWrite) as Solid3d; sol.BooleanOperation(BooleanOperationType.BoolUnite, sol_i); } ent.BooleanOperation(BooleanOperationType.BoolSubtract, sol); } catch { } tr.Commit(); } } } } else { MessageBox.Show("\nData Base Empty !\n", "Range Error !", MessageBoxButtons.OK, MessageBoxIcon.Error); } }