public void geometryPlaceToPlVertex() { // учитываем систему координат McDocument doc = McDocument.WorkingDocument; Matrix3d matCurrent = doc.UCS; Matrix3d matUsc = matCurrent.Inverse(); List <Point3d> Vertices = new List <Point3d>(); // собираем все вершины в list Vertices = this.PlineGetFromUser.listVertecs(this.PlineGetFromUser.plineGetFromUser); // какой тип объекта расставляем (блок либо обычную геометрию).у текстов отдельная обработка. if (ObjPlace is McBlockRef) { McBlockRef objPlMcBlockRef = new McBlockRef(); objPlMcBlockRef = ObjPlace as McBlockRef; foreach (Point3d onePt in Vertices) { McBlockRef refBlock = new McBlockRef(); String selBlock = objPlMcBlockRef.BlockName; refBlock.DbEntity.MatchProperties(objPlMcBlockRef.DbEntity, MatchPropEnum.All);//копирование свойств refBlock.BlockName = selBlock; refBlock.DbEntity.AddToCurrentDocument(); Point3d centrObj = refBlock.InsertPoint; Vector3d vec = centrObj.GetVectorTo(onePt); Matrix3d mat = Matrix3d.Displacement(vec); refBlock.DbEntity.Transform(mat); } } else if (ObjPlace is DbText) { DbText objPlDbText = new DbText(); objPlDbText = ObjPlace as DbText; foreach (Point3d onePt in Vertices) { McDbObject cloneGeom = objPlDbText.DbEntity.Clone() as McDbObject; cloneGeom.Entity.DbEntity.MatchProperties(objPlDbText.DbEntity, MatchPropEnum.All);//копирование свойств Point3d centrObj = objPlDbText.Text.Origin; Vector3d vec = centrObj.GetVectorTo(onePt); Matrix3d mat = Matrix3d.Displacement(vec); cloneGeom.Entity.DbEntity.Transform(mat); cloneGeom.Entity.DbEntity.AddToCurrentDocument(); } } else { DbGeometry objPlDbGeometry = new DbGeometry(); objPlDbGeometry = ObjPlace as DbGeometry; foreach (Point3d onePt in Vertices) { McDbObject cloneGeom = objPlDbGeometry.DbEntity.Clone() as McDbObject; cloneGeom.Entity.DbEntity.MatchProperties(objPlDbGeometry.DbEntity, MatchPropEnum.All);//копирование свойств Point3d centrObj = cloneGeom.Entity.DbEntity.BoundingBox.Center; Vector3d vec = centrObj.GetVectorTo(onePt); Matrix3d mat = Matrix3d.Displacement(vec); cloneGeom.Entity.DbEntity.Transform(mat); cloneGeom.Entity.DbEntity.AddToCurrentDocument(); } } }
public override hresult PlaceObject(PlaceFlags lInsertType) { InputJig jig = new InputJig(); List <McObjectId> SelectObjects = jig.SelectObjects("Select Object"); //InputResult res = jig.SelectObject("Select a Polyline"); //McObjectId id = SelectObjects[0];//.ObjectId; //DbGeometry selection = id.GetObject(); if (SelectObjects.Count == 0) { DbEntity.Erase(); return(hresult.e_Fail); } McDocument document = McDocumentsManager.GetActiveDoc(); McDocument block = document.CreateBlock("ArrayBlock", true); _block_name = block.Name; InputResult res = jig.GetPoint("Select Base Point:"); foreach (McObjectId obj in SelectObjects) { McDbObject item = obj.GetObject(); item.Entity.DbEntity.Transform(Matrix3d.Displacement(res.Point.GetAsVector().MultiplyBy(-1))); block.AddObject(item.Clone()); } _idRef = document.GetBlock(_block_name); res = jig.GetPoint("Select first point:"); if (res.Result != InputResult.ResultCode.Normal) { return(hresult.e_Fail); } _pnt1 = res.Point; foreach (McObjectId obj in SelectObjects) { McDbObject item = obj.GetObject(); item.Erase(); } McBlockRef blockref = new McBlockRef(); blockref.BlockName = _block_name; blockref.InsertPoint = res.Point; blockref.DbEntity.AddToCurrentDocument(); _blockRef.Add(blockref); _blockRef.Add(_blockRef[0].DbEntity.Clone()); _blockRef.Add(_blockRef[0].DbEntity.Clone()); DbEntity.AddToCurrentDocument(); //Exclude this from osnap to avoid osnap to itself jig.ExcludeObject(ID); //Monitor mouse move jig.MouseMove = (s, a) => { TryModify(); _pnt2 = a.Point; DbEntity.Update(); }; res = jig.GetPoint("Select second point:", res.Point); if (res.Result != InputResult.ResultCode.Normal) { DbEntity.Erase(); blockref.DbEntity.Erase(); return(hresult.e_Fail); } _pnt2 = res.Point; Editor ed = HostMgd.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; PromptIntegerOptions opts = new PromptIntegerOptions("Enter Count number: "); opts.AllowNegative = false; opts.AllowZero = false; opts.DefaultValue = 1; PromptIntegerResult pr = ed.GetInteger(opts); if (PromptStatus.OK == pr.Status) { ed.WriteMessage("You entered: " + pr.StringResult); _count = pr.Value; _blockRef.Add(blockref.DbEntity.Clone()); _blockRef[1].InsertPoint = res.Point; _blockRef[1].DbEntity.AddToCurrentDocument(); } else { _count = 1; _blockRef.Add(blockref.DbEntity.Clone()); _blockRef[1].InsertPoint = res.Point; _blockRef[1].DbEntity.AddToCurrentDocument(); } for (int i = 1; i < Count; i++) { _blockRef.Add(_blockRef[0].DbEntity.Clone()); } return(hresult.s_Ok); }
public McTable vertexInTable(DbPolyline plineGetFromUser, string accuracyPoint) { List <Point3d> Vert = new List <Point3d>(); Vert = this.listVertecs(plineGetFromUser); // создаем таблицу McTable TablePoint = new McTable(); int rowCount = Vert.Count; int colCount = 4; TablePoint.Rows.AddRange(0, rowCount + 1); TablePoint.Columns.AddRange(0, colCount); // настройки таблицы по умолчанию TablePoint.DefaultCell.TextHeight = 2.5; TablePoint.DefaultCell.TextColor = System.Drawing.Color.Black; // наименование_столбцов TablePoint[0, 0].Value = "№_Point"; TablePoint[0, 1].Value = "X"; TablePoint[0, 2].Value = "Y"; TablePoint[0, 3].Value = "Z"; // учитываем систему координат McDocument doc = McDocument.WorkingDocument; Matrix3d matCurrent = doc.UCS; Matrix3d matUsc = matCurrent.Inverse(); //номера точек в ячейки и координата X,Y,Z for (int i = 0; i < Vert.Count; i++) { Point3d onePointAtList = new Point3d(); onePointAtList = Vert[i]; onePointAtList = onePointAtList.TransformBy(matUsc);// преобразуем в текущую систему координат int j = i + 1; // точность представления чисел в ячейках - получается из формы от пользователя switch (accuracyPoint) { case "0": TablePoint[j, 1].Precision = CellPrecisionEnum.Integer; TablePoint[j, 2].Precision = CellPrecisionEnum.Integer; TablePoint[j, 3].Precision = CellPrecisionEnum.Integer; break; case "0.0": TablePoint[j, 1].Precision = CellPrecisionEnum.Precision1; TablePoint[j, 2].Precision = CellPrecisionEnum.Precision1; TablePoint[j, 3].Precision = CellPrecisionEnum.Precision1; break; case "0.00": TablePoint[j, 1].Precision = CellPrecisionEnum.Precision2; TablePoint[j, 2].Precision = CellPrecisionEnum.Precision2; TablePoint[j, 3].Precision = CellPrecisionEnum.Precision2; break; case "0.000": TablePoint[j, 1].Precision = CellPrecisionEnum.Precision3; TablePoint[j, 2].Precision = CellPrecisionEnum.Precision3; TablePoint[j, 3].Precision = CellPrecisionEnum.Precision3; break; } //номера точек в ячейки и координата X,Y,Z TablePoint[j, 0].Type = CellFormatEnum.Number; TablePoint[j, 0].Value = j.ToString(); TablePoint[j, 1].Type = CellFormatEnum.Number; TablePoint[j, 1].Value = onePointAtList.X.ToString(); TablePoint[j, 2].Type = CellFormatEnum.Number; TablePoint[j, 2].Value = onePointAtList.Y.ToString(); TablePoint[j, 3].Type = CellFormatEnum.Number; TablePoint[j, 3].Value = onePointAtList.Z.ToString(); } return(TablePoint); }