.NET

Reply
Valued Mentor
Posts: 317
Registered: ‎10-10-2003
Message 1 of 3 (145 Views)

Inseting a Block that is already defined with Block Attributes

145 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
Posts: 370
Registered: ‎05-06-2012
Message 2 of 3 (123 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
Posts: 317
Registered: ‎10-10-2003
Message 3 of 3 (117 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Welcome to the new Autodesk Community!
If this is your first visit, click here to get started and make the most of the Community. Let us know what you think of the new experience in the Community Feedback Forum.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community