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

Explode block with Attributes... converting attribute to text

6 REPLIES 6
Reply
Message 1 of 7
glanard
1635 Views, 6 Replies

Explode block with Attributes... converting attribute to text

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 😉

 

Thanks in advance,

Best regards

6 REPLIES 6
Message 2 of 7
AubelecBE
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..

Message 3 of 7
arcticad
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))
Message 4 of 7
glanard
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.

 

++

Message 5 of 7
glanard
in reply to: glanard

Message 6 of 7
arcticad
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))
Message 7 of 7
glanard
in reply to: glanard

Well, it seems to be very intersting 😉
I Will have a look at this asap.
Thanks.

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