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 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(); } } }