private void btnLogin_Click(object sender, EventArgs e) { //client = WcfClient.CommonUntils.proxy("192.168.0.8", "8000"); client = Common.Util.Service; WcfClient.pdmService.ResultObject obj = client.Login(txtUserName.Text.Trim(), txtPassWord.Text.Trim()); if (obj.AckResult) { if (DialogResult.OK == MessageBox.Show("用户登录成功!", "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Information)) { Common.Util.UserName = txtUserName.Text.Trim(); //COM方式获取AutoCAD应用程序对象 AcadApplication acadApp = (AcadApplication)services.Application.AcadApplication; var menuCount = acadApp.MenuGroups.Item(0).Menus.Item(0).Count; for (int i = 0; i < menuCount; i++) { acadApp.MenuGroups.Item(0).Menus.Item(0).Item(i).Enable = true; } this.Visible = false; } } else { MessageBox.Show(obj.ErrMessage); } }
public static void Test() { AcadApplication AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.22"); AcadDocument doc = AcadApp.ActiveDocument; AcadModelSpace ms = doc.ModelSpace; AcadSelectionSets SelSets = doc.SelectionSets; //SelSets. AcadSelectionSet sles = SelSets.Add("Ssd"); sles.SelectOnScreen(); Console.WriteLine("{0}", sles.Count); List <AcadLWPolyline> curList = new List <AcadLWPolyline>(); foreach (var item in sles) { try { AcadLWPolyline PL = (AcadLWPolyline)item; if (PL.Closed) { curList.Add(PL); } } catch (Exception) { continue; } // Console.WriteLine("Length={0}", L.Length); } sles.Delete(); }
/// <summary> /// Plot with override configuration /// </summary> /// <param name="acApp">AutoCAD application</param> /// <param name="plotConfig">Plot override Configuration</param> public void Plot(AcadApplication acApp, EPlotConfig pConfig) { AcadDocuments acDocs = acApp.Documents; int opFlag = DocIndex(acDocs); if (Open(acApp)) { AcadLayout acLot = acApp.ActiveDocument.ActiveLayout; // Store plot configuration of active layout double numerator, denominator; EPlotConfig strConfig = new EPlotConfig( acLot.ConfigName, acLot.CanonicalMediaName, acLot.StyleSheet, acLot.PlotType, acLot.StandardScale, acLot.UseStandardScale, 1, acLot.CenterPlot, acLot.PlotRotation, false, acLot.ScaleLineweights);//, acLot.PlotOrigin); acLot.GetCustomScale(out numerator, out denominator); try { // Setting layout for plot acLot.ConfigName = pConfig.Plotter; acLot.CanonicalMediaName = pConfig.CanonicalMediaName; acLot.StyleSheet = pConfig.PlotStyleTable; acLot.PlotType = pConfig.PlotType; acLot.StandardScale = pConfig.StandardScale; acLot.UseStandardScale = pConfig.UseStandardScale; // NOTE: ----------------------------------------------------- // ROTATION AUTOMATICALLY FEATURE WILL BE WRITTEN IN NEXT TIME // ----------------------------------------------------------- acLot.PlotRotation = pConfig.PlotRotation; acLot.ScaleLineweights = pConfig.IsScaleLineweight; //acLot.PlotOrigin = pConfig.PlotOrigin; acLot.SetCustomScale(pConfig.CustomScale, 1); // Update plot config then Plot acLot.RefreshPlotDeviceInfo(); acApp.ActiveDocument.Plot.PlotToDevice(); } catch { } // Restore layout setting of plot acLot.ConfigName = strConfig.Plotter; acLot.CanonicalMediaName = strConfig.CanonicalMediaName; acLot.StyleSheet = strConfig.PlotStyleTable; acLot.PlotType = strConfig.PlotType; acLot.StandardScale = strConfig.StandardScale; acLot.UseStandardScale = strConfig.UseStandardScale; acLot.PlotRotation = strConfig.PlotRotation; acLot.ScaleLineweights = strConfig.IsScaleLineweight; //acLot.PlotOrigin = strConfig.PlotOrigin; acLot.SetCustomScale(numerator, denominator); } // If sheet is not opened initially, closing this after plot finish if (opFlag == -1 && DocIndex(acDocs) != -1) { acDocs.Item(DocIndex(acDocs)).Close(false); } }
public XMManagerControl() { InitializeComponent(); AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application"); AcadApp.BeginOpen += new _DAcadApplicationEvents_BeginOpenEventHandler(AcadApp_BeginOpen); AcadApp.EndOpen += new _DAcadApplicationEvents_EndOpenEventHandler(AcadApp_EndOpen); BtnOpenCAD.Command = new CHXQ.XMManager.Command.OpenCADDocment(); BtnOpenCAD.CommandParameter = this; BtnSave.Command = new CHXQ.XMManager.Command.SaveCommand(); BtnSave.CommandParameter = this; BtnSave.ButtonStyle = DevComponents.DotNetBar.eButtonStyle.ImageAndText; BtnSave.UseSmallImage = true; pXMWDDirTreeView = new XMDirTreeView(); pXMWDDirTreeView.Dock = DockStyle.Fill; splitContainer1.Panel1.Controls.Add(pXMWDDirTreeView); pXMWDDirTreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(pXMDirTreeView_NodeMouseClick); pWDFileListView = new FileListView(); pWDFileListView.Dock = DockStyle.Fill; panel3.Controls.Add(pWDFileListView); pXMTreeview = new XMTreeview(); pXMTreeview.Dock = DockStyle.Fill; panelEx1.Controls.Add(pXMTreeview); pXMTreeview.LoadData(); pXMTreeview.ExpandAll(); pXMTreeview.XMTreeViewOperEvent += new XMTreeViewEventHandler(pXMTreeview_XMTreeViewOperEvent); superTabControl1.SelectedTabIndex = 0; }
public void AddToolBar() { //获取当前运行的程序集 System.Reflection.Module myModule = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0]; //获取当前运行的程序集的完整路径(包含文件名) string modulePath = myModule.FullyQualifiedName; //获取去除文件名后程序集的路径,即程序集所在的文件夹 modulePath = modulePath.Substring(0, modulePath.LastIndexOf("\\")); //COM方式获取AutoCAD应用程序对象 AcadApplication acadApp = (AcadApplication)Application.AcadApplication; //获取当前菜单组,用于加入工具栏 AcadMenuGroup currMenuGroup = acadApp.MenuGroups.Item(0); //为AutoCAD添加一个新的工具栏,并设置标题为"我的工具栏" AcadToolbar tbModify = currMenuGroup.Toolbars.Add("我的工具栏"); //在新建的工具栏中添加一个"复制"按钮,以调用复制命令 AcadToolbarItem button0 = tbModify.AddToolbarButton("", "复制", "复制对象", "_Copy ", Type.Missing); //设置复制按钮的图片 button0.SetBitmaps(modulePath + "\\Resources\\Copy.bmp", modulePath + "\\Resources\\Copy.bmp"); //'添加一个"删除"按钮,以调用删除命令 AcadToolbarItem button1 = tbModify.AddToolbarButton("", "删除", "从图形删除对象", "_Erase ", Type.Missing); //设置删除按钮的图片 button1.SetBitmaps(modulePath + "\\Resources\\Erase.bmp", modulePath + "\\Resources\\Erase.bmp"); //添加一个"移动"按钮,以调用删除命令 AcadToolbarItem button2 = tbModify.AddToolbarButton("", "移动", "移动对象", "_Move ", Type.Missing); //设置移动按钮的图片 button2.SetBitmaps(modulePath + "\\Resources\\Move.bmp", modulePath + "\\Resources\\Move.bmp"); //添加一个"旋转"按钮,以调用旋转命令 AcadToolbarItem button3 = tbModify.AddToolbarButton("", "旋转", "绕基点旋转对象", "_Rotate ", Type.Missing); //设置旋转按钮的图片 button3.SetBitmaps(modulePath + "\\Resources\\Rotate.bmp", modulePath + "\\Resources\\Rotate.bmp"); //添加一个弹出按钮,该按钮只用来附着下面的画图工具栏 AcadToolbarItem FlyoutButton = tbModify.AddToolbarButton("", "画图工具", "画图工具", " ", true); //创建第二个工具栏。该工具栏将通过弹出按钮附加到第一个工具栏。 AcadToolbar tbDraw = currMenuGroup.Toolbars.Add("画图工具栏"); //下面的语句分别在工具栏上设置绘制圆、直线、多段线、矩形的按钮 AcadToolbarItem button4 = tbDraw.AddToolbarButton("", "圆", "用指定半径创建圆", "_Circle ", Type.Missing); button4.SetBitmaps(modulePath + "\\Resources\\Circle.bmp", modulePath + "\\Resources\\Circle.bmp"); AcadToolbarItem button5 = tbDraw.AddToolbarButton("", "直线", "创建直线段", "_Line ", Type.Missing); button5.SetBitmaps(modulePath + "\\Resources\\Line.bmp", modulePath + "\\Resources\\Line.bmp"); AcadToolbarItem button6 = tbDraw.AddToolbarButton("", "多段线", "创建二维多段线", "_Pline ", Type.Missing); button6.SetBitmaps(modulePath + "\\Resources\\Polyline.bmp", modulePath + "\\Resources\\Polyline.bmp"); AcadToolbarItem button7 = tbDraw.AddToolbarButton("", "矩形", "创建矩形多段线", "_Rectangle ", Type.Missing); button7.SetBitmaps(modulePath + "\\Resources\\Rectangle.bmp", modulePath + "\\Resources\\Rectangle.bmp"); //将第二个工具栏附着到第一个工具栏的弹出按钮上 FlyoutButton.AttachToolbarToFlyout(currMenuGroup.Name, tbDraw.Name); //显示第一个工具栏 tbModify.Visible = true; //隐藏第二个工具栏 tbDraw.Visible = false; }
static void Main(string[] args) { AutoCAD.AcadApplication app; app = new AcadApplication(); app.Visible = true; Console.Read(); }
/// <summary> /// /// </summary> public static void OpenAutoCAD() { try { AcadApp = (AcadApplication)Marshal.GetActiveObject("Autocad.Application"); AcadDoc = AcadApp.ActiveDocument; } catch { try { AcadApp = new AcadApplication(); AcadApp.Visible = true; OpenFileDialog openFileDialog = new OpenFileDialog() { Multiselect = true, Filter = "Abrir Plantilla|*.dwg", Title = "Archivo dwg" }; openFileDialog.ShowDialog(); if (openFileDialog != null) { AcadDoc = AcadApp.Documents.Add(openFileDialog.FileName); } } catch { NotificadorErrores?.Invoke("Error inesperado."); } } }
static void Main(string[] args) { Console.WriteLine("Hello World!"); AcadApplication AcadApp = default; try { // Getting running AutoCAD instance by Marshalling by passing Programmatic ID as a string, AutoCAD.Application is the Programmatic ID for AutoCAD. AcadApp = (AcadApplication)Marshal3.GetActiveObject("AutoCAD.Application"); AcadApp.Visible = true; AcadApp.ActiveDocument.Utility.Prompt($"Hello World\n{DateTime.Now.ToLongDateString()}\n"); } catch (Exception ex) { Console.WriteLine(ex); } finally { // System.Runtime.InteropServices.Marshal.ReleaseComObject(AcadApp); AcadApp = null; } }
// Zoom via COM private static void ZoomWin2( Editor ed, Point3d min, Point3d max ) { AcadApplication app = (AcadApplication)Application.AcadApplication; double[] lower = new double[3] { min.X, min.Y, min.Z }; double[] upper = new double[3] { max.X, max.Y, max.Z }; app.ZoomWindow(lower, upper); }
public Form1() { a = new AcadApplicationClass(); a.Visible = true;//使AutoCAD可见 InitializeComponent(); }
/// <summary> /// Opening sheet on acad application /// </summary> /// <param name="acApp"></param> internal bool Open(AcadApplication acApp) { try { AcadDocuments acDocs = acApp.Documents; int id = DocIndex(acDocs); if (id != -1) { // If file is not opened, switch to it acDocs.Item(id).Activate(); } else { // If file is not opened, opening it in read-only acDocs.Open(Path, true); } // Switch to layout AcadLayouts acLots = acApp.ActiveDocument.Layouts; foreach (AcadLayout acLot in acLots) { if (acLot.Name == this.Name) { acApp.ActiveDocument.ActiveLayout = acLot; break; } } return(true); } catch { return(false); } }
/// <summary> /// 新建AutoCAD进程 /// </summary> /// <returns></returns> private static AcadApplication NewCAD() { AcadApplication app=null; bool flag = false; while (app == null) { try { app = new AcadApplicationClass(); } catch { } } while (!flag) { try { app.Visible = false; app.ActiveDocument.Close(); flag = true; } catch { flag = false; } } return app; }
static void Main(string[] args) { // Start an AutoCAD instance AcadApplication acad = new AcadApplication(); Console.WriteLine("AutoCAD started!"); //Open an AxDbDocument object obj = acad.GetInterfaceObject("ObjectDBX.AxDbDocument.22"); //Acad2018 AxDbDocument doc = obj as AxDbDocument; if (doc == null) { Console.WriteLine("Cannot open AxDbDocument for some reason!"); return; } else { doc.Open(@"a:\Dropbox\Infratools\2_Presentation\4.0 Automation\Dictionary\test.dwg"); List<string> dicts = AcDictToList(doc.Database); Console.WriteLine(dicts.Count + " Dictionaries found."); foreach (string s in dicts) Console.WriteLine(s); } //Get drawing information //Console.WriteLine("Entities in ModelSpace: " + doc.ModelSpace.Count); //You can make changes to the entities in AxDbDocument and save the changes back to the drawing file. //doc.Save(); doc = null; acad.Quit(); Console.Read(); }
public void AddMenuContent() { try { AcadApplication acadApp = (AcadApplication)Application.AcadApplication; //添加根菜单 AcadPopupMenu pMenu = acadApp.MenuGroups.Item(0).Menus.Add("psw二次开发"); ////添加子菜单项,多级 //AcadPopupMenu cMenu = pMenu.AddSubMenu(pMenu.Count + 1, "液压插件"); //AcadPopupMenuItem cMenuItem0 = cMenu.AddMenuItem(cMenu.Count + 1, "插件1", "hydrPlugin1\n"); //AcadPopupMenuItem cMenuItem1 = cMenu.AddMenuItem(cMenu.Count + 1, "插件2", "hydrPlugin2\n"); //AcadPopupMenuItem cMenuItem2 = cMenu.AddMenuItem(cMenu.Count + 1, "插件3", "hydrPlugin3\n"); //添加分隔条 //pMenu.AddSeparator(pMenu.Count + 1); //添加子菜单项,单级 AcadPopupMenuItem cMenu2 = pMenu.AddMenuItem(pMenu.Count + 1, "建筑插件", "architecturePlugin\n"); pMenu.InsertInMenuBar(acadApp.MenuBar.Count + 1); } catch (System.Exception ex) { Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString()); } }
public void openDWG(string dwgpath) { if (dwgpath == null) { MessageBox.Show("请先读取CAD文件"); return; } const string progID = "AutoCAD.Application.18.0"; AcadApplication AcadApp; AcadDocument AcadDoc; try { AcadApp = (AcadApplication)Marshal.GetActiveObject(progID); AcadDoc = AcadApp.ActiveDocument; } catch { AcadApp = new AcadApplication(); AcadDoc = AcadApp.Documents.Open(dwgpath, null, null); } AcadApp.Application.Visible = true; Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption); }
private void btnCircle_Click(object sender, EventArgs e) { // Getting running AutoCAD instance by Marshalling by passing Programmatic ID as a string, AutoCAD.Application is the Programmatic ID for AutoCAD. AcadApp = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application"); // Now AcadApp has the reference to the running AutoCAD instance, AcadApp object acts as a port for accessing running instance of AutoCAD. // Syntax for creating circle in AutoCAD // AcadApp.ActiveDocument.ModelSpace.AddCircle(CenterOfCircle, RadiusOfCircle); // // AcadApp - Reference to the running instance of AutoCAD. // ActiveDocument - Represents the current working drawing in AutoCAD. // ModelSpace - Work Area in the current drawing. // AddCricle - Method, which adds a circle to the modelspace of the current drawing using the CenterPoint and Radius. // CenterOfCircle - 3 Dimensional double array variable holds the center point of the circle in the X, Y and Z axis. // RadiusOfCircle - Double variable holds the radius of circle. // Definfing the center point for the circle, in this example, we are using origin(0,0,0) as the center of circle. double[] CenterOfCircle = new double[3]; CenterOfCircle[0] = 0; CenterOfCircle[1] = 0; CenterOfCircle[2] = 0; // Defining radius of circle from the user input. double RadiusOfCircle = Convert.ToDouble(txtRadius.Text.Trim()); // Adding Circle to the modelspace and getting reference to the circle created. Circle = AcadApp.ActiveDocument.ModelSpace.AddCircle(CenterOfCircle, RadiusOfCircle); }
public static void Auto_Mate() { AcadApplication acAppObj = null; const String strProgId = "AutoCAD.Application.22.0"; // get a running instance of autocad try { acAppObj = (AcadApplication)Marshal.GetActiveObject(strProgId); } catch // an error occurs if no instance is running { try { // create a new instance of autocad acAppObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); } catch { // if an instandce is not created then message and exit System.Windows.Forms.MessageBox.Show("Instance of 'AutoCAD.Application' could not be created"); return; } } // display the application and return the name and the version acAppObj.Visible = true; System.Windows.Forms.MessageBox.Show("Now Running " + acAppObj.Name + " Version " + acAppObj.Version); // get the active document AcadDocument acDoc = acAppObj.ActiveDocument; // optionally, load your assembly and start command }
/// <summary> /// Plot with override plot configuration /// </summary> /// <param name="pConfig"></param> public void Plot(AcadApplication acApp, EPlotConfig pConfig) { // Sort sheetset object[] sets = new object[m_sets.Count]; foreach (object obj in m_sets) { if (obj is Sheet) { Sheet s = obj as Sheet; sets[s.Handle.Order] = obj; } else { SheetSet s = obj as SheetSet; sets[s.Handle.Order] = obj; } } // Plot without override config foreach (object obj in sets) { if (obj is Sheet) { Sheet s = obj as Sheet; s.Plot(acApp, pConfig); } else { SheetSet s = obj as SheetSet; s.Plot(acApp, pConfig); } } System.GC.Collect(); }
private void UploadCurCAD(AcadApplication AcadApp, IXMRK pXMRK) { AcadDocument AcadDoc = AcadApp.ActiveDocument; Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption); AcadDoc.Save(); string path = AcadDoc.Path; string DocmantPath = AcadDoc.FullName; //string strPath = HR.Utility.CommonConstString.STR_TempPath + "\\" + pXMRK.ID + ".dwg"; string TempstrPath = HR.Utility.CommonConstString.STR_TempPath + pXMRK.TZBH + ".dwg"; AcadDoc.SaveAs(TempstrPath, AcSaveAsType.ac2000_dwg, null); AcadDoc = AcadApp.ActiveDocument; AcadDoc.Close(); Application.DoEvents(); /* if (System.IO.File.Exists(strPath)) * { * System.IO.File.Delete(strPath); * } * System.IO.File.Copy(TempstrPath, strPath);*/ pXMRK.UploadCAD(TempstrPath); }
public override void Execute(DevComponents.DotNetBar.ICommandSource commandSource) { XMManagerControl pXMManagerControl = commandSource.CommandParameter as XMManagerControl; IXMRK pXMRK = pXMManagerControl.GetXMRK(); bool IsNewXMYD = pXMRK.ID == -1; if (pXMRK.GetIsGeoCange() && !IsNewXMYD) { AcadApplication AcadApp = pXMManagerControl.AcadApp; UploadCurCAD(AcadApp, pXMRK); } try { pXMRK.Save(); if (IsNewXMYD) { AcadApplication AcadApp = pXMManagerControl.AcadApp; UploadCurCAD(AcadApp, pXMRK); } ISTPoint MinPoint = pXMRK.STGeometry.GetMinPoint(); ISTPoint MaxPoint = pXMRK.STGeometry.GetMaxPoint(); pXMRK.UpdateMapServerCache(MinPoint.X, MinPoint.Y, MaxPoint.X, MaxPoint.Y); MessageBox.Show("保存成功", "消息", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } catch (Exception ex) { MessageBox.Show(ex.Message, "保存出错", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
void OpenCad() { const string strProgId = "AutoCAD.Application"; // Get a running instance of AutoCAD获取正在运行的AutoCAD实例; try { acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId); } catch // An error occurs if no instance is running没有正在运行的实例时出错; { try { // Create a new instance of AutoCAD创建新的AutoCAD实例; acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); } catch { // If an instance of AutoCAD is not created then message and exit创建新实例不成功就显示信息并退出; MessageBox.Show("创建新实例不成功"); return; } } }
public Connector() { this._acAppComObj = null; this._strProgId = ""; this._customDllPath = ""; this._isAssemblyLoaded = false; }
public void CreateRibbon() { AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as AcadApplication; var doc = Application.DocumentManager.MdiActiveDocument; if (ComponentManager.Ribbon == null) { MessageBox.Show($"请先通过 RIBBON 命令打开选项卡,然后重复 {CmdStartRibbon} 命令。", @"提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } var ed = Application.DocumentManager.MdiActiveDocument.Editor; RibbonControl ribCntrl = ComponentManager.Ribbon; // ribCntrl can also be RibbonServices.RibbonPaletteSet.RibbonControl, this class can be found in AcWindows.dll; // 如果已经加载,则显示出来即可 var existingRibbonTab = ribCntrl.Tabs.FirstOrDefault(r => r.Id == AddinOptions.TabId && r.Title == AddinOptions.TabTitle && r.Name == AddinOptions.TabName); if (existingRibbonTab != null) { eZcad.Utility.Utils.SendCommandSync("Ribbon "); // doc.SendStringToExecute("Ribbon ", false, false, false); // AutoCAD 2014 // ed.Command(new object[] { "Ribbon" }); // AutoCAD 2016 existingRibbonTab.IsActive = true; return; } else { //Add the tab RibbonTab ribTab = new RibbonTab { Title = AddinOptions.TabTitle, Id = AddinOptions.TabId, Name = AddinOptions.TabName }; ribCntrl.Tabs.Add(ribTab); // try { AddControls(ribTab); } catch (Exception ex) { MessageBox.Show(ex.Message, "选项卡工具加载出错\r\n" + ex.StackTrace, MessageBoxButtons.OK, MessageBoxIcon.Error); } //set as active tab ribTab.IsActive = true; } eZcad.Utility.Utils.SendCommandSync("Ribbon "); //doc.SendStringToExecute("Ribbon ", false, false, false); // AutoCAD 2014 //ed.Command(new object[] { "Ribbon" }); // AutoCAD 2016 }
public void Test() { DocumentCollection acDocColl = Application.DocumentManager; Editor acEd = Application.DocumentManager.MdiActiveDocument.Editor; Window wind = Application.MainWindow; AcadApplication acadApplication = Application.AcadApplication as AcadApplication; AcadMenuBar acadMenuBa = Application.MenuBar as AcadMenuBar; ContextMenuExtension acCtxMenuExten = new ContextMenuExtension(); /*Document acNewDoc = acDocColl.Add("acac.dwg"); * Document acNewDoc2 = acDocColl.Add("aca.dwg");*/ /* foreach (Document acDoc in acDocColl) * { * * acEd.WriteMessage($"\n{acDoc.Name}"); * * }*/ /*wind.WindowState = Window.State.Minimized; * * wind.Text = "学习学习再学习"; * wind.SetLocation(new System.Drawing.Point(200, 200)); * wind.SetSize(new System.Drawing.Size(500, 500));*/ /*Application.ShowAlertDialog($"{acadApplication.Width},{acadApplication.Height}");*/ /*foreach ( AcadPopupMenu pm in acadMenuBa) * { * * acEd.WriteMessage($"\n{pm.Name}"); * * }*/ /*AcadPopupMenu pm = acadMenuBa.Item(0); * pm.AddMenuItem(0, "画直线", "Line");*/ acCtxMenuExten.Title = "自定义菜单"; MenuItem acNewMenuItem = new MenuItem("创建新文档"); acNewMenuItem.Click += (o, e) => { Document acNewDoc = acDocColl.Add("acac.dwg"); }; acCtxMenuExten.MenuItems.Add(acNewMenuItem); /*Application.AddDefaultContextMenuExtension(acCtxMenuExten);*/ /*Application.AddObjectContextMenuExtension(RXObject.GetClass(typeof(Line)), acCtxMenuExten);*/ }
private void Btn1_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.ShowDialog(); string filepath = ofd.FileName; AcadApplication app = new AcadApplication { Visible = true }; AcadDocument doc = app.Documents.Open(filepath, null, null); }
private void AutoRead_Click(object sender, EventArgs e) { // Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor; //Database db = HostApplicationServices.WorkingDatabase; tAcadApplication = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application"); AcadDocument doc = tAcadApplication.ActiveDocument; double[] d2 = new double[3] { 0, 0, 0 }; var d = doc.Utility.GetPoint(d2, "Select a point:"); }
//加载菜单栏 public void AddMenu() { Document doc = Application.DocumentManager.MdiActiveDocument; doc.Editor.WriteMessage("添加菜单栏成功!>>>>>>>>>>>>>>"); AcadApplication acadApp = Application.AcadApplication as AcadApplication; //创建建菜单栏的对象 AcadPopupMenu myMenu = null; // 创建菜单 if (myMenu == null) { // 菜单名称 myMenu = acadApp.MenuGroups.Item(0).Menus.Add("实用工具箱"); myMenu.AddMenuItem(myMenu.Count, "批量重命名PDF", "THTM "); myMenu.AddMenuItem(myMenu.Count, "测试程序", "CSCS "); myMenu.AddMenuItem(myMenu.Count, "标高及桩号初始化", "GLCSH "); myMenu.AddMenuItem(myMenu.Count, "两行数值相减", "SZXJ "); myMenu.AddMenuItem(myMenu.Count, "生成节点桩号", "JDZH "); myMenu.AddMenuItem(myMenu.Count, "拾取线生成标高", "QXBG "); myMenu.AddMenuItem(myMenu.Count, "选点生成桩号及标高", "QDZHBG "); myMenu.AddSeparator(myMenu.Count); //加入分割符号 //开始加子菜单栏 AcadPopupMenu subMenu = myMenu.AddSubMenu(myMenu.Count, "图号重排"); //子菜单对象 subMenu.AddMenuItem(myMenu.Count, "按行重排", "THCP R "); subMenu.AddMenuItem(myMenu.Count, "按列重排", "THCP C "); //结束加子菜单栏 } // 菜单是否显示 看看已经显示的菜单栏里面有没有这一栏 bool isShowed = false; //初始化没有显示 foreach (AcadPopupMenu menu in acadApp.MenuBar) //遍历现有所有菜单栏 { if (menu == myMenu) { isShowed = true; break; } } // 显示菜单 加载自定义的菜单栏 if (!isShowed) { myMenu.InsertInMenuBar(acadApp.MenuBar.Count); } }
public static void LogOut() { AcadApplication acadApp = (AcadApplication)services.Application.AcadApplication; var menuCount = acadApp.MenuGroups.Item(0).Menus.Item(0).Count; for (int i = 0; i < menuCount; i++) { if (i != 0) { acadApp.MenuGroups.Item(0).Menus.Item(0).Item(i).Enable = false; } } }
// Zoom by sending a command private static void ZoomWin3( Editor ed, Point3d min, Point3d max ) { string lower = min.ToString().Substring( 1, min.ToString().Length - 2 ); string upper = max.ToString().Substring( 1, max.ToString().Length - 2 ); string cmd = "_.ZOOM _W " + lower + " " + upper + " "; // Call the command synchronously using COM AcadApplication app = (AcadApplication)Application.AcadApplication; app.ActiveDocument.SendCommand(cmd); // Could also use async command calling: //ed.Document.SendStringToExecute( // cmd, true, false, true //); }
/// <summary> /// 同步发送命令 /// </summary> /// <param name="command"></param> public static void SendCommandSync(string command) { /* * 使用SendStringToExecute()方法执行命令是异步的(同步是阻塞的,就是你做了这件事情,没做完就做不了别的事情了,异步就是做了做一件事情没做完,就可以去做别的事情了),直到.NET命令结束,所调用的AutoCAD命令才被执行。如果需要立即执行命令(同步),我们应该: * Commands executed with SendStringToExecute are asynchronous and are not invoked until the .NET command has ended. If you need to execute a command immediately (synchronously), you should: * 使用COM Automation库提供的acadDocument.SendCommand()方法。放心,.NET COM互操作程序集可以访问COM Automation库; * 对于AutoCAD本地命令,以及由ObjectARX或.NET API定义的命令,调用(P/Invoke)非托管的acedCommand()方法或acedCmd()方法; * 对于由AutoLISP定义的命令,调用(P/Invoke)非托管的acedInvoke()方法; */ AcadApplication acadApp = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as AcadApplication; acadApp.ActiveDocument.SendCommand(command); }
public static void CreateAutoCADObject() { try { CloseAllInstance(); gbl_app = new AcadApplication(); gbl_doc = gbl_app.ActiveDocument; gbl_app.Application.Visible = true; gbl_modSpace = (AcadModelSpaceClass)gbl_doc.ModelSpace; //MessageBox.Show(gbl_app.Path); gbl_doc.Linetypes.Load("HIDDEN", "acad.lin"); gbl_doc.Linetypes.Load("CENTER", "acad.lin"); //Other Objects Layer SwitchLayer = CADAutomation.gbl_doc.Layers.Add("Switch110Layer"); SwitchLayer.color = AcColor.acGreen; CADAutomation.gbl_doc.ActiveLayer = SwitchLayer; //Layer For Donuts TerminalsLayer = CADAutomation.gbl_doc.Layers.Add("TerminalsLayer"); TerminalsLayer.color = AcColor.acRed; //Layer Termination Points TerminationPoints = CADAutomation.gbl_doc.Layers.Add("TerminationPoints"); TerminationPoints.color = AcColor.acWhite; } catch (System.Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 导出线路到CAD /// </summary> /// <param name="linecode">线路编号数组</param> public void ToDwg(string[] linecode) { try { f.SetText("处理中请等待......"); f.Show(); cad = AutoCADConnector(); cad.ActiveDocument.SendCommand("-units 2 8 1 0 0 n "); ArrayList nlist = getLineCode(linecode); if (cad != null) { cad.ActiveDocument.Layers.Add("line"); cad.ActiveDocument.Layers.Add("gt"); cad.ActiveDocument.Layers.Add("gth"); cad.ActiveDocument.Layers.Add("text"); for (int n = 0; n < nlist.Count; n++) { f.SetText("正在处理线路" + nlist[n].ToString()); IList<PS_gt> list = Client.ClientHelper.PlatformSqlMap.GetListByWhere<PS_gt>("where LineCode='" + nlist[n].ToString() + "' order by gtcode"); IList<PS_gt> newlist = ReLoadList(list); //PS_xl xl = Client.ClientHelper.PlatformSqlMap.GetOne<PS_xl>("where LineCode='" + nlist[n].ToString() + "'"); IList<PJ_05jcky> kylist = Client.ClientHelper.PlatformSqlMap.GetListByWhere<PJ_05jcky>("where LineID='" + nlist[n].ToString() + "' order by jckyID"); IList<PJ_05jcky> newkylist = ReLoadKYList(kylist); if (newlist.Count > 1) { CallCAD(cad, newlist, newkylist); } } cad.Visible = true; cad.ActiveDocument.SendCommand("Z e "); cad.ActiveDocument.SendCommand("audit y "); f.Close(); } else { f.Close(); } } catch (Exception e2) { MessageBox.Show("请安装AutoCAD2009或以上版本。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void Open() { const string strProgId = "AutoCAD.Application"; //获取正在运行的AutoCAD实例; try { acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId); } catch //没有正在运行的实例时出错; { try { //创建新的AutoCAD实例; acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); } catch { //创建新实例不成功就显示信息并退出; //MessageBox.Show("创建新实例不成功"); return; } } }
public void CallCAD(AcadApplication cad, IList<PS_gt> list, IList<PJ_05jcky> kylist) { try { double[] col = new double[list.Count * 3]; int k = 0; for (int i = 0; i < list.Count; i++) { col[k] = Convert.ToDouble(list[i].gtLon.ToString("0.########")); col[k + 1] = Convert.ToDouble(list[i].gtLat.ToString("0.########")); col[k + 2] = 0; k = k + 3; } AcadPolyline ple = cad.ActiveDocument.ModelSpace.AddPolyline(col); ple.ConstantWidth = 0; ple.Layer = "line"; Color c1 = ColorTranslator.FromHtml(color_str); AcadAcCmColor color = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.17"); color.SetRGB(c1.R, c1.G, c1.B); ple.TrueColor = color; cad.Application.Update(); int gtnum = 0; for (int i = 0; i < list.Count; i++) { //if () continue;//跳过借杆 bool isjg = list[i].gtJg == "是"; double[] pnt = new double[3]; pnt[0] = Convert.ToDouble(list[i].gtLon.ToString("0.########")); pnt[1] = Convert.ToDouble(list[i].gtLat.ToString("0.########")); pnt[2] = 0; gtnum++; bool hasbyq = false; PS_tq tq = Client.ClientHelper.PlatformSqlMap.GetOne<PS_tq>(" where gtID='" + list[i].gtID + "'"); if (tq != null) { //PS_tqbyq byq = Client.ClientHelper.PlatformSqlMap.GetOne<PS_tqbyq>(" where tqID='" + tq.tqID + "'"); //if (byq != null) //{ //} hasbyq = true; PS_gt gt0 = null; double a = 0; if (i > 0) { gt0 = list[i - 1]; a = getAndgle(gt0, list[i]); } else if (list.Count > 1) { a = getAndgle(list[0], list[1]); } if (double.IsNaN(a)) a = 0; cad.ActiveDocument.ModelSpace.InsertBlock(pnt, Application.StartupPath + "\\byq.dwg", 0.3, 0.3, 1, a * Math.PI / 180, 0); } if (isjg) continue; bool isbtgt = false; if (i < list.Count - 1) { if (list[i + 1].gtSpan < 20) isbtgt = true;//如果下一杆塔的档距小于20作为变台杆塔,不与显示 } if (hasbyq || isbtgt) { continue; } else { AcadCircle cirz = cad.ActiveDocument.ModelSpace.AddCircle(pnt, 0.00005 * zoom);//杆塔 cirz.Layer = "gt"; cirz.TrueColor = color; } string gg = list[i].gtHeight.ToString("##"); pnt[0] += 0.00005d * zoom; AcadMText ntext = cad.ActiveDocument.ModelSpace.AddMText(pnt, 2, gg + "/" + gtnum.ToString()); pnt[0] -= 0.00005d * zoom; ntext.Height = 0.00005 * zoom; ntext.Layer = "gth"; if (i < list.Count - 1 && list[i].gtSpan > 15) { double[] n1 = new double[2]; n1[0] = Convert.ToDouble(list[i].gtLon); n1[1] = Convert.ToDouble(list[i].gtLat); double[] n2 = new double[2]; n2[0] = Convert.ToDouble(list[i + 1].gtLon); n2[1] = Convert.ToDouble(list[i + 1].gtLat); double[] n = new double[3]; n[0] = (n1[0] + n2[0]) / 2; n[1] = (n1[1] + n2[1]) / 2; n[2] = 0; AcadMText mtext = cad.ActiveDocument.ModelSpace.AddMText(n, 2, list[i].gtSpan.ToString("#") + "M"); mtext.Height = 0.00005 * zoom; mtext.Layer = "text"; } for (int j = 0; j < kylist.Count; j++) { if (kylist[j].kygh == gtnum.ToString()) { PointF p1 = new PointF((float)pnt[0], (float)pnt[1]); PointF p2 = new PointF((float)list[i + 1].gtLon, (float)list[i + 1].gtLat); double x = pnt[0] > (double)list[i + 1].gtLon ? pnt[0] : (double)list[i + 1].gtLon; double y = pnt[1] < (double)list[i + 1].gtLat ? pnt[1] : (double)list[i + 1].gtLat; PointF p0 = new PointF((float)x, (float)y); double[] ins = new double[3]; ins[0] = (p1.X + p2.X) / 2; ins[1] = (p1.Y + p2.Y) / 2; ins[2] = 0; double ss = 0; if (p1.Y < p2.Y) { ss = getAngle(p1, p2, p0); } else { ss = getAngle(p2, p1, p0); } string block = getBlock(kylist[j].kymc); cad.ActiveDocument.ModelSpace.InsertBlock(ins, Application.StartupPath + "\\" + block, 1, 1, 1, (ss + 90) * Math.PI / 180, 0); ins[1] = ins[1] + 0.1; AcadMText kytext = cad.ActiveDocument.ModelSpace.AddMText(ins, 1, kylist[j].kymc); kytext.Height = 0.00005 * zoom; kytext.Layer = "text"; } } } TX_Point tp = null; tp = Client.ClientHelper.PlatformSqlMap.GetOneByKey<TX_Point>(list[0].LineCode); if (tp != null) { double[] ins = new double[3]; ins[0] = Math.Round(Convert.ToDouble(tp.x), 8) * zoom; ins[1] = Math.Round(Convert.ToDouble(tp.y), 8) * zoom; ins[2] = 0; AcadMText text = cad.ActiveDocument.ModelSpace.AddMText(ins, 2, tp.Text); text.Height = 0.0001 * zoom; text.Layer = "text"; } else { //线路名称放置最后一杆塔上 PS_xl xl = Client.ClientHelper.PlatformSqlMap.GetOne<PS_xl>(" where LineCode='" + list[0].LineCode + "'"); double[] ins = new double[3]; ins[0] = Convert.ToDouble(list[list.Count - 1].gtLon.ToString("0.########")); ins[1] = Convert.ToDouble(list[list.Count - 1].gtLat.ToString("0.########")); ins[2] = 0; AcadMText text = cad.ActiveDocument.ModelSpace.AddMText(ins, 2, xl.LineName); text.Height = 0.0001 * zoom; text.Layer = "text"; ins[1] = ins[1] + 0.3; AcadMText text2 = cad.ActiveDocument.ModelSpace.AddMText(ins, 5, xl.WireType); text2.Height = 0.0001 * zoom; text2.Layer = "text"; } cad.Application.Update(); } catch (Exception e) { MessageBox.Show(e.Message); }; }
/// <summary> /// 导出线路到CAD /// </summary> /// <param name="linecode">线路编号</param> /* public void ToDwg(string linecode) { try { f.SetText("处理中请等待......"); f.Show(); cad = AutoCADConnector(); cad.ActiveDocument.SendCommand("-units 2 8 1 0 0 n "); if (cad != null) { cad.ActiveDocument.Layers.Add("line"); cad.ActiveDocument.Layers.Add("gt"); cad.ActiveDocument.Layers.Add("gth"); cad.ActiveDocument.Layers.Add("text"); IList<PS_gt> list = Client.ClientHelper.PlatformSqlMap.GetListByWhere<PS_gt>("where LineCode='" + linecode + "' order by gtcode"); IList<PS_gt> newlist = ReLoadList(list); if (newlist.Count > 1) { CallCAD(cad, newlist); } cad.Visible = true; cad.ActiveDocument.SendCommand("Z e "); cad.ActiveDocument.SendCommand("audit y "); f.Close(); } else { f.Close(); } } catch (Exception e2) { MessageBox.Show("请安装AutoCAD2009或以上版本。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } }*/ public AcadApplication AutoCADConnector() { AcadApplication cad; try { cad = (AcadApplication)Marshal.GetActiveObject("AutoCAD.Application.17"); cad.Visible = false; } catch { try { cad = new AcadApplicationClass(); cad.Visible = false; return cad; } catch (Exception e2) { MessageBox.Show("请安装AutoCAD2009或以上版本。", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return null; } } return cad; }
private DwgDirectXManager() { oHost = new OdaHostAppClass(); oApp = oHost.Application; }
void OpenCad() { const string strProgId = "AutoCAD.Application"; // Get a running instance of AutoCAD获取正在运行的AutoCAD实例; try { acAppComObj = (AcadApplication)Marshal.GetActiveObject(strProgId); } catch // An error occurs if no instance is running没有正在运行的实例时出错; { try { // Create a new instance of AutoCAD创建新的AutoCAD实例; acAppComObj = (AcadApplication)Activator.CreateInstance(Type.GetTypeFromProgID(strProgId), true); } catch { // If an instance of AutoCAD is not created then message and exit创建新实例不成功就显示信息并退出; MessageBox.Show("创建新实例不成功"); return; } } }
/// <summary> /// 替换装配图中的明细表中的编号 /// </summary> /// <param name="entity"></param> /// <param name="acAppComObj"></param> /// <param name="ds"></param> public static void ReplaceDrawingCode(AcadEntity entity, AcadApplication acAppComObj) { if (entity.ObjectName == "AcmPartRef") { AXDBLib.AcadObject obj = entity as AXDBLib.AcadObject; McadSymbolBBMgr symbb = (McadSymbolBBMgr)acAppComObj.GetInterfaceObject("SymBBAuto.McadSymbolBBMgr"); McadBOMMgr bommgr = (McadBOMMgr)symbb.BOMMgr; oldCode = bommgr.GetPartAttribute(obj, "DESCR", false); string newCode = getByNewCode(oldCode); if (!string.IsNullOrEmpty(newCode)) bommgr.SetPartAttribute(obj, "DESCR", newCode); } }
public void CallCAD(SvgElementCollection _col, string lab, int count, AcadApplication cad) { int errid = 0; AcadEntity[] en = new AcadEntity[2]; AcadHatch wt = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); wt.color = ACAD_COLOR.acWhite; AcadHatch h; AcadHatch h2; AcadHatch h3; AcadHatch h4; AcadHatch h5; //h = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid",/* "JIS_LC_20",*/ true, 0); if (CadFullType == "1") { h = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); h2 = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); h3 = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); h4 = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); h5 = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); } else { h = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0);//JIS_LC_20 //JIS_LC_20 h2 = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); h3 = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); h4 = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); h5 = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); } if (CadFullType == "2") { h.PatternScale = 0.25; h.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; } Color c_500 = ColorTranslator.FromHtml(str500kv); AcadAcCmColor color500 = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); //2006 -"AutoCAD.AcCmColor.16" color500.SetRGB(c_500.R, c_500.G, c_500.B); h.TrueColor = color500; if (CadFullType == "2") { h2.PatternScale = 0.25; h2.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; } Color c_220 = ColorTranslator.FromHtml(str220kv); AcadAcCmColor color220 = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color220.SetRGB(c_220.R, c_220.G, c_220.B); h2.TrueColor = color220; if (CadFullType == "2") { h3.PatternScale = 0.25; h3.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; } Color c_110 = ColorTranslator.FromHtml(str110kv); AcadAcCmColor color110 = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color110.SetRGB(c_110.R, c_110.G, c_110.B); h3.TrueColor = color110; if (CadFullType == "2") { h4.PatternScale = 0.25; h4.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; } Color c_66 = ColorTranslator.FromHtml(str66kv); AcadAcCmColor color66 = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color66.SetRGB(c_66.R, c_66.G, c_66.B); h4.TrueColor = color66; if (CadFullType == "2") { h5.PatternScale = 0.25; h5.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; } Color c_33 = ColorTranslator.FromHtml(str33kv); AcadAcCmColor color33 = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color33.SetRGB(c_33.R, c_33.G, c_33.B); h5.TrueColor = color33; for (int i = 0; i < _col.Count; i++) { SvgElement ele = (SvgElement)_col[i]; f.SetText("共有" + count + "个图层。正在处理" + lab + "图层。\r\n 此图层共" + _col.Count + "个图元,正在处理第" + i + "个,请等待......"); if (ele.Name == "rect") { try { RectangleElement rect = ele as RectangleElement; PointF[] points = new PointF[1]; points[0].X = rect.X; points[0].Y = rect.Y; rect.Transform.Matrix.TransformPoints(points); double[] col = new double[15]; col[0] = points[0].X; col[1] = -points[0].Y; col[2] = 0; col[3] = rect.X; col[4] = -(rect.Y + rect.Height); col[5] = 0; col[6] = rect.X + rect.Width; col[7] = -(rect.Y + rect.Height); col[8] = 0; col[9] = rect.X + rect.Width; col[10] = -rect.Y; col[11] = 0; col[12] = rect.X; col[13] = -rect.Y; col[14] = 0; AcadPolyline pl = cad.ActiveDocument.ModelSpace.AddPolyline(col); string color_str = rect.GetAttribute("style"); int sub_i = color_str.IndexOf("stroke:"); if (sub_i == -1) { color_str = "#000000"; } else { color_str = color_str.Substring(sub_i + 7, 7); // color_str = color_str.Replace("000000", "FFFFFF"); } Color c1 = ColorTranslator.FromHtml(color_str); AcadAcCmColor color = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color.SetRGB(c1.R, c1.G, c1.B); pl.TrueColor = color; pl.Layer = lab; cad.Application.Update(); } catch { } } if (ele.Name == "ellipse") { //Ellips eli = ele as Ellips; //DxfEllipse eli = new DxfEllipse(new Point3D(eli.RX, eli.RY, 0), new Vector3D(1, 1, 0), 1); //model.Entities.Add(eli); } if (ele.Name == "polyline") { try { Polyline p1 = ele as Polyline; PointF[] points = p1.Points; if (points.Length > 1) { p1.Transform.Matrix.TransformPoints(points); double[] col = new double[points.Length * 3]; int k = 0; for (int n = 0; n < points.Length; n++) { col[k] = points[n].X; col[k + 1] = -points[n].Y; col[k + 2] = 0; k = k + 3; } string color_str = p1.GetAttribute("style"); int gh_line = color_str.IndexOf("stroke-dasharray:"); int sub_i = color_str.IndexOf("stroke:"); if (sub_i == -1) { //color_str = "#FFFFF"; color_str = "#000000"; } else { color_str = color_str.Substring(sub_i + 7, 7); //color_str = color_str.Replace("000000", "FFFFFF"); } Color c1 = ColorTranslator.FromHtml(color_str); AcadPolyline ple = cad.ActiveDocument.ModelSpace.AddPolyline(col); Layer temp_l = tlVectorControl1.SVGDocument.GetLayerByID(ele.GetAttribute("layer"),false); if (temp_l != null) { if (temp_l.Label.ToLower().Contains("500kv")) { ple.ConstantWidth = w_500; } if (temp_l.Label.ToLower().Contains("220kv")) { ple.ConstantWidth = w_220; } if (temp_l.Label.ToLower().Contains("110kv")) { ple.ConstantWidth = w_110; } if (temp_l.Label.ToLower().Contains("66kv")) { ple.ConstantWidth = w_66; } if (temp_l.Label.ToLower().Contains("35kv")) { ple.ConstantWidth = w_35; } } if (gh_line != -1) { ple.Linetype = "DASHEDX2"; } ple.Layer = lab; AcadAcCmColor color = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color.SetRGB(c1.R, c1.G, c1.B); ple.TrueColor = color;//ACAD_COLOR.acMagenta; cad.Application.Update(); } } catch { } } if (ele.Name == "polygon") { try { Polygon p1 = ele as Polygon; PointF[] points = p1.Points; if (points.Length < 2) return; p1.Transform.Matrix.TransformPoints(points); double[] col = new double[points.Length * 3 + 3]; int k = 0; for (int n = 0; n < points.Length; n++) { col[k] = points[n].X; col[k + 1] = -points[n].Y; col[k + 2] = 0; k = k + 3; } col[points.Length * 3 + 2] = 0; col[points.Length * 3 + 1] = col[1]; col[points.Length * 3] = col[0]; AcadPolyline poly = cad.ActiveDocument.ModelSpace.AddPolyline(col); string IsArea = p1.GetAttribute("IsArea"); string color_str = p1.GetAttribute("style"); int sub_i = color_str.IndexOf("stroke:"); int sub_fill = color_str.IndexOf("fill:#"); if (sub_i == -1 && sub_fill == -1) { //color_str = "#FFFFF"; color_str = "#000000"; } else { if (IsArea == "1") { if (sub_fill == -1) { color_str = color_str.Substring(sub_i + 7, 7); // color_str = color_str.Replace("000000", "FFFFFF"); } else { color_str = color_str.Substring(sub_fill + 5, 7); //color_str = color_str.Replace("000000", "FFFFFF"); } } else { color_str = color_str.Substring(sub_i + 7, 7); //color_str = color_str.Replace("000000", "FFFFFF"); } } Color c1 = ColorTranslator.FromHtml(color_str); AcadAcCmColor color = (AcadAcCmColor)cad.ActiveDocument.Application.GetInterfaceObject("AutoCAD.AcCmColor.18"); color.SetRGB(c1.R, c1.G, c1.B); if (IsArea == "1") { AcadHatch solid = cad.ActiveDocument.ModelSpace.AddHatch(0, "solid", true, 0); solid.TrueColor = color; AcadEntity[] obj = new AcadEntity[1]; obj[0] = (AcadEntity)poly; solid.AppendOuterLoop(obj); solid.Evaluate(); solid.Layer = lab; } poly.TrueColor = color; poly.Layer = lab; cad.Application.Update(); } catch { } } if (ele.Name == "text") { try { ItopVector.Core.Figure.Text t1 = ele as ItopVector.Core.Figure.Text; PointF[] points = new PointF[1]; points[0].X = t1.X; points[0].Y = t1.Y; t1.Transform.Matrix.TransformPoints(points); double[] ins = new double[3]; ins[0] = points[0].X+offX; ins[1] =- points[0].Y+offY; ins[2] = 0; AcadMText text = cad.ActiveDocument.ModelSpace.AddMText(ins, TextLength, t1.TextString); text.Height = TextSize; text.Layer = lab; cad.Application.Update(); } catch { } } if (ele.Name == "use") { try { PointF[] cirp = new PointF[1]; Use u = ele as Use; PointF[] points = new PointF[1]; points[0].X = u.X; points[0].Y = u.Y; XmlNodeList list = tlVectorControl1.SVGDocument.SelectNodes("svg/defs/symbol [@id='" + u.GraphId + "']"); XmlElement e = (XmlElement)list[0]; XmlNodeList sonlist = e.ChildNodes; for (int k = 0; k < sonlist.Count; k++) { string str1 = sonlist[k].GetType().ToString(); if (str1 == "ItopVector.Core.Figure.Circle") { Circle cir = (Circle)sonlist[k]; cirp[0].X = cir.CX; cirp[0].Y = cir.CY; cir.Transform.Matrix.TransformPoints(cirp); break; } if (str1 == "ItopVector.Core.Figure.RectangleElement") { RectangleElement cir = (RectangleElement)sonlist[k]; cirp[0].X = cir.X; cirp[0].Y = cir.Y; cir.Transform.Matrix.TransformPoints(cirp); break; } } PointF p = cirp[0]; points[0].X = points[0].X + p.X; points[0].Y = points[0].Y + p.Y; u.Transform.Matrix.TransformPoints(points); if (u.GraphId.Contains("Substation500")) { double[] pnt = new double[3]; pnt[0] = points[0].X; pnt[1] = -points[0].Y; pnt[2] = 0; AcadCircle cirz = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir1); cirz.Layer = lab; cirz.TrueColor = color500; if (CadFullType == "2") { AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)cirz; wt.AppendOuterLoop(otw); wt.Layer = lab; } AcadCircle cir = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir2); cir.Layer = lab; cir.TrueColor = color500; AcadCircle cir1 = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir3); cir1.TrueColor = color500; cir1.Layer = lab; if (CadFullType == "2") { AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h.AppendOuterLoop(ot); if (u.GraphId.Contains("gh")) { cir.Linetype = "ACAD_ISO03W100"; cir1.Linetype = "ACAD_ISO03W100"; } } if(CadFullType=="1"){ if (!u.GraphId.Contains("gh") && !u.GraphId.Contains("user")) { AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h.AppendOuterLoop(ot); } } } if (u.GraphId.Contains("Substation220")) { double[] pnt = new double[3]; pnt[0] = points[0].X; pnt[1] = -points[0].Y; pnt[2] = 0; AcadCircle cir = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir2); cir.TrueColor = color220; cir.Layer = lab; if (CadFullType == "2") { AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)cir; wt.AppendOuterLoop(otw); wt.Layer = lab; } AcadCircle cir1 = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir3); cir1.Layer = lab; cir1.TrueColor = color220; if (CadFullType == "2") { if (u.GraphId.Contains("gh")) { cir.Linetype = "ACAD_ISO03W100"; cir1.Linetype = "ACAD_ISO03W100"; } AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h2.AppendOuterLoop(ot); } if (CadFullType == "1") { if (!u.GraphId.Contains("gh") && !u.GraphId.Contains("user")) { AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h2.AppendOuterLoop(ot); } if (u.GraphId.Contains("gh-user")) { double[] stat1 = new double[3]; stat1[0] = pnt[0] - int_cir3 / 2 - int_cir3 / 10; stat1[1] = pnt[1] - int_cir3 / 2 - int_cir3 / 10; stat1[2] = 0; double[] end1 = new double[3]; end1[0] = pnt[0] + int_cir3 / 2 + int_cir3 / 10; end1[1] = pnt[1] + int_cir3 / 2 + int_cir3 / 10; end1[2] = 0; AcadLine line1 = cad.ActiveDocument.ModelSpace.AddLine(stat1, end1); line1.Layer = lab; line1.TrueColor = color220; double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir3 / 2 - int_cir3 / 10; stat2[1] = pnt[1] + int_cir3 / 2 + int_cir3 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir3 / 2 + int_cir3 / 10; end2[1] = pnt[1] - int_cir3 / 2 - int_cir3 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color220; } if (u.GraphId.Contains("user")) { double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir3 / 2 - int_cir3 / 10; stat2[1] = pnt[1] + int_cir3 / 2 + int_cir3 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir3 / 2 + int_cir3 / 10; end2[1] = pnt[1] - int_cir3 / 2 - int_cir3 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color220; } } } if (u.GraphId.Contains("Substation110")) { double[] pnt = new double[3]; pnt[0] = points[0].X; pnt[1] = -points[0].Y; pnt[2] = 0; AcadCircle cir = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir3); cir.Layer = lab; cir.TrueColor = color110; if (CadFullType == "2") { AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)cir; wt.AppendOuterLoop(otw); wt.Layer = lab; } AcadCircle cir1 = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir4); cir1.Layer = lab; cir1.TrueColor = color110; if (CadFullType == "2") { if (u.GraphId.Contains("gh")) { cir.Linetype = "ACAD_ISO03W100"; cir1.Linetype = "ACAD_ISO03W100"; } AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h3.AppendOuterLoop(ot); } if (CadFullType == "1") { if (!u.GraphId.Contains("gh") && !u.GraphId.Contains("user")) { AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h3.AppendOuterLoop(ot); } if (u.GraphId.Contains("gh-user")) { double[] stat1 = new double[3]; stat1[0] = pnt[0] - int_cir4 / 2 - int_cir4 / 10; stat1[1] = pnt[1] - int_cir4 / 2 - int_cir4 / 10; stat1[2] = 0; double[] end1 = new double[3]; end1[0] = pnt[0] + int_cir4 / 2 + int_cir4 / 10; end1[1] = pnt[1] + int_cir4 / 2 + int_cir4 / 10; end1[2] = 0; AcadLine line1 = cad.ActiveDocument.ModelSpace.AddLine(stat1, end1); line1.Layer = lab; line1.TrueColor = color110; double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir4 / 2 - int_cir4 / 10; stat2[1] = pnt[1] + int_cir4 / 2 + int_cir4 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir4 / 2 + int_cir4 / 10; end2[1] = pnt[1] - int_cir4 / 2 - int_cir4 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color110; } if (u.GraphId.Contains("user")) { double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir4 / 2 - int_cir4 / 10; stat2[1] = pnt[1] + int_cir4 / 2 + int_cir4 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir4 / 2 + int_cir4 / 10; end2[1] = pnt[1] - int_cir4 / 2 - int_cir4 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color110; } } } if (u.GraphId.Contains("Substation66")) { double[] pnt = new double[3]; pnt[0] = points[0].X; pnt[1] = -points[0].Y; pnt[2] = 0; AcadCircle cir = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir4); cir.Layer = lab; cir.TrueColor = color66; if (CadFullType == "2") { AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)cir; wt.AppendOuterLoop(otw); wt.Layer = lab; } AcadCircle cir1 = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir5); cir1.Layer = lab; cir1.TrueColor = color66; if (CadFullType == "2") { if (u.GraphId.Contains("gh")) { cir.Linetype = "ACAD_ISO03W100"; cir1.Linetype = "ACAD_ISO03W100"; } AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h4.AppendOuterLoop(ot); h4.Evaluate(); } if (CadFullType == "1") { if (!u.GraphId.Contains("gh") && !u.GraphId.Contains("user")) { AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h4.AppendOuterLoop(ot); } if (u.GraphId.Contains("gh-user")) { double[] stat1 = new double[3]; stat1[0] = pnt[0] - int_cir5 / 2 - int_cir5/10; stat1[1] = pnt[1] - int_cir5 / 2 - int_cir5 / 10; stat1[2] = 0; double[] end1 = new double[3]; end1[0] = pnt[0] + int_cir5 / 2 + int_cir5 / 10; end1[1] = pnt[1] + int_cir5 / 2 + int_cir5 / 10; end1[2] = 0; AcadLine line1 = cad.ActiveDocument.ModelSpace.AddLine(stat1, end1); line1.Layer = lab; line1.TrueColor = color66; double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir5 / 2 - int_cir5 / 10; stat2[1] = pnt[1] + int_cir5 / 2 + int_cir5 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir5 / 2 + int_cir5 / 10; end2[1] = pnt[1] - int_cir5 / 2 - int_cir5 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color66; } if (u.GraphId.Contains("user")) { double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir5 / 2 - int_cir5 / 10; stat2[1] = pnt[1] + int_cir5 / 2 + int_cir5 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir5 / 2 + int_cir5 / 10; end2[1] = pnt[1] - int_cir5 / 2 - int_cir5 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color66; } } } if (u.GraphId.Contains("Substation35")) { double[] pnt = new double[3]; pnt[0] = points[0].X; pnt[1] = -points[0].Y; pnt[2] = 0; AcadCircle cir = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir4); cir.Layer = lab; cir.TrueColor = color33; if (CadFullType == "2") { AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)cir; wt.AppendOuterLoop(otw); wt.Layer = lab; } AcadCircle cir1 = cad.ActiveDocument.ModelSpace.AddCircle(pnt, int_cir5); cir1.Layer = lab; cir1.TrueColor = color33; if (CadFullType == "2") { if (u.GraphId.Contains("gh")) { cir.Linetype = "ACAD_ISO03W100"; cir1.Linetype = "ACAD_ISO03W100"; } AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h5.AppendOuterLoop(ot); } if (CadFullType == "1") { if (!u.GraphId.Contains("gh") && !u.GraphId.Contains("user")) { AcadEntity[] ot = new AcadEntity[1]; ot[0] = (AcadEntity)cir1; h5.AppendOuterLoop(ot); } if (u.GraphId.Contains("gh-user")) { double[] stat1 = new double[3]; stat1[0] = pnt[0] - int_cir5 / 2 - int_cir5 / 10; stat1[1] = pnt[1] - int_cir5 / 2 - int_cir5 / 10; stat1[2] = 0; double[] end1 = new double[3]; end1[0] = pnt[0] + int_cir5 / 2 + int_cir5 / 10; end1[1] = pnt[1] + int_cir5 / 2 + int_cir5 / 10; end1[2] = 0; AcadLine line1 = cad.ActiveDocument.ModelSpace.AddLine(stat1, end1); line1.Layer = lab; line1.TrueColor = color33; double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir5 / 2 - int_cir5 / 10; stat2[1] = pnt[1] + int_cir5 / 2 + int_cir5 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir5 / 2 + int_cir5 / 10; end2[1] = pnt[1] - int_cir5 / 2 - int_cir5 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color33; } if (u.GraphId.Contains("user")) { double[] stat2 = new double[3]; stat2[0] = pnt[0] - int_cir5 / 2 - int_cir5 / 10; stat2[1] = pnt[1] + int_cir5 / 2 + int_cir5 / 10; stat2[2] = 0; double[] end2 = new double[3]; end2[0] = pnt[0] + int_cir5 / 2 + int_cir5 / 10; end2[1] = pnt[1] - int_cir5 / 2 - int_cir5 / 10; end2[2] = 0; AcadLine line2 = cad.ActiveDocument.ModelSpace.AddLine(stat2, end2); line2.Layer = lab; line2.TrueColor = color33; } } //h3.Evaluate(); } if (u.GraphId.Contains("Substation-hdc") ) { double[] col = new double[15]; col[0] = points[0].X; col[1] = -points[0].Y; col[2] = 0; col[3] = points[0].X; col[4] = -(points[0].Y + 60); col[5] = 0; col[6] = points[0].X + 180; col[7] = -(points[0].Y + 60); col[8] = 0; col[9] = points[0].X + 180; col[10] = -points[0].Y; col[11] = 0; col[12] = points[0].X; col[13] = -points[0].Y; col[14] = 0; AcadPolyline pl = cad.ActiveDocument.ModelSpace.AddPolyline(col); if (u.GraphId.Contains("gh")) { } else { AcadHatch solid = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); //JIS_LC_20//JIS_LC_20 solid.PatternScale = 0.25; solid.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; solid.color = ACAD_COLOR.acRed; AcadEntity[] obj = new AcadEntity[1]; obj[0] = (AcadEntity)pl; solid.AppendOuterLoop(obj); solid.Evaluate(); solid.Layer = lab; } pl.Layer = lab; pl.color = ACAD_COLOR.acRed; double[] col2 = new double[15]; col2[0] = points[0].X; col2[1] = -points[0].Y+60; col2[2] = 0; col2[3] = points[0].X; col2[4] = -points[0].Y ; col2[5] = 0; col2[6] = points[0].X + 180; col2[7] = -points[0].Y; col2[8] = 0; col2[9] = points[0].X + 180; col2[10] = -points[0].Y+60; col2[11] = 0; col2[12] = points[0].X; col2[13] = -points[0].Y+60; col2[14] = 0; AcadPolyline pl2 = cad.ActiveDocument.ModelSpace.AddPolyline(col2); pl2.Layer = lab; pl2.color = ACAD_COLOR.acRed; //AcadEntity[] otw = new AcadEntity[1]; //otw[0] = (AcadEntity)pl2; //wt.AppendOuterLoop(otw); //wt.Layer = lab; } if ( u.GraphId.Contains("Substation-rdc")) { double[] col = new double[15]; col[0] = points[0].X; col[1] = -points[0].Y; col[2] = 0; col[3] = points[0].X; col[4] = -(points[0].Y + 120); col[5] = 0; col[6] = points[0].X + 90; col[7] = -(points[0].Y + 120); col[8] = 0; col[9] = points[0].X + 90; col[10] = -points[0].Y; col[11] = 0; col[12] = points[0].X; col[13] = -points[0].Y; col[14] = 0; AcadPolyline pl = cad.ActiveDocument.ModelSpace.AddPolyline(col); if (u.GraphId.Contains("gh")) { } else { AcadHatch solid = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); solid.PatternScale = 0.25; solid.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; solid.color = ACAD_COLOR.acWhite; AcadEntity[] obj = new AcadEntity[1]; obj[0] = (AcadEntity)pl; solid.AppendOuterLoop(obj); solid.Evaluate(); solid.Layer = lab; } pl.Layer = lab; double[] col2 = new double[15]; col2[0] = points[0].X+90; col2[1] = -points[0].Y; col2[2] = 0; col2[3] = points[0].X+90; col2[4] = -(points[0].Y + 120); col2[5] = 0; col2[6] = points[0].X + 90+90; col2[7] = -(points[0].Y + 120); col2[8] = 0; col2[9] = points[0].X + 90+90; col2[10] = -points[0].Y; col2[11] = 0; col2[12] = points[0].X+90; col2[13] = -points[0].Y; col2[14] = 0; AcadPolyline pl2 = cad.ActiveDocument.ModelSpace.AddPolyline(col2); pl2.Layer = lab; AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)pl2; wt.AppendOuterLoop(otw); wt.Layer = lab; } if (u.GraphId.Contains("水电站")) { double[] col2 = new double[12]; col2[0] = points[0].X; col2[1] = -points[0].Y; col2[2] = 0; col2[3] = points[0].X; col2[4] = -points[0].Y + 120; col2[5] = 0; col2[6] = points[0].X + 180; col2[7] = -(points[0].Y) + 120; col2[8] = 0; col2[9] = points[0].X; col2[10] = -points[0].Y; col2[11] = 0; AcadPolyline pl = cad.ActiveDocument.ModelSpace.AddPolyline(col2); AcadHatch solid = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); solid.PatternScale = 0.25; solid.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; solid.color = ACAD_COLOR.acWhite; AcadEntity[] obj = new AcadEntity[1]; obj[0] = (AcadEntity)pl; solid.AppendOuterLoop(obj); solid.Evaluate(); solid.Layer = lab; pl.Layer = lab; double[] col = new double[12]; col[0] = points[0].X; col[1] = -points[0].Y; col[2] = 0; col[3] = points[0].X + 180; col[4] = -points[0].Y; col[5] = 0; col[6] = points[0].X + 180; col[7] = -(points[0].Y) + 120; col[8] = 0; col[9] = points[0].X; col[10] = -points[0].Y; col[11] = 0; AcadPolyline pl2 = cad.ActiveDocument.ModelSpace.AddPolyline(col); pl2.Layer = lab; AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)pl2; wt.AppendOuterLoop(otw); wt.Layer = lab; } if (u.GraphId.Contains("gh-Substation-sdz")) { double[] col2 = new double[12]; col2[0] = points[0].X; col2[1] = -points[0].Y; col2[2] = 0; col2[3] = points[0].X; col2[4] = -points[0].Y + 120; col2[5] = 0; col2[6] = points[0].X + 180; col2[7] = -(points[0].Y) + 120; col2[8] = 0; col2[9] = points[0].X; col2[10] = -points[0].Y; col2[11] = 0; AcadPolyline pl = cad.ActiveDocument.ModelSpace.AddPolyline(col2); pl.Layer = lab; double[] col = new double[12]; col[0] = points[0].X; col[1] = -points[0].Y; col[2] = 0; col[3] = points[0].X + 180; col[4] = -points[0].Y; col[5] = 0; col[6] = points[0].X + 180; col[7] = -(points[0].Y) + 120; col[8] = 0; col[9] = points[0].X; col[10] = -points[0].Y; col[11] = 0; AcadPolyline pl2 = cad.ActiveDocument.ModelSpace.AddPolyline(col); pl2.Layer = lab; AcadEntity[] otw = new AcadEntity[1]; otw[0] = (AcadEntity)pl2; wt.AppendOuterLoop(otw); wt.Layer = lab; } if (u.GraphId.Contains("Substation-csxn")) { double[] col = new double[15]; col[0] = points[0].X; col[1] = -points[0].Y; col[2] = 0; col[3] = points[0].X; col[4] = -(points[0].Y + 120); col[5] = 0; col[6] = points[0].X + 180; col[7] = -(points[0].Y + 120); col[8] = 0; col[9] = points[0].X + 180; col[10] = -points[0].Y; col[11] = 0; col[12] = points[0].X; col[13] = -points[0].Y; col[14] = 0; AcadPolyline pl = cad.ActiveDocument.ModelSpace.AddPolyline(col); //AcadEntity[] otw = new AcadEntity[1]; //otw[0] = (AcadEntity)pl; //wt.AppendOuterLoop(otw); //wt.Layer = lab; double[] col2 = new double[15]; col2[0] = points[0].X; col2[1] = -points[0].Y-30; col2[2] = 0; col2[3] = points[0].X; col2[4] = -(points[0].Y)- 120; col2[5] = 0; col2[6] = points[0].X + 90; col2[7] = -(points[0].Y)- 120; col2[8] = 0; col2[9] = points[0].X + 90; col2[10] = -points[0].Y-30; col2[11] = 0; col2[12] = points[0].X; col2[13] = -points[0].Y-30; col2[14] = 0; AcadPolyline pl2 = cad.ActiveDocument.ModelSpace.AddPolyline(col2); double[] col3 = new double[15]; col3[0] = points[0].X+90; col3[1] = -points[0].Y-60; col3[2] = 0; col3[3] = points[0].X+90; col3[4] = -(points[0].Y )- 120; col3[5] = 0; col3[6] = points[0].X + 180; col3[7] = -(points[0].Y) - 120; col3[8] = 0; col3[9] = points[0].X + 180; col3[10] = -points[0].Y-60; col3[11] = 0; col3[12] = points[0].X+90; col3[13] = -points[0].Y-60; col3[14] = 0; AcadPolyline pl3 = cad.ActiveDocument.ModelSpace.AddPolyline(col3); if (u.GraphId.Contains("gh")) { } else { AcadHatch solid = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); solid.PatternScale = 0.25; solid.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; solid.color = ACAD_COLOR.acWhite; AcadEntity[] obj = new AcadEntity[1]; obj[0] = (AcadEntity)pl2; solid.AppendOuterLoop(obj); solid.Evaluate(); solid.Layer = lab; AcadHatch solid2 = cad.ActiveDocument.ModelSpace.AddHatch(0, "JIS_LC_20", true, 0); solid2.PatternScale = 0.25; solid2.Lineweight = ACAD_LWEIGHT.acLnWtByLwDefault; solid2.color = ACAD_COLOR.acWhite; AcadEntity[] obj2 = new AcadEntity[1]; obj2[0] = (AcadEntity)pl3; solid2.AppendOuterLoop(obj2); solid2.Evaluate(); solid2.Layer = lab; } pl.Layer = lab; pl2.Layer = lab; pl3.Layer = lab; } } catch { } } } //wt.color = ACAD_COLOR.acWhite; try { wt.Evaluate(); h.Evaluate(); h.Layer = lab; } catch(Exception e2) { } try { h2.Evaluate(); h2.Layer = lab; } catch(Exception e3) { } try { h3.Evaluate(); h3.Layer = lab; } catch { } try { h4.Evaluate(); h4.Layer = lab; } catch { } try { h5.Evaluate(); h5.Layer = lab; } catch { } cad.Application.Update(); //cad.ActiveDocument.SendCommand("Z e "); }