.NET

Reply
Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 1 of 7 (553 Views)

Explode block with Attributes... converting attribute to text

553 Views, 6 Replies
02-07-2012 08:13 AM

Hi,

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 :smileywink:

 

Thanks in advance,

Best regards

Valued Mentor
AubelecBE
Posts: 363
Registered: ‎01-27-2010
Message 2 of 7 (546 Views)

Re: Explode block with Attributes... converting attribute to text

02-07-2012 08:21 AM in reply to: glanard

HI.

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..

 

Bye.

 

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..

*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 3 of 7 (545 Views)

Re: Explode block with Attributes... converting attribute to text

02-07-2012 08:23 AM in reply to: glanard

to answer the second question. No, you would have to create a new block. text can not vary, attributues can vary between the blocks.

 

 

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



(defun botsbuildbots() (botsbuildbots))
Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 4 of 7 (533 Views)

Re: Explode block with Attributes... converting attribute to text

02-07-2012 09:48 AM in reply to: AubelecBE

Hi,

 

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.

 

++

Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 5 of 7 (526 Views)

Re: Explode block with Attributes... converting attribute to text

02-07-2012 10:10 AM in reply to: glanard
*Expert Elite*
arcticad
Posts: 1,285
Registered: ‎06-21-2004
Message 6 of 7 (518 Views)

Re: Explode block with Attributes... converting attribute to text

02-07-2012 10:53 AM in reply to: glanard

Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.EditorInput

Public Class info

    <CommandMethod("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.DocumentManager.MdiActiveDocument
                Using lock As DocumentLock = myDWG.LockDocument

                    Dim ed As Editor
                    ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor

                    Dim sOptions As New PromptEntityOptions(vbCr & "Select Block: ")
                    sOptions.SetRejectMessage(vbLf & "Invalid Selection: ")
                    sOptions.AddAllowedClass(GetType(BlockReference), False)

                    Dim sRes As PromptEntityResult = Nothing

                    While (True)
                        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)
                                    MsgBox(layoutObj.LayoutName)
                                End If
                            End If
                        Else
                            Exit While
                        End If
                    End While
                End Using
            End Using
        End Using

    End Sub

End Class

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



(defun botsbuildbots() (botsbuildbots))
Contributor
glanard
Posts: 20
Registered: ‎09-29-2006
Message 7 of 7 (512 Views)

Re: Explode block with Attributes... converting attribute to text

02-07-2012 11:04 AM in reply to: glanard
Well, it seems to be very intersting :smileywink:
I Will have a look at this asap.
Thanks.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community