获取用户输入的字符串,输入的点,关键字,int以及向autocad发送命令
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.EditorInput;
namespace AutoDemo16
{
public class Class1
{
[CommandMethod("GerString")]
public static void GerString()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
PromptStringOptions pSo = new PromptStringOptions("\n输入字符串");
pSo.AllowSpaces = true;
PromptResult pR = acDoc.Editor.GetString(pSo);
Application.ShowAlertDialog("\n你输入的字符串:"+ pR.ToString());
}
[CommandMethod("GetPoint")]
public static void GetPoint()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
PromptPointOptions pSo = new PromptPointOptions("");
pSo.Message = "请输入一个点";
PromptPointResult pR = acDoc.Editor.GetPoint(pSo);
Autodesk.AutoCAD.Geometry.Point3d p3d = pR.Value;
Application.ShowAlertDialog("x坐标:"+p3d.X.ToString()+"y坐标:"+p3d.Y.ToString());
}
[CommandMethod("GetKey")]
public static void GetKey()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
PromptKeywordOptions pSo = new PromptKeywordOptions("");
pSo.Message = "请输入关键字";
pSo.Keywords.Add("Line");
pSo.Keywords.Add("Arc");
pSo.AllowNone = false;
PromptResult pR = acDoc.Editor.GetKeywords(pSo);
Application.ShowAlertDialog("输入的关键字:" + pR.StringResult);
}
[CommandMethod("GetInt")]
public static void GetInt()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acDB = acDoc.Database;
PromptIntegerOptions pSo = new PromptIntegerOptions("");
pSo.Message = "请输入数字";
pSo.AllowNegative = false;
pSo.AllowZero = false;
pSo.AllowNone = true;
pSo.Keywords.Add("Line");
pSo.Keywords.Add("Arc");
pSo.Keywords.Default = "Arc";
PromptIntegerResult pR = acDoc.Editor.GetInteger(pSo);
if (pR.Status == PromptStatus.Keyword)
{
Application.ShowAlertDialog("输入的关键字:" + pR.StringResult);
}
else
{
Application.ShowAlertDialog("输入的数值:" + pR.Value.ToString());
}
}
[CommandMethod("SendCommand")]
public static void SendCommand()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Point2d pc = GetPointCommand();
string str = "._circle "+pc.X.ToString()+","+pc.Y.ToString()+" 10 ";
acDoc.SendStringToExecute(str, true, false, true);
acDoc.SendStringToExecute("._zoom _e ", true, false, true);
}
public static Point2d GetPointCommand()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
PromptPointOptions po = new PromptPointOptions("");
po.Message = "\n输入圆心";
PromptPointResult pre = acDoc.Editor.GetPoint(po);
Point3d p3d = pre.Value;
Point2d p2d = new Point2d(p3d.X, p3d.Y);
return p2d;
}
}
}