• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    .NET

    Reply
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

    Explode block with Attributes... converting attribute to text

    417 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

    Please use plain text.
    Mentor
    Posts: 258
    Registered: ‎01-27-2010

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

    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    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.

     

     

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



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

    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.

     

    ++

    Please use plain text.
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

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

    02-07-2012 10:10 AM in reply to: glanard
    Please use plain text.
    *Expert Elite*
    arcticad
    Posts: 1,250
    Registered: ‎06-21-2004

    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

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



    “We don’t have a snowball’s chance in a blast furnace of surviving this attack unless every one of our units gets into the fight right now!”
    Please use plain text.
    Contributor
    Posts: 20
    Registered: ‎09-29-2006

    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.
    Please use plain text.