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

    .NET

    Reply
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005
    Accepted Solution

    Inserting block with attributes

    856 Views, 7 Replies
    12-03-2011 01:58 AM

    I wish to insert a title sheet dwg, which has attribute definitions, as a block in another dwg.

    I can insert it, and if I explode it, the attribute definitions appear. Otherwise they are not added to the database.

    I am using standard code, which I can attach if it helps.

    it starts

         

    Dim btr As BlockTableRecord

    ..

            

    Dim blk As BlockReference = New BlockReference(ip, blkid)                        '  insert block

    ..

    btr.AppendEntity(blk)

            

    If btr.HasAttributeDefinitions Then

               

      ForEach attID As ObjectId In btr

     

    etc.

    

    but btr.HasAttributeDefinitions = False

     

    Please help?

    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Inserting block with attributes

    12-03-2011 01:59 AM in reply to: stuartnathan

    ps. I have looked everywhere.

    Please use plain text.
    *Expert Elite*
    Posts: 6,463
    Registered: ‎06-29-2007

    Re: Inserting block with attributes

    12-03-2011 02:44 AM in reply to: stuartnathan

    Hi,

     

    you insert a BlockReference into a BlockTableRecord, the the BlockTableRecord will not hold AttributeDefinitions, you have not inserted multiple Objects, just added ONE BlockReference.

    And you have no chance to get nested ones.

     

    Try in AutoCAD:

    create one Block inluding a rectangle + one Attribute(definition) ==> call it TABLE

    copy this Block(References) 5 times

    create a new Block(Definition) TABLEGROUP out of these 5 BlockReferences and insert it anywhere in your drawing ==> the BlockReference TABLEGROUP does not show Attribute(References) to work with.

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Inserting block with attributes

    12-03-2011 06:07 AM in reply to: alfred.neswadba

    Sorry, I don't understand your point.

    I am using this code to insert a dwg

     

    Dim btr As BlockTableRecord

    Dim bt As BlockTable = DirectCast(tr.GetObject(CurDb.BlockTableId, OpenMode.ForRead), BlockTable)

    Dim blkid As ObjectId

    If Not bt.Has(Name) Then

        btr = tr.GetObject(CurDb.CurrentSpaceId, OpenMode.ForWrite)                   '  not already inserted?

        Dim db As Database = New Database(False, True)

        Using db

           db.ReadDwgFile(Path, System.IO.FileShare.Read, False, "")                  '  insert dwg

           blkid = CurDb.Insert(Name, db, True)

        End Using

    End If

    btr = DirectCast(tr.GetObject(CurDb.CurrentSpaceId, OpenMode.ForWrite), BlockTableRecord)

    If String.IsNullOrEmpty(btr.Name) Then

         btr.UpgradeOpen()

         btr.Name = Name

         btr.DowngradeOpen()

    End If

    Dim blk As BlockReference = New BlockReference(ip, blkid)                        '  insert block

     

    I understand that the dwg's attributes may not be loaded into the database. So how do I do that?

    Please use plain text.
    *Expert Elite*
    Posts: 6,463
    Registered: ‎06-29-2007

    Re: Inserting block with attributes

    12-03-2011 06:44 AM in reply to: stuartnathan

    Hi,

     

    could you also attach/upload the drawing that you use for this statement

    db.ReadDwgFile(Path, System.IO.FileShare.Read, False, "")

     

    - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Inserting block with attributes

    12-03-2011 06:46 AM in reply to: alfred.neswadba

    OK

    Please use plain text.
    *Expert Elite*
    Posts: 6,463
    Registered: ‎06-29-2007

    Re: Inserting block with attributes

    12-03-2011 07:18 AM in reply to: stuartnathan

    HI,

     

    ok, I tried ... and I understand your question now :smileywink:

     

    You donot have a problem defining the BlockDefinition by inserting data from an external DWG

    Your problem is: when inserting the BlockReference into the modelspace the AttributeReferences are not generated automatically. And yes, that is by default, to get them inserted look to >>>this sample<<< .... especially the part with:

    ar.SetAttributeFromBlock(ad, blkRef.BlockTransform)

    The AttRef's have to be created seperatly and attached to the BlockRef's AttributeCollection.

     

    Good luck, - alfred -

    -------------------------------------------------------------------------
    Alfred NESWADBA
    Ingenieur Studio HOLLAUS ... www.hollaus.at
    -------------------------------------------------------------------------
    Please use plain text.
    Valued Contributor
    Posts: 70
    Registered: ‎02-17-2005

    Re: Inserting block with attributes

    12-03-2011 09:52 AM in reply to: alfred.neswadba

    :smileyvery-happy:Thanks for that.

    I attach a text file showing my code as it seems to encapsulate all that I found out.

    Please use plain text.