I wrote this little piece of code (attached) that explode all the blocks in the current drawing.
This is magical, compared with what we had to do in VBA.
This works perfectly but now I want to go deeper and managed blockreferences with attributes.
Based on my code, I can determine if oBTR.HasAttributeDefinitions is true or false.
If the blockreference has attributes, I suppose I will have to use Explode instead of ExplodeToOwnerSpace.
My first question is, using explode, I need before to know in which space the blockreference is inserted (Model or any layout) so to insert the exploded entities correctly. So, is it possible from a blockreference to get its own SpaceId?
An another idea I had is to edit the blockreference (not the block definition) to replace attributes with text... is it possible?
If you have other ideas
Thanks in advance,
In VBA i create Text object with the text inside the attribut.
If you explode Attribut in BlockReference you have only AttributBlockReference. This Object is not visible on you ModelSpace or PaperSpace.
So you need to create Text Object With the position. Calculate the X/y with the position of your BlockReference and scale X/Y and after add this to your paper/model Space.
I'am new on VB.NET but i need to do this for one of my VBA prog..
PS. You need to check if the attribut is visible or not. Or you can add option for the user.
I dont know how to the dynamic attribut is explosed.. If some one car give me a example code. I thanks you..
to answer the second question. No, you would have to create a new block. text can not vary, attributues can vary between the blocks.
I know all of this but the main question, in other words, is: from a BlockReference object, is there a way (using VB.NET), to know if this BlockReference is in the Model or Layout1 or Layout2...?
What I did in VBA was to iterate through the layouts and, for each one, create a selectionset of INSERT and then do the rest... this was working but was very very long, probably because of regeneration on each layout change.
I found this:
and will analyze it to see if it can help me.
Public Class info
Public Shared Sub displaySpace()
Using db As Database = HostApplicationServices.WorkingDatabase()
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim myDWG As Document = Autodesk.AutoCAD.ApplicationServices.Application.D
Using lock As DocumentLock = myDWG.LockDocument
Dim ed As Editor
ed = Autodesk.AutoCAD.ApplicationServices.Application.D
Dim sOptions As New PromptEntityOptions(vbCr & "Select Block: ")
sOptions.SetRejectMessage(vbLf & "Invalid Selection: ")
Dim sRes As PromptEntityResult = Nothing
sRes = ed.GetEntity(sOptions)
If Not sRes.Status <> PromptStatus.OK Then
Dim ent As Entity = DirectCast(tr.GetObject(sRes.ObjectId, OpenMode.ForRead), Entity)
If TypeOf ent Is BlockReference Then
Dim ent2 As Object = tr.GetObject(ent.OwnerId, OpenMode.ForRead)
If TypeOf ent2 Is BlockTableRecord Then
Dim blref As BlockTableRecord = tr.GetObject(ent2.OBJECTID, OpenMode.ForRead)
Dim layoutObj As Layout = tr.GetObject(blref.LayoutId, OpenMode.ForRead)