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?
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
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 -
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?
Hi,
could you also attach/upload the drawing that you use for this statement
db.ReadDwgFile(Path, System.IO.FileShare.Read, False, "")
- alfred -
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 -
Thanks 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.