Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA attribute reference problem 1

Status
Not open for further replies.

mochamoo

Technical User
Mar 8, 2005
8
US
If anyone can help with this I will be greatly appreciative.

First, I create a block which has 2 atributes attached to it(length, and size) Next, I attach a block to every line in my drawing that is in a specified layer. The attributes for this block are then set to the size(width) and length of the line. The block is inserted at the midpoint of this line. This part works fine. The only problem is that if I erase all of these blocks and run the program again, every block now has 4 attributes attached to it (2 length attributes and 2 size attributes). If I do it again, each block has 6 attributes attached to it (3 length attributes and 3 size attributes) etc. etc. etc.

I can not figure out why this is happening. I am using an array of acadattributereferences when I insert these blocks so that I can store the references somewhere. Could this be a problem.

If you need actual code or if you have any suggestions at all, I would greatly appreciate any help.

Thanks,
James
 
Hi mochamoo,

This is your problem. When you erase the blocks from the drawing you erase the blockreference, not the block definition itself. When you rerun your program, you are only redefining the blocks within your drawing (adding the same two attributes).

HTH
Todd
 
How can I remedy this situation. Is there a solution ???
 
Hi mochamoo,

Just search for the existence of your block before you recreate it.

Code:
For Each blk in ThisDrawing.Blocks
  If blk.Name = "mochamooBlock" then
    Exit For
  Else
    ' Block creation routine here
  End If
End If

HTH
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top