.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with retaining Xdata after Exploding Block reference

1 REPLY 1
Reply
Message 1 of 2
jithin.dcs
575 Views, 1 Reply

Problem with retaining Xdata after Exploding Block reference

hi,
i am facing a problem with retaining xdata of block after exploding.
Actually i have a block reference and it will contain blocks and other entities. Each of these

entities(including nested blocks) will have xdata attached to it. If i explode this parent block

reference, everything works fine except retaining the xdata of the child blocks. I am getting xdata of

all other entities in the parent block except child block's.

here is the code

// Inserting the parent block

BlockReference blkRef = new BlockReference(new Point3d(0, 0, 0), blockId);
blkRef.LayerId = db.Clayer;
btr.AppendEntity(blkRef);
trans1.AddNewlyCreatedDBObject(blkRef, true);
blkRef.LayerId = db.Clayer;

// Exploding and getting dbobject collection
DBObjectCollection dboCollect = new DBObjectCollection();
blkRef.Explode(dboCollect);

// Changing layer of each dbobject and inserting to database
foreach (DBObject dboBJ in dboCollect)
{
Entity ent = (Entity)dboBJ;
ent.LayerId = db.Clayer;
btr.AppendEntity(ent);
trans1.AddNewlyCreatedDBObject(ent, true);
}

blkRef.Erase();
trans1.Commit();


Can anybody help........??
1 REPLY 1
Message 2 of 2
jithin.dcs
in reply to: jithin.dcs

hi all,

found the solution for this problem..
after reading the block to new database, change the layer name of the block to the current layer name in the parent database. (create a layer with the same name in the new database). then after inserting block to parent database and after creating the block reference and append it. then do a blockrefernce.ExplodetoOwnerSpace.

here is the code

// Creating the new database for reading the block
Database dbNew = new Database();
using (Transaction transNew = dbNew.TransactionManager.StartTransaction())
{
// Reading the selected scheme block in to a new database
dbNew.ReadDwgFile(sDwgFileName, FileOpenMode.OpenForReadAndAllShare, true, "");
BlockTableRecord btrNew = (BlockTableRecord)transNew.GetObject(dbNew.CurrentSpaceId, OpenMode.ForWrite);
LayerTable lt=(LayerTable)transNew.GetObject(dbNew.LayerTableId,OpenMode.ForWrite);

// Checking whether the current layer name in the original database exists in the new database, Adding the layer if it doesnt exists
if (lt.Has(currentLayerName) == false)
{
LayerTableRecord ltrNew = new LayerTableRecord();
ltrNew.Name = currentLayerName;
lt.Add(ltrNew);
transNew.AddNewlyCreatedDBObject(ltrNew, true);
}

// Changing layer of all objects to current layer.
foreach (ObjectId idNew in btrNew)
{
Entity objNew = (Entity)transNew.GetObject(idNew, OpenMode.ForWrite);
objNew.Layer = currentLayerName;
}
transNew.Commit();
}

// Inserting block to the current database
blockId = db.Insert(sBlockName, dbNew, true);
}

using (Transaction trans1 = doc.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)trans1.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
BlockReference blkRef = new BlockReference(new Point3d(0, 0, 0), blockId);
blkRef.LayerId = db.Clayer;
btr.AppendEntity(blkRef);
trans1.AddNewlyCreatedDBObject(blkRef, true);

blkRef.LayerId = db.Clayer;

// Exploding the block
blkRef.ExplodeToOwnerSpace();
blkRef.Erase();
trans1.Commit();
}

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost