CAD二次开发实验报告(3)

2020-04-14 18:26

Application.DocumentManager.MdiActiveDocument.SendStringToExecute( \ + flName + \, false, false, false); } } }

(2)编译,并在AutoCAD利用NETLOAD加载dll。

4.6 创建工具条

(1)输入完整程序如下:

using System;

using System.Collections.Generic; using System.Linq; using System.Text;

using System.Threading.Tasks;

using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Customization; using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.Runtime; using System.IO; using System.Data;

[assembly: CommandClass(typeof(AddToolbar.ToolBar))] namespace AddToolbar {

public class ToolBar {

Database m_db = HostApplicationServices.WorkingDatabase; CustomizationSection pMainCS = null; CustomizationSection[] partials; public int BlockCount = 0;

10

public string fname = null;

Editor pEd = Application.DocumentManager.MdiActiveDocument.Editor; string mainCuiFile; public ToolBar() {

mainCuiFile = (string)Application.GetSystemVariable(\); mainCuiFile += \;

pMainCS = new CustomizationSection(mainCuiFile);

partials = new CustomizationSection[pMainCS.PartialCuiFiles.Count]; foreach (string fileName in pMainCS.PartialCuiFiles) {

if (File.Exists(fileName)) { } } } #region

[CommandMethod(\)] public void addToolbar() {

Toolbar newTb = new Toolbar(\公路边桩绘制工具\, pMainCS.MenuGroup); newTb.ToolbarOrient = ToolbarOrient.floating; newTb.ToolbarVisible = ToolbarVisible.show; newTb.Description = \公路边桩绘制工具\;

MacroGroup oMacroGroup = new MacroGroup(\, pMainCS.MenuGroup); MenuMacro oMenuMacro1 = new MenuMacro(oMacroGroup,\, \, \, MacroType.Any);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\; ToolbarButton tbBtn = new ToolbarButton(newTb, -1); tbBtn = new ToolbarButton(newTb, -1); tbBtn.Name = \起始里程设置\;

tbBtn.MacroID = oMenuMacro1.ElementID;

oMenuMacro1 = new MenuMacro(oMacroGroup,\, \, \, MacroType.Any); tbBtn = new ToolbarButton(newTb, -1);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\; tbBtn.Name = \任意点设置边桩\;

tbBtn.MacroID = oMenuMacro1.ElementID;

oMenuMacro1 = new MenuMacro(oMacroGroup, \, \, \, MacroType.Any); tbBtn = new ToolbarButton(newTb, -1);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\;

11

tbBtn.Name = \已知里程设置边桩\;

tbBtn.MacroID = oMenuMacro1.ElementID;//ModifyBZ

oMenuMacro1 = new MenuMacro(oMacroGroup, \, \, \, MacroType.Any); tbBtn = new ToolbarButton(newTb, -1);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\; tbBtn.Name = \修改边桩\;

tbBtn.MacroID = oMenuMacro1.ElementID;

oMenuMacro1 = new MenuMacro(oMacroGroup, \, \, \, MacroType.Any); tbBtn = new ToolbarButton(newTb, -1);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\; tbBtn.Name = \属性查看\;//OutputBZ

tbBtn.MacroID = oMenuMacro1.ElementID;//DelMidPl oMenuMacro1 = new MenuMacro(oMacroGroup,\, \, \, MacroType.Any); tbBtn = new ToolbarButton(newTb, -1);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\; tbBtn.Name = \删除所选中线\;//OutputBZ

tbBtn.MacroID = oMenuMacro1.ElementID;//DelMidPl oMenuMacro1 = new MenuMacro(oMacroGroup, \, \, \, MacroType.Any); tbBtn = new ToolbarButton(newTb, -1);

oMenuMacro1.macro.SmallImage = @\; oMenuMacro1.macro.LargeImage = @\; tbBtn.Name = \导出边桩信息\;//OutputBZ tbBtn.MacroID = oMenuMacro1.ElementID; foreach (Workspace wk in pMainCS.Workspaces) {

WorkspaceToolbar wkTb = new WorkspaceToolbar(wk, newTb); wk.WorkspaceToolbars.Add(wkTb); wkTb.Display = 1; }

saveCui(); }

#endregion

[CommandMethod(\)] public void saveCui() {

if (pMainCS.IsModified) pMainCS.Save();

12

string flName = pMainCS.CUIFileBaseName; Application.SetSystemVariable(\, 0);

Application.DocumentManager.MdiActiveDocument.SendStringToExecute( \ + flName + \, false, false, false);

Application.DocumentManager.MdiActiveDocument.SendStringToExecute( \ + flName + \, false, false, false); }

[CommandMethod(\)] public void remToolbar() {

Toolbar tbr = pMainCS.MenuGroup.Toolbars.FindToolbarWithName(\公路桩号设置\); if (tbr != null) {

foreach (Workspace wk in pMainCS.Workspaces) {

WorkspaceToolbar wkTb = wk.WorkspaceToolbars.FindWorkspaceToolbar( tbr.ElementID, tbr.Parent.Name); if (wkTb != null)

wk.WorkspaceToolbars.Remove(wkTb); }

pMainCS.MenuGroup.Toolbars.Remove(tbr); } }

[CommandMethod(\)] public void callForAllChanges() {

addToolbar(); saveCui(); } } }

(2)编译,并在AutoCAD利用NETLOAD加载dll。

4.7 创建有模态和无模态对话框

(1)定义窗体 MyForm,选择 1 个 TextBox 和 3 个 Button 控件。 窗体主要代码如下:

using System;

using System.Collections.Generic; using System.ComponentModel;

13

using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Threading.Tasks; using System.Windows.Forms; using Autodesk.AutoCAD.Geometry; using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.ApplicationServices; namespace 对话框 {

public partial class MyForm : Form {

public MyForm() {

InitializeComponent(); }

private void button1_Click(object sender, EventArgs e) {

Editor ed = Autodesk.AutoCAD.ApplicationServices.Application. DocumentManager.MdiActiveDocument.Editor;

using (EditorUserInteraction edUsrInt = ed.StartUserInteraction(this)) {

Point3d pt = GetPoint(\选择点:\);

this.InputText.Text = \ + pt.X.ToString() + \ \ + pt.Y.ToString() + \ + pt.Z.ToString() + \; edUsrInt.End(); this.Focus(); } }

public Point3d GetPoint(string word) {

Document doc = Autodesk.AutoCAD.ApplicationServices.Application. DocumentManager.MdiActiveDocument; Editor ed = doc.Editor;

PromptPointResult pt = ed.GetPoint(word); if (pt.Status == PromptStatus.OK) {

return (Point3d)pt.Value; } else {

return new Point3d(); }

14


CAD二次开发实验报告(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:(全国通用版)2019版高考数学一轮复习 第二单元 函数的概念及其

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: