예제 #1
0
        public static void MoveLocation()
        {
            Initialize();

            while (true)
            {
                var boxIds = SelectSocketBox();
                if (boxIds.Count == 0)
                {
                    return;
                }

                var layerName = AutoCad.Db.Entity.GetLayerName(boxIds[0]);
                if (layerName == Const.Layer.電気_SocketPlan_Specific)
                {
                    //バラ品移動処理へ
                    return;
                }
                else if (layerName != Const.Layer.電気_SocketPlan)
                {
                    MessageDialog.ShowWarning("this is not a socket box.");
                    return;
                }

                int?boxId       = boxIds[0];  //IsTypeだとなんかだめなので。。。
                var boxSize     = AutoCad.Db.BlockReference.GetSize(boxId.Value);
                var beforePoint = AutoCad.Db.BlockReference.GetPosition(boxId.Value);
                var bounds      = AutoCad.Db.BlockReference.GetBlockBound(boxId.Value);

                if (IsOSnap())
                {
                    OffOSnap();
                }

                var afterPoint = SocketBoxObject.GetClickPoint();
                if (afterPoint == null)
                {
                    throw new ApplicationException(Messages.FailedToGetPoint());
                }

                var leaderId = SocketBoxObject.GetLeaderObjectId(bounds);
                if (!leaderId.HasValue)
                {
                    throw new ApplicationException("Failed to get leader.");
                }

                var leaderFirstPoint = AutoCad.Db.Leader.GetFirstVertex(leaderId.Value);
                AutoCad.Db.Leader.Erase(leaderId.Value);
                AutoCad.Status.WaitFinish();
                AutoCad.Command.RefreshExEx();

                AutoCad.Command.SendLine("MOVE\n" + ToStringNoSpace(beforePoint) + "\n\n" +
                                         ToStringNoSpace(beforePoint) + "\n" + ToStringNoSpace(afterPoint));
                AutoCad.Status.WaitFinish();
                AutoCad.Command.RefreshExEx();

                SocketBoxObject.MakeLeader(leaderFirstPoint, afterPoint, boxSize);
                AutoCad.Command.RefreshExEx();
            }
        }