Not sure what you mean by 'nested blocks/attributes'.
A BlockReference has attributes, which correspond to
attribute definitions in the block's defining entities.
If there are BlockReferences that are nested in the
definition of a block, which also have attributes, those
attributes are part of another BlockReference that is
inserted into/resides in the 'parent' block's definition.
I think you're going to need to explain more clearly
what you are trying to do. If you have blocks nested
within other blocks, you deal with them in the same
way you deal with 'top-level' block references, except
that the owner is not the modelspace or a paperspace
block, it is the block that contains the nested block
references.
--
http://www.caddzone.com
AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010
http://www.acadxtabs.com
Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");
wrote in message news:6279865@discussion.autodesk.com...
Here is the For Each Next Solution that Jerry Winters actually worked out
for me after I mentioned this discussion to him.
It works, but only for the top level blocks. It does not find any nested
block attributes. I'm thinking that the enumeration method will find all
the nested blocks as well. The same code is in the attached file also.
Some of the discussion on this subject indicates this is not a difficult
problem. I'm not finding it so smple.... but then I'm pretty new as well...
However since the question was raised, I wanted to close the loop on this
sub discussion.
{code}
Public Function AddBlockAndAtts(ByVal InsPt As Geometry.Point3d, _
ByVal BlockName As String) As DatabaseServices.ObjectId
'Add Block Reference with all the attributes from the block
definition.
Dim myTransMan As DatabaseServices.TransactionManager
Dim myTrans As DatabaseServices.Transaction
Dim myDwg As Document
Dim myBT As BlockTable
Dim myBTR As BlockTableRecord
myDwg = Application.DocumentManager.MdiActiveDocument
myTransMan = myDwg.TransactionManager
myTrans = myTransMan.StartTransaction
'Open the database for Write
myBT = myDwg.Database.BlockTableId.GetObject(OpenMode.ForRead)
myBTR =
myBT(BlockTableRecord.ModelSpace).GetObject(OpenMode.ForWrite)
'Insert the Block
Dim myBlockDef As BlockTableRecord =
myBT(BlockName).GetObject(OpenMode.ForRead)
Dim myBlockRef As New BlockReference(InsPt, myBT(BlockName))
myBTR.AppendEntity(myBlockRef)
myTrans.AddNewlyCreatedDBObject(myBlockRef, True)
'Set the Attribute Value
Dim myAttColl As AttributeCollection
Dim myEnt As Entity
' Dim myBTREnum As BlockTableRecordEnumerator
myAttColl = myBlockRef.AttributeCollection
Dim myEntID As ObjectId
' myBTREnum = myBlockDef.GetEnumerator
For Each myEntID In myBlockDef
' While myBTREnum.MoveNext
'myEnt = myBTREnum.Current.GetObject(OpenMode.ForWrite)
myEnt = CType(myEntID.GetObject(OpenMode.ForWrite), Entity)
If TypeOf myEnt Is DatabaseServices.AttributeDefinition Then
Dim myAttDef As DatabaseServices.AttributeDefinition =
myEnt
Dim myAttRef As New DatabaseServices.AttributeReference
myAttRef.SetAttributeFromBlock(myAttDef,
myBlockRef.BlockTransform)
myAttColl.AppendAttribute(myAttRef)
myTrans.AddNewlyCreatedDBObject(myAttRef, True)
End If
' End While
Next
'Commit the Transaction
myTrans.Commit()
'Dispose of the Transaction Objects
myTrans.Dispose()
myTransMan.Dispose()
Return myBlockRef.ObjectId
End Function
{code}