PDA

View Full Version : acadblockreference (VBA basics)



j_r_auden
13th Jan 2005, 07:36 pm
If I am trying to reference a particular block in my drawing so i can extract the attributes. I am doing this with a small for statement that searches all the blocks in my drawing and stores the item#.

Example: For i=0 to thisdrawing.blocks.items.count - 1
if thisdrawing.blocks.item(i) = "PIPETAG"
refNumber = i

Now that I know which item is the block i am looking for, how do i reference its' attributes. I need to set an ACADattributereference to this block, but if I am correct, you can not do that. I read that ACADattribute references are automatically inserted into the drawing with each copy of the block. Is this correct??

Please help. If I am going about this in the wrong way, or if there is a simpler way, please let me know.

Thanks,
James

hendie
13th Jan 2005, 07:52 pm
it would probably be easier just to select the block(s) you want by creating a filtered selection set


mode = acSelectionSetAll
Set SSet1 = ThisDrawing.SelectionSets.Add("Myblocks")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 2: FilterData(1) = "PIPETAG"
SSet1.Select mode, , , FilterType, FilterData
then you know you're only getting the blocks you really want.

Barry Clark
14th Jan 2005, 04:12 am
Yeah, then you would need to set up a means to edit or view. I use For Each...Next and then a Select Case scanerio to edit the attribute info. ;)

hendie
14th Jan 2005, 09:14 am
a slightly more comprehensive approach

Dim BlkNm As AcadBlockReference
Dim BlkAtts As Variant
Dim FW As String
FW = MyTextBox.Value
Mode = acSelectionSetAll

Set SSet1 = ThisDrawing.SelectionSets.Add("SS1")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 2: FilterData(1) = "TheBlockName*"
SSet1.Select Mode, , , FilterType, FilterData

For Each BlkNm In SSet1
BlkAtts = BlkNm.GetAttributes
BlkAtts(0).TextString = FW
Next

If you have more than one attribute in the block you will neeed to set the properties accordingly.

j_r_auden
18th Jan 2005, 05:08 pm
I tried copying and pasting your program to play with it, but I have a couple of questions.

What does mode=asSelectionSetAll mean????
I have added notes on the lines I don't understand.
Please help if you can. Thanks again.

Dim BlkNm As AcadBlockReference
Dim BlkAtts As Variant
Dim FW As String
FW = MyTextBox.Value (I am getting an error from this line)
Mode = acSelectionSetAll (Don't know what this is doing)

Set SSet1 = ThisDrawing.SelectionSets.Add("SS1")
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
FilterType(0) = 0: FilterData(0) = "INSERT"
FilterType(1) = 2: FilterData(1) = "TheBlockName*"
SSet1.Select Mode, , , FilterType, FilterData (Don't know what this is doing)

For Each BlkNm In SSet1
BlkAtts = BlkNm.GetAttributes
BlkAtts(0).TextString = FW
Next

hendie
3rd Feb 2005, 09:17 pm
my apologies, I thought I had answered this some time ago.

asSelectionSetAll means selecting All ~ everything in the dwg

SSet1.Select Mode, , , FilterType, FilterData means you are selecting everything but filtering out the unwanted stuff. i.e. anything that isn't a block and in particular anything that isn't a block called "TheBlockName"
Then once you have the blocks, just cyle through them using

For Each BlkNm In SSet1
BlkAtts = BlkNm.GetAttributes <<== this gets ALL attributes in the block
do what you want with the attributes here
Next BlkNm

the attributes are returned in an array so you will need to test to see which ones you want. Of course if you have created the block then you know the order of the attributes, so it's easier to retrieve what you want