Inseting a Block that is already defined with Block Attributes

Inseting a Block that is already defined with Block Attributes

gluckett
Collaborator Collaborator
643 Views
2 Replies
Message 1 of 3

Inseting a Block that is already defined with Block Attributes

gluckett
Collaborator
Collaborator

HI All,

I can insert a block with block attributes using the Interop very easily:

 

Dim theBlock AsAcadBlockReference       

Dim pickScreenVBA = myDoc.Utility.GetPoint(, "insert the hydrant")

       

theBlock = myDoc.ModelSpace.InsertBlock(pickScreenVBA, "Hydrant", 1.0#, 1.0#, 1.0#, 0)

           

Dim varAttributes AsObject

varAttributes = theBlock.GetAttributes

varAttributes(0).TextString ="3 Ports"

varAttributes(1).TextString ="Salt water"

 

Works great, but when I try using the non-interop, all the example insert new Attributes and not add block with existing attribute (so I end up with duplicate attributes for each block - i.e "Salt water" attribute is added to the block each time I run the code), 

Are they any examples that does the same as above using the non-interop code?

 

thanks

 

0 Likes
644 Views
2 Replies
Replies (2)
Message 2 of 3

DiningPhilosopher
Collaborator
Collaborator

@gluckett wrote:

HI All,

I can insert a block with block attributes using the Interop very easily:

 

Dim theBlock AsAcadBlockReference       

Dim pickScreenVBA = myDoc.Utility.GetPoint(, "insert the hydrant")

       

theBlock = myDoc.ModelSpace.InsertBlock(pickScreenVBA, "Hydrant", 1.0#, 1.0#, 1.0#, 0)

           

Dim varAttributes AsObject

varAttributes = theBlock.GetAttributes

varAttributes(0).TextString ="3 Ports"

varAttributes(1).TextString ="Salt water"

 

Works great, but when I try using the non-interop, all the example insert new Attributes and not add block with existing attribute (so I end up with duplicate attributes for each block - i.e "Salt water" attribute is added to the block each time I run the code), 

Are they any examples that does the same as above using the non-interop code?

 

thanks

 


You'll need to post the code you're having the problem with. Attributes must be added manually when inserting blocks using .NET APIs, and if there are duplicate attributes it is a problem with the code, or you are just not using ithe code correctly.

0 Likes
Message 3 of 3

gluckett
Collaborator
Collaborator

Thanks, I actually tried using this code, and it appended the attributes to the already exiting ones so each time it ran I would have another Attribute on the block called Hydrant_Type

 

 BTR = trans.GetObject(CType(transe.GetObject(mBR.BlockTableRecord, OpenMode.ForRead),         BlockTableRecord).ObjectId, OpenMode.ForRead)
  
            Dim attIDs As AttributeCollection = BTR.AttributeCollection
          
                For Each aID As ObjectId In attIDs
                    Dim attRef As AttributeReference = trans.GetObject(aID, OpenMode.ForRead)
                    If attRef.Tag = "Hydrant_Type"  Then
                                    attRef.TextString="Salt Water"
                                    trans.Commit()
                     End If
                 Next
            End If

0 Likes