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

Inseting a Block that is already defined with Block Attributes

2 REPLIES 2
Reply
Message 1 of 3
gluckett
335 Views, 2 Replies

Inseting a Block that is already defined with Block Attributes

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

 

2 REPLIES 2
Message 2 of 3


@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.

Message 3 of 3

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

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