private RbInfo GetNearest(Point3d point3d, List <RbInfo> RbInsPoints) { var sorted = RbInsPoints.OrderBy(x => x.Pos.Distance2dTo(point3d)).ToList(); RbInfo ret = sorted[0]; double dist = point3d.Distance2dTo(ret.Pos); if (dist > _MaxDist) { return(null); } return(ret); }
internal void MoveFbh(double xDist, double yDist) { List <ObjectId> allHkBlocks = SelectAllHkBlocks(); if (allHkBlocks.Count == 0 || _AllRaumBlocks.Count == 0) { return; } using (Transaction myT = _TransMan.StartTransaction()) { List <RbInfo> RbInsPoints = GetRbInfos(); foreach (var oid in allHkBlocks) { BlockReference blockRef = _TransMan.GetObject(oid, OpenMode.ForRead) as BlockReference; if (blockRef == null) { continue; } RbInfo par = GetNearest(blockRef.Position, RbInsPoints); if (par == null) { continue; } Vector2d v = new Vector2d(xDist * par.Scale, yDist * par.Scale); v = v.RotateBy(par.Rot); Vector3d v3 = new Vector3d(v.X, v.Y, 0.0); Point3d newP = par.Pos.Add(v3); Vector3d vAtt = blockRef.Position.GetVectorTo(newP); blockRef.UpgradeOpen(); blockRef.Position = newP; foreach (ObjectId attId in blockRef.AttributeCollection) { var anyAttRef = _TransMan.GetObject(attId, OpenMode.ForWrite) as AttributeReference; if (anyAttRef != null) { newP = anyAttRef.Position.Add(vAtt); anyAttRef.Position = newP; } } } myT.Commit(); } }