public static void Delete() { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); AutoCad.Command.SendLineEsc("PICKSTYLE 1"); //グループ選択必須 var dwg = Drawing.GetCurrent(); var leaderIds = AutoCad.Db.Leader.GetAll(Const.Layer.電気_SocketPlan); leaderIds.AddRange(AutoCad.Db.Leader.GetAll(Const.Layer.電気_SocketPlan_Specific)); var ids = SocketBoxObject.SelectSocketBoxes(); var blockIds = new List <int>(); List <PointD> bounds = new List <PointD>(); //PointD bottomleft = new PointD(double.MaxValue, double.MaxValue); //PointD topRight = new PointD(double.MinValue, double.MinValue); double bottom = double.MaxValue; double top = double.MinValue; double left = double.MaxValue; double right = double.MinValue; var deleteSeqs = new List <string>(); foreach (var id in ids) { var layerName = AutoCad.Db.Entity.GetLayerName(id); if (layerName != Const.Layer.電気_SocketPlan && layerName != Const.Layer.電気_SocketPlan_Specific) { continue; } //Block削除 if (AutoCad.Db.BlockReference.IsType(id)) { var socketboxAttribute = Attribute.GetAll(id); var seqAttr = socketboxAttribute.Find(p => p.Tag == "seq"); if (seqAttr == null) { throw new ApplicationException("Please execute generating."); } var seq = seqAttr.Value.ToString(); if (!string.IsNullOrEmpty(seq)) { deleteSeqs.Add(seq); } bounds = AutoCad.Db.BlockReference.GetBlockBound(id); if (left > bounds[0].X) { left = bounds[0].X; } if (left > bounds[1].X) { left = bounds[1].X; } if (right < bounds[0].X) { right = bounds[0].X; } if (right < bounds[1].X) { right = bounds[1].X; } if (bottom > bounds[0].Y) { bottom = bounds[0].Y; } if (bottom > bounds[1].Y) { bottom = bounds[1].Y; } if (top < bounds[0].Y) { top = bounds[0].Y; } if (top < bounds[1].Y) { top = bounds[1].Y; } AutoCad.Db.BlockReference.Erase(id); blockIds.Add(id); } //枠削除(バラ品のみ) else if (AutoCad.Db.Polyline.IsType(id)) { AutoCad.Db.Polyline.Erase(id); } } //LeadLine削除 var leaderId = SocketBoxObject.GetLeaderObjectId(new List <PointD>() { new PointD(left, bottom), new PointD(right, top) }, leaderIds); PointD leaderStart = new PointD(); PointD leaderEnd = new PointD(); if (leaderId.HasValue) { leaderStart = AutoCad.Db.Leader.GetStartPoint(Int32.Parse(leaderId.ToString())); leaderEnd = AutoCad.Db.Leader.GetEndPoint(Int32.Parse(leaderId.ToString())); AutoCad.Db.Leader.Erase(Int32.Parse(leaderId.ToString())); } //DB削除 using (var service = new SocketPlanService()) { service.DeleteSocketBoxes(Static.ConstructionCode, deleteSeqs.ToArray()); } AutoCad.Command.RefreshEx(); }