How can you modify the components of a BlockReference.
I have an XXX (a Civil Entity), which I explode it and I obtain a BlockReference.
I take the BlockReference and exploded it and I get the components (MTexts).
I modify the Contents attribute of the Mtext object, but I don't see any changes in the drawing.
So, any ideas? Maybe there is fundamental thing which I don't see.
[CommandMethod("app")]
public static void app()
{
Document document = Application.DocumentManager.MdiActiveDocument;
Database database = document.Database;
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
String caleDirector = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "NumeroteazaKilometrii\\";
listAx = new List<Entity>();
using (Transaction transaction = database.TransactionManager.StartTransaction())
{
Entity minor;
DBObjectCollection dBObjectCollection = new DBObjectCollection();
PromptSelectionResult promptSelectionResult = Helper.selectEntities("Minor", document, true);
if (promptSelectionResult.Status == PromptStatus.OK)
{
SelectionSet selectionSet = promptSelectionResult.Value;
minor = transaction.GetObject(selectionSet[0].ObjectId, OpenMode.ForWrite) as Entity;
if (minor == null) return;
}
else
{
return;
}
if (minor is AlignmentMinorStationLabelGroup)
{
minor.Explode(dBObjectCollection);
foreach (Entity elementAx in dBObjectCollection)
{
listAx.Add(elementAx);
}
Entity minor2 = listAx[0];
dBObjectCollection.Clear();
listAx.Clear();
BlockReference block = null;
if (minor2 is BlockReference)
{
block = minor2 as BlockReference;
}
if (block != null)
{
block.Explode(dBObjectCollection);
foreach (Entity e in dBObjectCollection)
{
if (e is MText)
{
MText mText = e as MText;
mText.Contents = "BlaBlaBla";
}
}
}
}
transaction.Commit();
}
}
I know I must take the components directly from database, but I don't know how to do this.
I modified this line
MText mText = e as MText;
with
MText mText = transaction.GetObject(e.ObjectId, OpenMode.ForRead); as MText;
But I receive "null ObjectId"
So, how can I add those entity to my block? How can I delete some components from my block?
I can't seem to find some code to understand this thing. I found some code to insert new BlockReferences, but not to modify them.
I know nothing about Civil objects but if you need to
get valid ObjectID you have to add exploded objects
in the current space and then you can edit
the properties after
you could check if ObjectID before easy way
if ((e.ObjectID!=ObjectID.NUll) && (e.ObjectID.IsValid))
{
//TODO
}
Just from top of my head
You can't edit a block reference's mtext. You would have to redefine the text in the block definition. Otherwise copy the block definition with a new unique blockname and then edit that definition and then replace the block reference with the new block reference you just created.
Attributes are the only objects that can be edited per block reference.
When you explode the Block Reference you are making a copy of the contents. You could use those contents to build a new block. Also the original Block Reference is still in the drawing when you explode it. You haven't affected the block refererence at all by exploding it.