Sorry, what you're trying to do makes no sense.
You're adding new objects to the database, and then
using AssumeOwnershipOf() to transfer them to another
owner block. There is no point in doing that.
Just add the new entities to the block that you want
to be the owner.
Lastly, It's difficult to read code that has identifiers
that are prequalified with the namespace.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6266398@discussion.autodesk.com...
Tony, here is post without formatting.
I'm triing to add entities to BlockReference. Entities, that I want to add
is not in database (created before in 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;
}
}
}
}
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
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 });
}
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.