- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
Preserving Draworder of Entities while “wblockcloning” the blocks By Madhukar Moogala
The WblockClone API doesn’t guarantee draw order when Blocks are cloned ,wblockclone is very low level function ,it does only copying of entities ,the high-level functionality likes preserving draw order should be explicitly implement by application developer.
The above screenshots display correct and incorrect draw orders when wblock clone is perform ,to preserve order same a source block ,we need to use drawordertable API to sort entities as per source block.
[CommandMethod("WTEST")]
public void MyWTEST()
{
string blockName = "CP_STERN_SY";
string pathDWG = "C:\\VESSELBLOCKS.dwg";
var doc = Application.DocumentManager.MdiActiveDocument;
using (Database OpenDb = new Database(false, false))
{
OpenDb.ReadDwgFile(pathDWG,
System.IO.FileShare.ReadWrite,
true, "");
ObjectIdCollection ids = new ObjectIdCollection();
BlockTable bt;
ObjectId sourceBlockId = ObjectId.Null;
using (Transaction tr =
OpenDb.TransactionManager.StartTransaction())
{
bt = (BlockTable)tr.GetObject(OpenDb.BlockTableId,
OpenMode.ForRead);
if (bt.Has(blockName))
{
ids.Add(bt[blockName]);
sourceBlockId = bt[blockName];
}
if (ids.Count != 0)
{
Database destdb = doc.Database;
IdMapping iMap = new IdMapping();
OpenDb.WblockCloneObjects(ids,
destdb.BlockTableId,
iMap,
DuplicateRecordCloning.Replace,
false);
using (Transaction t =
destdb.TransactionManager.StartTransaction())
{
ObjectId targetBlockId = ObjectId.Null;
BlockTable b = (BlockTable)t.GetObject(destdb.BlockTableId,
OpenMode.ForRead);
if (b.Has(blockName))
{
targetBlockId = b[blockName];
}
SetBlockDrawOrder(sourceBlockId, targetBlockId, iMap);
t.Commit();
}
}
tr.Commit();
}
}
}
public void SetBlockDrawOrder(ObjectId sourceBlockId,
ObjectId targetBlockId,
IdMapping iMap)
{
Database db = HostApplicationServices.WorkingDatabase;
using (Transaction t = db.TransactionManager.StartTransaction())
{
var sourceBTR =
(BlockTableRecord)t.GetObject(sourceBlockId,
OpenMode.ForRead);
var dotSource =
(DrawOrderTable)t.GetObject(sourceBTR.DrawOrderTableId,
OpenMode.ForRead, true);
ObjectIdCollection srcDotIds = new ObjectIdCollection();
srcDotIds = dotSource.GetFullDrawOrder(0);
var targetBTR =
(BlockTableRecord)t.GetObject(targetBlockId,
OpenMode.ForRead);
var dotTarget =
(DrawOrderTable)t.GetObject(targetBTR.DrawOrderTableId,
OpenMode.ForWrite, true);
ObjectIdCollection trgDotIds = new ObjectIdCollection();
foreach (ObjectId oId in srcDotIds)
{
if (iMap.Contains(oId))
{
IdPair idPair = iMap.Lookup(oId);
trgDotIds.Add(idPair.Value);
}
}
dotTarget.SetRelativeDrawOrder(trgDotIds);
t.Commit();
}
}
|
|