- 积分
- 3689
- 明经币
- 个
- 注册时间
- 2006-3-31
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
发表于 2019-12-14 22:19:50
|
显示全部楼层
本帖最后由 caiqs 于 2019-12-16 18:39 编辑
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.ApplicationServices;
[assembly: CommandClass(typeof(MakeBlock.Commands))]
namespace MakeBlock
{
/// <summary>
/// Summary description for Commands.
/// </summary>
public class Commands
{
public Commands()
{
//
// TODO: Add constructor logic here
//
}
// Define Command "AsdkCmd1"
//师兄 QQ361865648,一直都在用VC,好长时间没写C#了
[CommandMethod("AsdkCmd1")]
static public void test() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptSelectionResult ssres = ed.GetSelection();
if (ssres.Status == PromptStatus.OK)
{
Point3d basept = new Point3d(0, 0, 0);
PromptPointResult ptres = ed.GetPoint("\n指定基点:");
if (ptres.Status == PromptStatus.OK)
basept = ptres.Value;
if (ptres.Status == PromptStatus.Cancel) return;
Transaction tr = db.TransactionManager.StartTransaction();
ObjectIdCollection ids = new ObjectIdCollection(ssres.Value.GetObjectIds());
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;
BlockTableRecord mspbtr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
BlockTableRecord btr = new BlockTableRecord();
btr.Name = "*U";
btr.Origin = basept;
ObjectId id = bt.Add(btr);
tr.AddNewlyCreatedDBObject(btr, true);
IdMapping idm = new IdMapping();
db.DeepCloneObjects(ids, id, idm, false);
BlockReference bref = new BlockReference(basept, id);
mspbtr.AppendEntity(bref);
tr.AddNewlyCreatedDBObject(bref, true);
//此处删除原实体
foreach (ObjectId Oldid in ids)
{
DBObject old = tr.GetObject(Oldid, OpenMode.ForWrite);
old.Erase();
}
tr.Commit();
}
// Put your command code here
}
}
} |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?注册
x
|