view plaincopy to clipboardprint?
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
接着插入语句:[assembly: CommandClass(typeof(CsMgdAcad5.Commands))],同时注册CsMgdAcad5的命令。
整体的代码如下:
view plaincopy to clipboardprint?
// (C) Copyright 2002-2007 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(CsMgdAcad5.Commands))] //将直接通过auto cad 的Initialize命令进行初始化,并
namespace CsMgdAcad5
{
///
/// Summary description for Commands.
///
public class Commands
{
public Commands()
{
//
// TODO: Add constructor logic here
//
}
// Define Command "AsdkCmd1"
[CommandMethod("AsdkCmd1")]
static public void test() // This method can have any name
{
Document doc=Application.DocumentManager.MdiActiveDocument;
Editor ed=doc.Editor;
PromptPointOptions prpoint = new PromptPointOptions("select a point");
PromptPointResult prpointres;
prpointres = ed.GetPoint(prpoint);
if (prpointres.Status != PromptStatus.OK)
{
ed.WriteMessage("找不到该点");
}
else
{
ed.WriteMessage("找到有效的点"+prpointres.Value.ToString());
}
// Put your command code here
}
[CommandMethod("getinstance")]
static public void getinstance()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
PromptDistanceOptions distanceoptions = new PromptDistanceOptions("请选择第一个点:");
PromptDoubleResult PriDisRes;
PriDisRes = ed.GetDistance(distanceoptions);
if (PriDisRes.Status != PromptStatus.OK)
{
ed.WriteMessage("对不起,有错误,请重新输入");
}
else
{
ed.WriteMessage("这条直线的距离是:"+PriDisRes.Value.ToString());
}
}
catch(System.Exception e)
{
ed.WriteMessage("存在错误"+e.Message);
}
}
}
}
// (C) Copyright 2002-2007 by Autodesk, Inc.
//
// Permission to use, copy, modify, and distribute this software in
// object code form for any purpose and without fee is hereby granted,
// provided that the above copyright notice appears in all copies and
// that both that copyright notice and the limited warranty and
// restricted rights notice below appear in all supporting
// documentation.
//
// AUTODESK PROVIDES THIS PROGRAM "AS IS" AND WITH ALL FAULTS.
// AUTODESK SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTY OF
// MERCHANTABILITY OR FITNESS FOR A PARTICULAR USE. AUTODESK, INC.
// DOES NOT WARRANT THAT THE OPERATION OF THE PROGRAM WILL BE
// UNINTERRUPTED OR ERROR FREE.
//
// Use, duplication, or disclosure by the U.S. Government is subject to
// restrictions set forth in FAR 52.227-19 (Commercial Computer
// Software - Restricted Rights) and DFAR 252.227-7013(c)(1)(ii)
// (Rights in Technical Data and Computer Software), as applicable.
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
[assembly: CommandClass(typeof(CsMgdAcad5.Commands))] //将直接通过auto cad 的Initialize命令进行初始化,并
namespace CsMgdAcad5
{
///
/// Summary description for Commands.
///
public class Commands
{
public Commands()
{
//
// TODO: Add constructor logic here
//
}
// Define Command "AsdkCmd1"
[CommandMethod("AsdkCmd1")]
static public void test() // This method can have any name
{
Document doc=Application.DocumentManager.MdiActiveDocument;
Editor ed=doc.Editor;
PromptPointOptions prpoint = new PromptPointOptions("select a point");
PromptPointResult prpointres;
prpointres = ed.GetPoint(prpoint);
if (prpointres.Status != PromptStatus.OK)
{
ed.WriteMessage("找不到该点");
}
else
{
ed.WriteMessage("找到有效的点"+prpointres.Value.ToString());
}
// Put your command code here
}
[CommandMethod("getinstance")]
static public void getinstance()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
try
{
PromptDistanceOptions distanceoptions = new PromptDistanceOptions("请选择第一个点:");
PromptDoubleResult PriDisRes;
PriDisRes = ed.GetDistance(distanceoptions);
if (PriDisRes.Status != PromptStatus.OK)
{
ed.WriteMessage("对不起,有错误,请重新输入");
}
else
{
ed.WriteMessage("这条直线的距离是:"+PriDisRes.Value.ToString());
}
}
catch(System.Exception e)
{
ed.WriteMessage("存在错误"+e.Message);
}
}
}
}
进行编译,在auto cad当中输入netload,加载CsMgdAcad5.dll,然后在输入:AsdkCmd1命令,表示查询CAD某点的坐标。
输入getinstance,表示查询某2点的距离。
0 评论:
发表评论