- UID
- 14
- 积分
- 8264
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-1-4
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
http://adndevblog.typepad.com/autocad/2012/05/insert-block-from-a-different-dwg-using-net-.htmlInsert Block from a different DWG using .NET By Virupaksha Aithal
Using the WblockCloneObjects() method, its possible to copy a particular block from a drawing in to the other drawing. The C# code snippet that shows how to use WblockCloneObjects to copy a specific block "test" from the drawing available at "C:\TEMP\test.dwg".
"C:\TEMP\test.dwg".
[CommandMethod("InsertBlock")]
static public void InsertBlock() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
using(Database OpenDb = new Database(false, true))
{
OpenDb.ReadDwgFile("c:\\temp\\test.dwg",
System.IO.FileShare.ReadWrite, true, "");
ObjectIdCollection ids = new ObjectIdCollection();
using (Transaction tr =
OpenDb.TransactionManager.StartTransaction())
{
//For example, Get the block by name "TEST"
BlockTable bt;
bt = (BlockTable)tr.GetObject(OpenDb.BlockTableId
, OpenMode.ForRead);
if (bt.Has("TEST"))
{
ids.Add(bt["TEST"]);
}
tr.Commit();
}
//if found, add the block
if (ids.Count != 0)
{
//get the current drawing database
Database destdb = doc.Database;
IdMapping iMap = new IdMapping();
destdb.WblockCloneObjects(ids, destdb.BlockTableId
,iMap,DuplicateRecordCloning.Ignore, false);
}
}
}
|
评分
-
查看全部评分
|