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

Invisible entity in BlockReference

7 REPLIES 7
Reply
Message 1 of 8
Anonymous
584 Views, 7 Replies

Invisible entity in BlockReference

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.
7 REPLIES 7
Message 2 of 8
Anonymous
in reply to: Anonymous

Sorry, the discussion software reformatted your code, and I don't have the
time to format it to be readable.

--
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:6266396@discussion.autodesk.com...
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.
Message 3 of 8
Anonymous
in reply to: Anonymous

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.
Message 4 of 8
Anonymous
in reply to: Anonymous

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.
Message 5 of 8
Anonymous
in reply to: Anonymous

I think, that code below is what you advise me to do.


Database db = HostApplicationServices.WorkingDatabase;
TransactionManager tm = db.TransactionManager;
Document dCurrentDock = Application.DocumentManager.MdiActiveDocument;

ObjectIdCollection oidcAddedEntities = new ObjectIdCollection();

using (DocumentLock DocLock = dCurrentDock.LockDocument(DocumentLockMode.Write, null, null, true))
{
using (Transaction trans = tm.StartTransaction())
{
try
{
BlockTableRecord btrOfBR = (BlockTableRecord)trans.GetObject(br_Inc.BlockTableRecord, OpenMode.ForWrite);
foreach (Entity eTmp in are_Inc)
{
oidcAddedEntities.Add(btrOfBR.AppendEntity(eTmp));
trans.AddNewlyCreatedDBObject(eTmp, true);
}

trans.Commit();
}
catch (Exception)
{
trans.Abort();
throw;
}
}
}
}


But situation didn't changed. Newly added entities is invisible. If only I enter BlockReference edit mode, they become vivsible.
Message 6 of 8
Anonymous
in reply to: Anonymous

You have to regenerate the block references.

--
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:6266769@discussion.autodesk.com...
I think, that code below is what you advise me to do.
Database db = HostApplicationServices.WorkingDatabase; TransactionManager tm
= db.TransactionManager; Document dCurrentDock =
Application.DocumentManager.MdiActiveDocument; ObjectIdCollection
oidcAddedEntities = new ObjectIdCollection(); using (DocumentLock DocLock =
dCurrentDock.LockDocument(DocumentLockMode.Write, null, null, true)) { using
(Transaction trans = tm.StartTransaction()) { try { BlockTableRecord btrOfBR
= (BlockTableRecord)trans.GetObject(br_Inc.BlockTableRecord,
OpenMode.ForWrite); foreach (Entity eTmp in are_Inc) {
oidcAddedEntities.Add(btrOfBR.AppendEntity(eTmp));
trans.AddNewlyCreatedDBObject(eTmp, true); } trans.Commit(); } catch
(Exception) { trans.Abort(); throw; } } } }
But situation didn't changed. Newly added entities is invisible. If only I
enter BlockReference edit mode, they become vivsible.
Message 7 of 8
Anonymous
in reply to: Anonymous

Tony, how to regenerate BlockReference?
Message 8 of 8
Anonymous
in reply to: Anonymous

I have founded solution.
To regenerate BlockReference you have to regenerate layer, where BR is placed.
To regenerate layer watch here http://discussion.autodesk.com/forums/thread.jspa?threadID=467019

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