.NET

Reply
Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 1 of 8 (1,257 Views)
Accepted Solution

Inserting block with attributes

1257 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?

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 -

Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 2 of 8 (1,257 Views)

Re: Inserting block with attributes

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

ps. I have looked everywhere.

*Expert Elite*
Alfred.NESWADBA
Posts: 9,413
Registered: ‎06-29-2007
Message 3 of 8 (1,251 Views)

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
-------------------------------------------------------------------------
Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 4 of 8 (1,247 Views)

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?

*Expert Elite*
Alfred.NESWADBA
Posts: 9,413
Registered: ‎06-29-2007
Message 5 of 8 (1,242 Views)

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
-------------------------------------------------------------------------
Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 6 of 8 (1,241 Views)

Re: Inserting block with attributes

12-03-2011 06:46 AM in reply to: Alfred.NESWADBA

OK

*Expert Elite*
Alfred.NESWADBA
Posts: 9,413
Registered: ‎06-29-2007
Message 7 of 8 (1,240 Views)

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
-------------------------------------------------------------------------
Valued Contributor
stuartnathan
Posts: 70
Registered: ‎02-17-2005
Message 8 of 8 (1,235 Views)

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.

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!