public static void CleanUpCeilingPanelDrawing() { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); var layerIds = AutoCad.Db.LayerTable.GetLayerIds(); foreach (var layerId in layerIds) { var layerName = AutoCad.Db.LayerTableRecord.GetLayerName(layerId); AutoCad.Db.LayerTableRecord.SetColor(layerId, CadColor.Gray); if (layerName == Const.Layer.Zero) { continue; } if (layerName.Contains(Const.Layer.電気)) { continue; } AutoCad.Db.LayerTableRecord.SetLayerName(layerId, Const.Layer.電気_天井パネル補足 + "_" + layerName); } AutoCad.Command.SetColorAll(CadColor.ByLayer); }
public static void DrawTexts(Comment comment) { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); //レイヤーを変える AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_コメント, CadColor.BlackWhite, Const.LineWeight.Default); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_コメント); //テキストスタイルを作る AutoCad.Db.TextStyleTableRecord.Make(Const.Font.MSGothic, Const.Font.MSGothic); var textId = 0; do { textId = TextDrawer.DrawText(comment.Text, CadColor.Red); }while (!AutoCad.Status.IsCanceled()); if (textId != 0) { AutoCad.Db.Object.Erase(textId); } }
private void DrawFrame() { AutoCad.Db.Database.SetFileDialogMode(false); foreach (var drawing in this.drawings) { WindowController2.BringDrawingToTop(drawing.WindowHandle); var layout = this.GetLayout(drawing); if (layout == null) { throw new ApplicationException("Failed to get template file."); } this.InsertLayoutTemplate(layout); this.SetLayer(); //ビューポートの縮尺を設定してからこれを呼ばないと、図枠の縮尺が正しく記入されない this.InsertLayoutTexts(drawing, layout); AutoCad.Command.ZoomAll(); AutoCad.Command.RefreshExEx(); } }
private void LoadCadObjectContainer() { WindowController2.BringAutoCadToTop(); this.currentDwg = Drawing.GetCurrent(); if (!this.currentDwg.FileName.Contains("Individual")) { throw new ApplicationException("Please first make, and select the Individual plan."); } AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); //こっちの方が多分楽なので this.container = new CadObjectContainer(new List <Drawing>() { this.currentDwg }, CadObjectTypes.RoomOutline | CadObjectTypes.Symbol | CadObjectTypes.HouseOutline | CadObjectTypes.Clip ); this.container.FillSymbolRooms(); this.container.FillIsOutsideAndIsOutdoor(); }
public static void CloseSelected(List <Drawing> drawings) { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Db.Database.SetFileDialogMode(false); foreach (var drawing in drawings) { WindowController2.BringDrawingToTop(drawing.WindowHandle); AutoCad.Command.Prepare(); try { while (true) { //closeコマンドはスクリプトを使わないと、保存を確かめるダイアログが出て処理が止まってしまう。 AutoCad.Command.SendLineEsc(@"script C:\UnitWiring\Scripts\Close.scr"); var currentHandle = WindowController2.GetTopDrawingHandle(); if (drawing.WindowHandle != currentHandle) { break; } } } catch { //取得に失敗したということは開いている図面が無いということなので抜けて良し } } AutoCad.Db.Database.SetFileDialogMode(true); }
public static int SaveAll(string savePath) { if (!savePath.EndsWith(@"\")) { savePath += @"\"; } WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); if (!System.IO.Directory.Exists(savePath + Static.ConstructionCode)) { System.IO.Directory.CreateDirectory(savePath + Static.ConstructionCode); } var drawings = Drawing.GetAll(true); drawings.AddRange(Drawing.GetAllForSocketPlan(null)); AutoCad.Db.Database.SetFileDialogMode(false); foreach (var drawing in drawings) { WindowController2.BringDrawingToTop(drawing.WindowHandle); string fileName = Static.Drawing.Prefix + "-" + Static.Drawing.ConstructionCodePlanRevisionNo + "-" + drawing.FloorCode + ".dwg"; if (drawing.IsSocketPlan) { fileName = drawing.FileName; } string filePath = savePath + Static.ConstructionCode + "\\" + fileName; var overwrite = false; //別の場所から同名のファイルを持ってきて保存する時は上書き確認する if (drawing.FullPath.ToUpper() != filePath.ToUpper() && drawing.FileName.ToUpper() == fileName.ToUpper()) { overwrite = true; } AutoCad.File.Save(filePath, overwrite); drawing.FullPath = filePath; } var groundFloor = drawings.Find(p => p.Floor == 1); if (groundFloor != null) { WindowController2.BringDrawingToTop(groundFloor.WindowHandle); } AutoCad.Db.Database.SetFileDialogMode(true); return(drawings.Count); }
public static List <Drawing> GetAll(bool withElevationPlan) { //AutoCAD2013でレイヤ管理画面を表示したまま、図面を切り替えるとエラーになる。 //対策としてここでやっときゃいいっしょ。 AutoCad.Command.CloseLayerManager(); var drawingHandles = WindowController2.GetDrawingHandles(); //MDIの子画面のサイズを小さくされていると、図面のファイル名を正しく取れないことがある。それ対策。 if (drawingHandles.Count != 0) { WindowController2.Maximize(drawingHandles[0]); } var drawings = new List <Drawing>(); foreach (var handle in drawingHandles) { var title = WindowController2.GetWindowTitle(handle); string fileName = Path.GetFileNameWithoutExtension(title); if (!fileName.Contains(Static.ConstructionCode)) { continue; } var drawing = new Drawing(); drawing.WindowHandle = handle; drawing.FullPath = title; if (!drawing.IsDenkiPlan) { continue; } if (!withElevationPlan && drawing.IsElevation) { continue; } if (drawing.PlanNo != Static.Drawing.PlanNo) { continue; } if (drawing.RevisionNo != Static.Drawing.RevisionNo) { continue; } drawings.Add(drawing); } drawings.Sort((p, q) => { return(p.FloorCode.CompareTo(q.FloorCode)); }); return(drawings); }
public static void CopyCeilingPanel() { WindowController2.BringAutoCadToTop(); AutoCad.Command.SendLineEsc("copybase"); //コピー基点入力待ち AutoCad.Status.WaitFinish(); }
private static void Initialize() { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_SocketPlan, CadColor.BlackWhite, Const.LineWeight._0_15); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_SocketPlan); }
public static void DrawCeilingPanel(string panelNo, bool isPolyline) { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); //レイヤーを追加する var layerName = Const.Layer.電気_天井パネル + "_" + panelNo; AutoCad.Db.LayerTableRecord.Make(layerName, CadColor.Red, Const.LineWeight.Default); AutoCad.Command.SetCurrentLayer(layerName); DrawResult result; //天井パネル枠を書いてもらう if (isPolyline) { result = AutoCad.Drawer.DrawPolyline(true); } else { result = AutoCad.Drawer.DrawRectangle(""); } if (result.Status == DrawStatus.Canceled) { return; } if (result.Status == DrawStatus.Failed) { throw new ApplicationException(Messages.CeilingPanelNotSet()); } var lineId = result.ObjectId; //線の始点を終点をくっつける if (!AutoCad.Db.Polyline.IsClosed(lineId)) { AutoCad.Db.Polyline.SetClose2(lineId); } //線種を変える if (!AutoCad.Db.LinetypeTable.Exist(Const.Linetype.CeilingPanel)) { AutoCad.Db.LinetypeTable.Add(Const.Linetype.CeilingPanel); } AutoCad.Db.Entity.SetLineType(lineId, Const.Linetype.CeilingPanel); //天井パネル番号を書く var center = AutoCad.Db.Entity.GetCenter(lineId); AutoCad.Db.TextStyleTableRecord.Make(Const.Font.MSGothic, Const.Font.MSGothic); AutoCad.Db.Text.Make(panelNo, 250, center, Align.中央); }
public static void Bring1FDrawingToTop() { var drawings = Drawing.GetAll(false); var groundFloor = drawings.Find(p => p.Floor == 1); if (groundFloor != null) { WindowController2.BringDrawingToTop(groundFloor.WindowHandle); } }
public static void DrawHouseOutline() { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_外周, CadColor.Cyan, Const.LineWeight._0_50); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_外周); AutoCad.Command.DrawPolyline(); }
public static Drawing GetCurrent() { var currentDrawingHandle = WindowController2.GetTopDrawingHandle(); var drawing = new Drawing(); drawing.WindowHandle = currentDrawingHandle; drawing.FullPath = WindowController2.GetWindowTitle(currentDrawingHandle); return(drawing); }
public void SaveDrawings() { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Db.Database.SetFileDialogMode(false); foreach (var dwg in this.socketPlanDrawings) { WindowController2.BringDrawingToTop(dwg.WindowHandle); AutoCad.File.Save(this.directoryPath + dwg.FileName, true); } AutoCad.Db.Database.SetFileDialogMode(true); }
public static int OpenAllForSocketPlan(List <Drawing> drawings) { var drawingHandles = WindowController2.GetDrawingHandles(); if (drawingHandles.Count == 0) { //図面が一枚も開かれていない場合、コマンドラインが表示されず、以降の処理がスカる。それ対策 //SendCommandだとテンプレートファイル名を入力するまで処理が帰ってこない AutoCad.File.Create("."); } WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Db.Database.SetFileDialogMode(false); AutoCad.Command.DisableSDI(); //AutoCAD2013対応ここから AutoCad.Command.SmoothZoomOff(); AutoCad.Command.SetInsertUnitToMM(); //ここまで AutoCad.Command.SendLineEsc("PICKSTYLE 1"); //グループ選択必須 drawings.Sort((p, q) => p.FloorCode.CompareTo(q.FloorCode)); //1階図面を最後に開くために階の降順でソートする int count = 0; //同ファイル名の図面を開くと、読み取り専用になって動かなくなるので、同名が既に開いていたら開かない。 var openedDrawings = Drawing.GetAllForSocketPlan(null); foreach (var drawing in drawings) { if (openedDrawings.Exists(p => p.FileName == drawing.FileName)) { continue; } AutoCad.File.Open(drawing.FullPath); AutoCad.Command.ZoomAll(); AutoCad.Command.SetCurrentLayoutToModel(); count++; } AutoCad.Db.Database.SetFileDialogMode(true); return(count); }
private void openButton_Click(object sender, EventArgs e) { try { this.Cursor = Cursors.WaitCursor; //AutoCADが起動していない時AutoCADを起動する if (!WindowController2.ExistAutoCad()) { throw new ApplicationException(Messages.PleaseLaunchAutoCAD()); //WindowController.LaunchAutoCAD();プログラムから起動すると、なぜかFatalErrorが頻発するので、やめ。 //ユーザーに起動してもらう } var dataRow = this.dataGridView.SelectedRows[0].DataBoundItem as DataRowView; var drawings = dataRow["Drawings"] as List <Drawing>; var count = this.OpenFiles(drawings); //new AdjustGrid0point().Run(); this.Activate(); if (count > 0) { MessageDialog.ShowInformation(this, Messages.FileOpened(count)); } else { MessageDialog.ShowInformation(this, Messages.FileAlreadyOpened()); } this.Close(); } catch (Exception ex) { MessageDialog.ShowError(ex); //途中でエラーになると、中途半端にStaticが更新されてしまう。 //そうなった時は、ConstructionCodeをnullにしてコントロールのenableを切る。 Static.ConstructionCode = null; this.DialogResult = DialogResult.None; } finally { this.Cursor = Cursors.Default; } }
public void GetExportDrawings() { AutoCad.Command.CloseLayerManager(); var drawingHandles = WindowController2.GetDrawingHandles(); if (drawingHandles.Count != 0) { WindowController2.Maximize(drawingHandles[0]); } var drawings = new List <Drawing>(); foreach (var handle in drawingHandles) { var title = WindowController2.GetWindowTitle(handle); string fileName = Path.GetFileNameWithoutExtension(title); if (!fileName.Contains(Static.ConstructionCode)) { continue; } var drawing = new Drawing(); drawing.WindowHandle = handle; drawing.FullPath = title; if (drawing.PlanNo != Static.Drawing.PlanNo) { continue; } if (drawing.RevisionNo != Static.Drawing.RevisionNo) { continue; } if (!drawing.IsSocketPlan) { continue; } this.socketPlanDrawings.Add(drawing); } }
//加工依頼後で、回路図面が存在しない場合警告 public static void WarnNotExistsKairoFrame(List <Drawing> drawings) { var messageId = @"There is no 提案HEMS回路図面. Please create a 提案HEMS回路図面 before do the option picking."; var validator = new Validator(); validator.Validate = delegate() { //加工依頼前はノーチェック using (var server = new SocketPlanServiceNoTimeout()) { if (server.IsBeforeProcessRequest(Static.ConstructionCode)) { return(null); } } var error = new ErrorDialog(messageId, 0); //回路図面が見つからなかったらエラー var kairoLayoutName = "提案HEMS回路図面"; foreach (var drawing in drawings) { if (drawing.Floor < 1 || drawing.Floor > 3) { continue; } WindowController2.BringDrawingToTop(drawing.WindowHandle); AutoCad.Command.SetCurrentLayoutToModel(); var modelLayout = AutoCad.Db.Layout.GetCurrent(); AutoCad.Command.SetCurrentLayout(kairoLayoutName); var kairoLayout = AutoCad.Db.Layout.GetCurrent(); if (modelLayout == kairoLayout) { return(error); } } return(null); }; validator.Run(messageId); }
private void setButton_Click(object sender, EventArgs e) { try { //念のためCurrentをチェックする WindowController2.BringAutoCadToTop(); var current = Drawing.GetCurrent(); if (current.Name != this.currentDwg.Name) { this.ShowErrorMessage("target drawing is moved. please close this form once."); return; } this.DrawSpecificItmes(); this.Show(); } catch (Exception ex) { this.ShowErrorMessage(ex.Message); } }
public static void DrawCeilingReceiver(string panelNo) { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); //レイヤーを追加する var layerName = Const.Layer.電気_天井パネル + "_" + panelNo; AutoCad.Db.LayerTableRecord.Make(layerName, CadColor.Red, Const.LineWeight.Default); AutoCad.Command.SetCurrentLayer(layerName); //繰り返し書く while (true) { //天井受けを書いてもらう var result = AutoCad.Drawer.DrawRectangle(""); if (result.Status == DrawStatus.Canceled) { return; } if (result.Status == DrawStatus.Failed) { throw new ApplicationException(Messages.CeilingReceiverNotSet()); } var rectangleId = result.ObjectId; //線種を変える if (!AutoCad.Db.LinetypeTable.Exist(Const.Linetype.CeilingReceiver)) { AutoCad.Db.LinetypeTable.Add(Const.Linetype.CeilingReceiver); } AutoCad.Db.Entity.SetLineType(rectangleId, Const.Linetype.CeilingReceiver); } }
public static void Move(string blockName, int attId, string attValue) { var attBound = AutoCad.Db.Entity.GetEntityBound(attId); WindowController2.BringAutoCadToTop(); string command = "-attedit" + "\n"; command += "y" + "\n"; command += blockName + "\n"; command += "*" + "\n"; //タグに小文字が含まれていると、なぜかひっかからないので。 command += attValue + "\n"; command += "fence\n" + attBound[0].X + "," + attBound[0].Y + "\n" + (attBound[1].X) + "," + (attBound[1].Y) + "\n" + "\n" + "\n"; command += "p"; AutoCad.Command.SendLineEsc(command); AutoCad.Status.WaitHistory("文字列の新しい挿入位置を指定 <変更しない>:", "Specify new text insertion point <no change>:"); if (AutoCad.Status.IsCanceled()) { return; } AutoCad.Command.SendLine(string.Empty); }
public static void Bring1FDrawingToTop(SocketPlanType type) { var drawings = Drawing.GetAll(false); Drawing groundFloor; if (type == SocketPlanType.Individual) { groundFloor = drawings.Find(p => p.Floor == 1 && p.Name.Contains("Individual")); } else if (type == SocketPlanType.Pattern) { groundFloor = drawings.Find(p => p.Floor == 1 && p.Name.Contains("Pattern")); } else { throw new ApplicationException("Invalid socket plan type is selected."); } if (groundFloor != null) { WindowController2.BringDrawingToTop(groundFloor.WindowHandle); } }
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(); }
public static void DrawRoomOutline(bool isPolyline, bool withJo) { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); if (withJo) { AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_部屋_WithJyou, CadColor.Magenta, Const.LineWeight._0_70); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_部屋_WithJyou); } else { AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_部屋_WithoutJyou, CadColor.Green, Const.LineWeight._0_70); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_部屋_WithoutJyou); } List <SiyoHeya> siyoHeyas; using (var service = new SocketPlanServiceNoTimeout()) { siyoHeyas = new List <SiyoHeya>(service.GetSiyoHeyas(Static.ConstructionCode, Static.Drawing.PlanNoWithHyphen)); } var drawing = Drawing.GetCurrent(); while (true) { //部屋名を選択してもらう。 var roomName = RoomObject.GetRoomNameText("Select Room Name:", false); if (string.IsNullOrEmpty(roomName)) { break; //入力をキャンセルしていたら終了 } if (!withJo && UnitWiring.Masters.Rooms.Exists(p => p.Name == roomName && p.WithJyou)) { MessageDialog.ShowWarning(Messages.ShouldHaveJyou()); //警告のみで処理続行 } var roomNameInSiyo = RoomObject.GetRoomNameInSiyo(roomName, siyoHeyas); if (string.IsNullOrEmpty(roomNameInSiyo)) { RoomSelectForm form = new RoomSelectForm(siyoHeyas, roomName); var dr = form.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Cancel) { break; } roomName = form.CorrectRoomName; } var roomCode = RoomObject.GetRoomCode(roomName, drawing.Floor, siyoHeyas); DrawResult result; //線を引いてもらう。 if (isPolyline) { result = AutoCad.Drawer.DrawPolyline(true); } else { result = AutoCad.Drawer.DrawRectangle(""); } if (result.Status == DrawStatus.Canceled) { break; } if (result.Status == DrawStatus.Failed) { throw new ApplicationException(Messages.RoomNotSet()); } var lineId = result.ObjectId; if (!AutoCad.Db.Entity.GetLayerName(lineId).Contains(Const.Layer.電気_部屋)) { throw new ApplicationException(Messages.RoomNotSet()); } //線の始点と終点をくっつける if (!AutoCad.Db.Polyline.IsClosed(lineId)) { AutoCad.Db.Polyline.SetClose2(lineId); } //帖数を選択してもらう。 string jo = string.Empty; if (withJo) { jo = RoomObject.SelectJoIndication(); if (string.IsNullOrEmpty(jo)) { AutoCad.Db.Object.Erase(lineId); AutoCad.Command.Refresh(); break; //入力をキャンセルしていたら書いた図形を削除して終了 } } //引いた線に部屋名を拡張データとして持たせる。 XData.Room.SetRoomName(lineId, roomName); XData.Room.SetRoomCode(lineId, roomCode); if (withJo) { XData.Room.SetRoomJyou(lineId, jo); } //タレ壁情報を入力する画面を表示する var roomObj = new RoomObject(lineId, 0, siyoHeyas); //階数は適当 var roomInfoForm = new RoomInfoForm(roomObj); var dr2 = roomInfoForm.ShowDialog(); if (dr2 == System.Windows.Forms.DialogResult.Cancel) { AutoCad.Db.Object.Erase(lineId); AutoCad.Command.Refresh(); break; //入力をキャンセルしていたら書いた図形を削除して終了 } AutoCad.Status.WaitFinish(); if (result.Status == DrawStatus.DrawnAndCanceled) { break; //線をひいてキャンセルしていたら拡張データを設定して終了 } } }
public static DrawResult DrawRoomOutline0Jyou(int floor) { WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_部屋_WithoutJyou, CadColor.Green, Const.LineWeight._0_70); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_部屋_WithoutJyou); List <SiyoHeya> siyoHeyas; using (var service = new SocketPlanServiceNoTimeout()) { siyoHeyas = new List <SiyoHeya>(service.GetSiyoHeyas(Static.ConstructionCode, Static.Drawing.PlanNoWithHyphen)); } //先に線を引いてもらう var result = AutoCad.Drawer.DrawPolyline(true); if (result.Status == DrawStatus.Canceled) { return(result); } if (result.Status == DrawStatus.Failed) { throw new ApplicationException("Failed to get line info.\nPlease draw line again."); } var lineId = result.ObjectId; if (!AutoCad.Db.Entity.GetLayerName(lineId).Contains(Const.Layer.電気_部屋)) { throw new ApplicationException("Invalid layer.\nPlease draw line again."); } //線の始点と終点をくっつける if (!AutoCad.Db.Polyline.IsClosed(lineId)) { AutoCad.Db.Polyline.SetClose2(lineId); } //部屋を選んでもらう var roomName = RoomObject.GetRoomNameText("Select Room Name:", true); if (roomName == null) { result.Status = DrawStatus.Canceled; AutoCad.Db.Polyline.Erase(lineId); return(result); } else if (roomName == string.Empty) { roomName = "外部"; } var roomNameInSiyo = RoomObject.GetRoomNameInSiyo(roomName, siyoHeyas); var roomCode = RoomObject.GetRoomCode(roomName, floor, siyoHeyas); if (string.IsNullOrEmpty(roomNameInSiyo)) { RoomSelectForm form = new RoomSelectForm(siyoHeyas, roomName); var dr = form.ShowDialog(); if (dr == System.Windows.Forms.DialogResult.Cancel) { result.Status = DrawStatus.Canceled; AutoCad.Db.Polyline.Erase(lineId); return(result); } roomName = form.CorrectRoomName; roomCode = form.CorrectRoomCode; } XData.Room.SetRoomName(lineId, roomName); XData.Room.SetRoomJyou(lineId, "0"); XData.Room.SetRoomTarekabeJyou(lineId, "0"); XData.Room.SetRoomCode(lineId, roomCode); return(result); }
public static void DrawSpecifics(ref List <SocketBoxSpecific> specifics, int seq) { if (specifics.Count == 0) { return; } WindowController2.BringAutoCadToTop(); AutoCad.Command.Prepare(); AutoCad.Command.SetCurrentLayoutToModel(); AutoCad.Db.LayerTableRecord.Make(Const.Layer.電気_SocketPlan_Specific, CadColor.BlackWhite, Const.LineWeight._0_15); System.Threading.Thread.Sleep(100); AutoCad.Command.SetCurrentLayer(Const.Layer.電気_SocketPlan_Specific); System.Threading.Thread.Sleep(100); //直交モードを一時的に有効にする var orhtoMode = AutoCad.Db.Database.IsOrthogonalMode(); if (!orhtoMode) { AutoCad.Db.Database.SetOrthogonalMode(true); } PointD bottomLeft = null; PointD topRight = null; List <int> drawnIds = new List <int>(); var basePosition = new PointD(); foreach (var specific in specifics) { if (!File.Exists(specific.BlockPath)) { throw new ApplicationException("a block file is not found."); } if (specifics.IndexOf(specific) == 0) { AutoCad.Command.InsertBlockWithRotation(specific.BlockPath); AutoCad.Status.WaitFinish(); if (AutoCad.Status.IsCanceled()) { return; } } else { basePosition.X += 1500; //2個目以降は自動で置く AutoCad.Db.BlockReference.Insert(specific.BlockPath, basePosition); } var id = AutoCad.Selection.GetLastObjectId(); if (id == null) { throw new ApplicationException("symbol drawing is failed. please retry."); } specific.SocketBlockId = (int)id; List <PointD> pos = AutoCad.Db.BlockReference.GetBlockBound(specific.SocketBlockId); if (specifics.IndexOf(specific) == 0) { basePosition = AutoCad.Db.BlockReference.GetPosition(specific.SocketBlockId); } //Seqを埋め込む //XData.Symbol.SetSocketBoxSeq(specific.SocketBlockId, seq); var attId = Attribute.Make(specific.SocketBlockId, "seq", seq.ToString(), new PointD(0, 0), true); AutoCad.Db.Attribute.SetVisible(attId, false); if (bottomLeft == null) { bottomLeft = pos[0]; } else { if (bottomLeft.X > pos[0].X) { bottomLeft.X = pos[0].X; } if (bottomLeft.Y > pos[0].Y) { bottomLeft.Y = pos[0].Y; } } if (topRight == null) { topRight = pos[1]; } else { if (topRight.X < pos[1].X) { topRight.X = pos[1].X; } if (topRight.Y < pos[1].Y) { topRight.Y = pos[1].Y; } } drawnIds.Add(specific.SocketBlockId); } //位置調節(あとまわし) //枠を置く var rectId = AutoCad.Db.Polyline.MakeRectangle(bottomLeft, topRight); AutoCad.Db.Entity.SetColor(rectId, CadColor.Orange); //チェックボックス追加 var lineId = SymbolDrawer.DrawCheckBox(bottomLeft, topRight); AutoCad.Db.Entity.SetColor(lineId, CadColor.Orange); //グループ化 var groupingIds = new List <int>(); groupingIds.AddRange(drawnIds); groupingIds.Add(rectId); groupingIds.Add(lineId); //Boxの座標取得 LeftBottom = bottomLeft; RightTop = topRight; AutoCad.Db.Group.Make("SocketSpecific_" + DateTime.Now.ToString("yyyyMMddhhmmssfff"), groupingIds); //名前は何でもいいが被ると困るので現在時刻で作る PointD endPoint = new PointD(); while (true) { AutoCad.Command.Prepare(); var ids = AutoCad.Selection.SelectObjects("Please select a socket symbol."); var blockIds = ids.FindAll(p => AutoCad.Db.BlockReference.IsType(p)); if (blockIds.Count == 1) { endPoint = AutoCad.Db.BlockReference.GetPosition(blockIds[0]); specifics.ForEach(p => p.SymbolObjectId = blockIds[0]); //blockIdを持ち帰る break; } else { MessageBox.Show("You can choose only one symbol. "); //選び直させる } if (AutoCad.Status.IsCanceled()) { return; } } //矢印を引く AutoCad.Command.ZoomAll(); var center = AutoCad.Db.ViewportTableRecord.GetCenterPointOfModelLayout(); var direction = Utilities.GetSocketPlanDirection(basePosition, center); var points = new List <PointD>(); if (direction == SocketPlanDirection.LeftDown || direction == SocketPlanDirection.LeftUp) { points.Add(new PointD(topRight.X, bottomLeft.Y)); } else { points.Add(bottomLeft); } points.Add(endPoint); points.Reverse(); int leaderId = AutoCad.Db.Leader.Make(points, null); AutoCad.Db.Leader.SetColor(leaderId, CadColor.BlackWhite); AutoCad.Db.Leader.SetLineWeight(leaderId, Const.LineWeight._0_15); //直交モードを復元する if (!orhtoMode) { AutoCad.Db.Database.SetOrthogonalMode(orhtoMode); } AutoCad.Command.RefreshExEx(); }
/// <summary>この図面をAutoCADの最前面に持ってくる</summary> public void Focus() { WindowController2.BringDrawingToTop(this.WindowHandle); }