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

How to modify the components of a BlockReference?

2 REPLIES 2
Reply
Message 1 of 3
pesctx
710 Views, 2 Replies

How to modify the components of a BlockReference?

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.

2 REPLIES 2
Message 2 of 3
Hallex
in reply to: pesctx

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

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Message 3 of 3
arcticad
in reply to: pesctx

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.

---------------------------



(defun botsbuildbots() (botsbuildbots))

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