Results 1 to 4 of 4

Thread: read attribute textstring vb.net

  1. #1
    Member
    Join Date
    2007-09
    Posts
    4

    Default read attribute textstring vb.net

    Hi Forum,

    I want to read the text string from an attribute where the state 'constant = true' in vb.net.

    Thanks for any reply.

    Martin

  2. #2
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,211

    Default Re: read attribute textstring vb.net

    You can retrieve the constant attributes from BlockTableRecord, eg.:
    Code:
            <CommandMethod("gatt", CommandFlags.Modal Or CommandFlags.Session)> _
            Public Shared Sub GetAttributesTest()
                Dim doc As Document = acApp.DocumentManager.MdiActiveDocument
                Dim db As Database = doc.Database
                Dim ed As Editor = doc.Editor
                Using docloc As DocumentLock = doc.LockDocument
                    Using tr As Transaction = db.TransactionManager.StartTransaction
                        Try
                            Dim bt As BlockTable = db.BlockTableId.GetObject(OpenMode.ForRead)
                            'Dim btr As BlockTableRecord = CType(tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)
                            Dim pso As PromptSelectionOptions = New PromptSelectionOptions
                            pso.MessageForRemoval = vbCr & "Wrong objects selected or Nothing selected"
                            pso.MessageForAdding = vbCr & "Select Blocks"
                            Dim tvs() As TypedValue = New TypedValue() {New TypedValue(0, "INSERT")}
                            Dim filt As SelectionFilter = New SelectionFilter(tvs)
                            Dim psr As PromptSelectionResult = ed.GetSelection(pso, filt)
                            If Not psr.Status = PromptStatus.OK Then Exit Sub
                            If psr.Value.Count = 0 Then
                                ed.WriteMessage("{0}Count: {1}blocks", vbNewLine, psr.Value.Count)
                                Exit Sub
                            End If
    
                            For Each sobj As SelectedObject In psr.Value
                                Dim bref As BlockReference = CType(tr.GetObject(sobj.ObjectId, OpenMode.ForRead), BlockReference)
                                Dim btrec As BlockTableRecord = CType(tr.GetObject(bref.BlockTableRecord, OpenMode.ForRead), BlockTableRecord)
                                Dim sb As New StringBuilder
                                'Get constant attributes from BlockDefinition object
                                For Each eid As ObjectId In btrec
                                    Dim obj As DBObject = CType(tr.GetObject(eid, OpenMode.ForRead), Entity)
                                    If (TypeOf (obj) Is AttributeDefinition) Then
                                        Dim atdef As AttributeDefinition = obj
                                        If atdef.Constant Then
                                            sb.AppendLine(atdef.TextString)
                                        End If
                                    End If
    
    
                                Next
                                'Get visible attributes from BlockReference object
                                Dim attcoll As AttributeCollection = bref.AttributeCollection
    
                                For Each id As ObjectId In attcoll
                                    Dim atref As AttributeReference = CType(tr.GetObject(id, OpenMode.ForRead), AttributeReference)
                                    sb.AppendLine(atref.TextString)
                                Next
                                ed.WriteMessage(sb.ToString + vbLf)
    
                            Next
                            tr.Commit()
                        Catch ex As Autodesk.AutoCAD.Runtime.Exception
                            ed.WriteMessage(vbCr & ex.Message & vbCr & ex.StackTrace)
                        End Try
                    End Using
                End Using
            End Sub
    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

  3. #3
    Member
    Join Date
    2007-09
    Posts
    4

    Default Re: read attribute textstring vb.net

    Fixo,

    I was hoping for a reply from you, this is what i needed. I've been trying for weeks to accomplish this.

    Many thanks from a fanatic dutchmen full of doubts.

    Martin

  4. #4
    AUGI Addict fixo's Avatar
    Join Date
    2005-05
    Location
    Pietari, Venäjä
    Posts
    1,211

    Default Re: read attribute textstring vb.net

    LOL,
    Let me know if you could not finish your task
    Cheers,

    ~'J'~
    "The whole problem with the world is that fools and fanatics are always
    so certain of themselves, and wiser people so full of doubts."
    Bertrand Russell

Similar Threads

  1. read field expression of an attribute
    By alberto.boffi695984 in forum AutoLISP
    Replies: 4
    Last Post: 2011-06-02, 07:29 AM
  2. READ ATTRIBUTE
    By lshivers in forum AutoLISP
    Replies: 3
    Last Post: 2009-05-08, 09:17 AM
  3. Retrieve Attribute TextString?
    By DThoma7778 in forum VBA/COM Interop
    Replies: 3
    Last Post: 2006-08-22, 11:17 PM
  4. script/lisp: read attribute value
    By David van Erk in forum AutoLISP
    Replies: 4
    Last Post: 2006-08-10, 05:02 PM
  5. Detect Read-Only file attribute
    By msretenovic in forum AutoLISP
    Replies: 4
    Last Post: 2004-07-22, 11:02 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •