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

Inserting block with attributes

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
stuartnathan
2108 Views, 7 Replies

Inserting block with attributes

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?

7 REPLIES 7
Message 2 of 8
stuartnathan
in reply to: stuartnathan

ps. I have looked everywhere.

Message 3 of 8

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 4 of 8

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?

Message 5 of 8

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 6 of 8

OK

Message 7 of 8

HI,

 

ok, I tried ... and I understand your question now 😉

 

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 ... blog.hollaus.at ... CDay 2024
------------------------------------------------------------------------------------
(not an Autodesk consultant)
Message 8 of 8

Smiley Very HappyThanks for that.

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

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