Results 1 to 10 of 10

Thread: Block Reference & Attributes

  1. #1
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Question Block Reference & Attributes

    Why is it that when you create a new BlockReference object it will not have AttributeReferences created? What needs to be done to add the AttributeReferences that are defined in the BlockRecordTable?

  2. #2
    Member
    Join Date
    2007-06
    Posts
    15
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    Hi there,

    I have encountered the same problem myself. The solution to that is to manually add the attributeReferences. You can do that by iterating through all the objects associated with BlockTableRecord. For each object check if the type is attributeDefinition. If it is, build a new attributeReference using that attDef and then attach the attributeReference to the atributeReference Collection of the BlockReference. If this explanation is unclear let me know and I will try to post some code that might help you.

  3. #3
    Member
    Join Date
    2007-12
    Posts
    2
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    I was surprised by this to:

    Autodesk give an example in Lab 5 of their tutorial for .net.

    As mentioned above but instead of searching the whole block table you can get the objectID for the block and search through that for attribute reference.

    Not sure what happens when you have several attributes in the block though.
    I guess as you cycle through the block attributes you could query its tag name. Maybe does not matter as long as you have the correct number of attributes created in the block - you can reset all its values when you create blockref.
    Last edited by runerdooner; 2008-01-03 at 12:09 AM. Reason: Thought of something

  4. #4
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    Any ideas how this will affect attributes that are moved in dynamic blocks?

  5. #5
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    Quote Originally Posted by ivan.markov View Post
    If this explanation is unclear let me know and I will try to post some code that might help you.
    Your explanation seems straight forward enough but I'm having problems with this still. I've tried to append attributes to the collection but funny things happen to the block and still I don't always get attributes. When I do get attributes I can't edit them, see the attachment for the error message when editing the attribute. Do you know how this will impact dynamic blocks? Many of our blocks use dynamics and appending the attributes really seems to muck it up unless I'm doing something wrong.
    Attached Images Attached Images

  6. #6
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    Here is my code. The attributes will show up in the Property Palette and I can double click the block to edit the attributes but the attributes do not show in the drawing and sometimes when editing the attributes I get the error mentioned in the previous post.

    Code:
    Public Sub ApplyAttributeDefinisions(ByRef BlockReference As Autodesk.AutoCAD.DatabaseServices.BlockReference)
            Dim Block As AcadDb.BlockTableRecord = BlockReference.BlockTableRecord.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
            If Not Block.HasAttributeDefinitions Then Exit Sub
            If Block.Database Is Nothing Then Exit Sub
    
            Dim Trans As AcadDb.Transaction = Block.Database.TransactionManager.StartTransaction
            Try
                If BlockReference.Database Is Nothing Then Block.Database.AddDBObject(BlockReference)
    
                For Each Id As AcadDb.ObjectId In Block
                    Dim Ent As AcadDb.Entity = Id.GetObject(Autodesk.AutoCAD.DatabaseServices.OpenMode.ForRead)
    
                    If TypeOf Ent Is AcadDb.AttributeDefinition Then
                        Dim AttDef As AcadDb.AttributeDefinition = Ent
                        Dim AttRef As New AcadDb.AttributeReference
    
                        AttRef.SetPropertiesFrom(AttDef)
                        AttRef.SetAttributeFromBlock(AttDef, New AcadGty.Matrix3d)
    
                        BlockReference.AttributeCollection.AppendAttribute(AttRef)
                        Trans.AddNewlyCreatedDBObject(AttRef, True)
                    End If
                Next
    
                Trans.Commit()
            Catch ex As Autodesk.AutoCAD.Runtime.Exception
                Trans.Abort()
            Finally
                Trans.Dispose()
            End Try
        End Sub

  7. #7
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Smile Re: Block Reference & Attributes

    Think I solved it. It seams that the text size and widths where not being set and received values of 0. This caused problems in AutoCAD as you can't have a height or width of 0. Looks to be working a lot better now. Now I just have a problem with the attribute reference not moving in my Jig. Any body have any ideas?

  8. #8
    Member
    Join Date
    2008-02
    Posts
    3
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    Hi, I tried your code, and have an "eWrongObjectType" exception in line:
    If BlockReference.Database Is Nothing Then Block.Database.AddDBObject(BlockReference)
    Please, can you explain what this statement do?

    And also, please, can you publish the fixed code?

    Thank-you very much in advance.

  9. #9
    I could stop if I wanted to
    Join Date
    2003-03
    Location
    Alberta
    Posts
    260
    Login to Give a bone
    0

    Default Re: Block Reference & Attributes

    Sorry Pauminku, I'll have to get back to you later. I'm just texting on my phone and don't have the code with me. I'll be back in my office on Tuesday, if I remember I'll post the update then.

    Cheers!

  10. #10
    Member
    Join Date
    2008-02
    Posts
    3
    Login to Give a bone
    0

    Thumbs up Re: Block Reference & Attributes

    Quote Originally Posted by bweir View Post
    Here is my code. The attributes will show up in the Property Palette and I can double click the block to edit the attributes but the attributes do not show in the drawing and sometimes when editing the attributes I get the error mentioned in the previous post.
    I fixed it, you only have to change the line:

    AttRef.SetAttributeFromBlock(AttDef, New AcadGty.Matrix3d)

    for that one
    AttRef.SetAttributeFromBlock(AttDef, BlockReference.BlockTransform)

    Now, attributes have the same scale, position, etc. as the block reference.

    I also supress the line:
    If BlockReference.Database Is Nothing Then Block.Database.AddDBObject(BlockReference)

    I think you only have to insert the block reference and be sure that the database knows it, with, for example: tm.AddNewlyCreatedDBObject(blocRef, True)

Similar Threads

  1. Replies: 1
    Last Post: 2014-06-16, 07:54 PM
  2. Replies: 2
    Last Post: 2012-06-06, 12:28 PM
  3. Nested reference attributes
    By zride91 in forum AutoCAD General
    Replies: 2
    Last Post: 2011-02-04, 06:43 PM
  4. Replies: 21
    Last Post: 2007-03-20, 02:03 PM
  5. Extract Dynamic Block Attributes, values change as Block changes
    By dave.buckberry in forum Dynamic Blocks - Technical
    Replies: 11
    Last Post: 2006-09-05, 04:38 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
  •