- 积分
- 6614
- 明经币
- 个
- 注册时间
- 2006-8-30
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
本帖最后由 cheng5276 于 2014-9-1 17:14 编辑
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using System.Drawing;
using Autodesk.AutoCAD.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
using Document = Autodesk.AutoCAD.ApplicationServices.Document;
using Autodesk.AutoCAD.LayerManager;
using Autodesk.AutoCAD.GraphicsSystem;
using Autodesk.AutoCAD.GraphicsInterface;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices.Filters;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Windows.ToolPalette;
using Autodesk.AutoCAD.Publishing;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.ApplicationServices;
namespace WPFClassLibrary
{
public class Class1
{
static void AddRegAppTableRecord(string regAppName)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Transaction trans = doc.TransactionManager.StartTransaction();
RegAppTable rat = (RegAppTable)trans.GetObject(db.RegAppTableId, OpenMode.ForRead, false);
if (!rat.Has(regAppName))
{
rat.UpgradeOpen();
RegAppTableRecord ratr = new RegAppTableRecord();
ratr.Name = regAppName;
rat.Add(ratr);
trans.AddNewlyCreatedDBObject(ratr, true);
}
trans.Commit();
trans.Dispose();
}
static public DBObject Selectobj(string word)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\n请选择实体:");
PromptEntityResult per = ed.GetEntity(peo);
DBObject obj=null;
if (per.Status == PromptStatus.OK)
{
Transaction trans = doc.TransactionManager.StartTransaction();
obj = trans.GetObject(per.ObjectId, OpenMode.ForWrite);
trans.Commit();
trans.Dispose();
}
return obj;
}
[CommandMethod("SXD")]
static public void SXDa()
{
SetXData(Selectobj("请选择对象aa:"));
}
static public void SetXData(DBObject obj)
{
AddRegAppTableRecord("cheng5276");
ResultBuffer rb = new ResultBuffer();
rb.Add(new TypedValue(1001, "cheng5276"));
rb.Add(new TypedValue(1000, "only ascii under AutoCAD 2006"));
rb.Add(new TypedValue(1000, "max length is 255"));
obj.XData = rb;
rb.Dispose();
}
[CommandMethod("SXD2")]
static public void SetXData2()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptEntityOptions peo = new PromptEntityOptions("\n请选择实体:");
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status == PromptStatus.OK)
{
Transaction trans = doc.TransactionManager.StartTransaction();
DBObject obj = trans.GetObject(per.ObjectId, OpenMode.ForWrite);
AddRegAppTableRecord("Test");
ResultBuffer rb = new ResultBuffer();
rb.Add(new TypedValue(1001, "Test"));
rb.Add(new TypedValue(1000, "only ascii under AutoCAD 2006"));
rb.Add(new TypedValue(1000, "max length is 255"));
obj.XData = rb;
rb.Dispose();
trans.Commit();
trans.Dispose();
}
}
}
}
请教,当我采用GXD2命令选择对象并设置器扩展数据,程序很顺利
但是当我将GXD2拆分成两个函数(分别为选择对象和设置扩展数据时),见SXD的命令及函数,程序就会弹出致命错误了,小弟初学C# CAD 编程,恭请大侠们指点迷津,拜谢了!
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|