插入动态块的代码
你好我只需要简单的代码来做一件事,在我当前使用的图形中插入一个动态块,该块存储在我计算机上的一个单独文件中(如C:/base/b-22)。例如,我有一个windows窗体,其中有一个列表框,其中包含存储在我的c驱动器上的许多动态块的名称。我想选择一个具有名称的块,在单击按钮或其他按钮时,将从单独的文件中获取该块,并将其插入我当前使用的图形中,并且需要能够选择我希望该块的位置。有人能帮忙吗,我正在使用autocad 2010和visual studio 2008-使用新的autocad。net语言。 我找到了这个链接,http://forums.autodesk.com/t5/NET/Code-to-insert-a-dynamic-block-into-the-current-drawing/m-p/2804900也许它可以帮助?? 只要从另一个文件克隆一个块并插入一个引用,无论它是否是动态的,都是一样的。
这里是一个链接到一个区块经理我张贴让人们开始一个http://www.theswamp.org/index.php?topic=35280.0
下面是该链接中的代码,用于将其引入并选择一个点以插入它。
它在VB中用于
private void InsertBlock(string blkName, string fileName)
{
Database extDb = new Database(false, true) as Database;
extDb.ReadDwgFile(fileName, FileOpenMode.OpenForReadAndAllShare, true, "");
Document doc = AcadApp.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
using (DocumentLock docloc = doc.LockDocument())
using (Transaction trx = db.TransactionManager.StartTransaction())
using (Transaction extTrx = extDb.TransactionManager.StartTransaction())
{
BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
BlockTableRecord currBtr = db.CurrentSpaceId.GetObject(OpenMode.ForRead) as BlockTableRecord;
if (!(bt.Has(blkName)))
{
BlockTable extBt = extDb.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable;
IdMapping map = new IdMapping();
ObjectIdCollection objIdColl = new ObjectIdCollection();
try
{
objIdColl.Add(extBt);
}
catch
{
trx.Commit();
return;
}
db.WblockCloneObjects(objIdColl, bt.ObjectId, map, DuplicateRecordCloning.Replace, false);
}
ObjectId btrId = bt.GetObject(OpenMode.ForRead).ObjectId;
PromptPointOptions ppo = new PromptPointOptions("/nSelect Insertion Point: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
Point3d insertPnt = ppr.Value;
currBtr.UpgradeOpen();
BlockReference bref = new BlockReference(insertPnt,btrId);
currBtr.AppendEntity(bref);
trx.AddNewlyCreatedDBObject(bref,true);
}
trx.Commit();
}
}
页:
[1]