.NET

.NET

Reply
Valued Mentor
gluckett
Posts: 422
Registered: ‎10-10-2003
Message 1 of 3 (169 Views)

Inseting a Block that is already defined with Block Attributes

169 Views, 2 Replies
04-08-2013 07:52 AM

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

 

Valued Mentor
DiningPhilosopher
Posts: 370
Registered: ‎05-06-2012
Message 2 of 3 (147 Views)

Re: Inseting a Block that is already defined with Block Attributes

04-08-2013 12:40 PM in reply to: gluckett

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.

Valued Mentor
gluckett
Posts: 422
Registered: ‎10-10-2003
Message 3 of 3 (141 Views)

Re: Inseting a Block that is already defined with Block Attributes

04-08-2013 01:00 PM in reply to: DiningPhilosopher

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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.