Message 1 of 8
Invisible entity in BlockReference

Not applicable
10-06-2009
03:20 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm triing to add entities to BlockReference. Entities, that I want to add is not in database (created before in code).
{code}
public static void AddEntityToBR(BlockReference br_Inc, Entity[] are_Inc)
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Autodesk.AutoCAD.ApplicationServices.Document dCurrentDock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
ObjectIdCollection oidcAddedEntities = new ObjectIdCollection();
using (Autodesk.AutoCAD.ApplicationServices.DocumentLock DocLock =
dCurrentDock.LockDocument(Autodesk.AutoCAD.ApplicationServices.DocumentLockMode.Write, null, null, true))
{
using (Transaction trans = tm.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)trans.GetObject(dCurrentDock.Database.BlockTableId, OpenMode.ForWrite, true, true);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
//Add entities to drawing
foreach (Entity eTmp in are_Inc)
{
oidcAddedEntities.Add(btr.AppendEntity(eTmp));
trans.AddNewlyCreatedDBObject(eTmp, true);
}
//Open BlockTableRecord and all entities forwrite as Tony Tanzillo said here http://discussion.autodesk.com/forums/thread.jspa?messageID=5700703�
BlockTableRecord btrOfBR = (BlockTableRecord)trans.GetObject(br_Inc.BlockTableRecord, OpenMode.ForWrite);
foreach (ObjectId oidCur in oidcAddedEntities)
{
DBObject dboTmp = trans.GetObject(oidCur, OpenMode.ForWrite);
}
btrOfBR.AssumeOwnershipOf(oidcAddedEntities);
trans.Commit();
}
catch (Exception)
{
trans.Abort();
throw;
}
}
}
}
{code}
The code above adds entities to BR (BlockReference), but I don't see them on screen (in the drawing). If I doubleclick on BR in AutoCad (I mean open BlockReference editing mode) and then close BlockReference editing mode with save changes, I can see it in the drawing.
I don't know how to make added entities to be visible in the drawing using C#?
If I call this function
{code}
public static void RegenerateWindow()
{
Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
object oAcadDoc = doc.AcadDocument;
oAcadDoc.GetType().InvokeMember("Regen", System.Reflection.BindingFlags.InvokeMethod, null, oAcadDoc,
new object[] { 1 });
}
{code}
added object become visible, but not as member of BR. I mean if i position my cursor on any entity, that belong to BR, whole BR become highlighted. If I position cursor on just added entity, BR do not become highlighted.
{code}
public static void AddEntityToBR(BlockReference br_Inc, Entity[] are_Inc)
{
Database db = HostApplicationServices.WorkingDatabase;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
Autodesk.AutoCAD.ApplicationServices.Document dCurrentDock = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
ObjectIdCollection oidcAddedEntities = new ObjectIdCollection();
using (Autodesk.AutoCAD.ApplicationServices.DocumentLock DocLock =
dCurrentDock.LockDocument(Autodesk.AutoCAD.ApplicationServices.DocumentLockMode.Write, null, null, true))
{
using (Transaction trans = tm.StartTransaction())
{
try
{
BlockTable bt = (BlockTable)trans.GetObject(dCurrentDock.Database.BlockTableId, OpenMode.ForWrite, true, true);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
//Add entities to drawing
foreach (Entity eTmp in are_Inc)
{
oidcAddedEntities.Add(btr.AppendEntity(eTmp));
trans.AddNewlyCreatedDBObject(eTmp, true);
}
//Open BlockTableRecord and all entities forwrite as Tony Tanzillo said here http://discussion.autodesk.com/forums/thread.jspa?messageID=5700703�
BlockTableRecord btrOfBR = (BlockTableRecord)trans.GetObject(br_Inc.BlockTableRecord, OpenMode.ForWrite);
foreach (ObjectId oidCur in oidcAddedEntities)
{
DBObject dboTmp = trans.GetObject(oidCur, OpenMode.ForWrite);
}
btrOfBR.AssumeOwnershipOf(oidcAddedEntities);
trans.Commit();
}
catch (Exception)
{
trans.Abort();
throw;
}
}
}
}
{code}
The code above adds entities to BR (BlockReference), but I don't see them on screen (in the drawing). If I doubleclick on BR in AutoCad (I mean open BlockReference editing mode) and then close BlockReference editing mode with save changes, I can see it in the drawing.
I don't know how to make added entities to be visible in the drawing using C#?
If I call this function
{code}
public static void RegenerateWindow()
{
Autodesk.AutoCAD.ApplicationServices.Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
object oAcadDoc = doc.AcadDocument;
oAcadDoc.GetType().InvokeMember("Regen", System.Reflection.BindingFlags.InvokeMethod, null, oAcadDoc,
new object[] { 1 });
}
{code}
added object become visible, but not as member of BR. I mean if i position my cursor on any entity, that belong to BR, whole BR become highlighted. If I position cursor on just added entity, BR do not become highlighted.