Sean
Guest
|
Posted:
Thu Sep 22, 2005 4:10 pm Post subject:
Redefine Block Attributes with VBA |
|
|
Hello,
I'm trying to change the text attribute, within a number of blocks, to
fit. At first I built a selection set to select all the blocks and
then change the textalignment to fit, however this won't redefine the
blocks in the drawing.
Here's the code I currently have to find the associated blocks and
change the text alignment to fit. This doesn't work either as the fit
does not work correctly. What is the best way to set the boundaries
for a text fit?:
Public Sub UpdateAttribute()
Dim sset As AcadSelectionSet
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
Set sset = ThisDrawing.SelectionSets.Add("SS1")
' Set your criteria
FilterType(0) = 2 'Looks for Block Name
FilterData(0) = "MFDG0624" 'Looks for MFDG0624 block in the dwg
sset.Select acSelectionSetAll, , , FilterType, FilterData
Dim x As Integer
Dim i As Integer
Dim objBlock As AcadBlockReference
Dim obj As AcadEntity
Dim varAtts() As AcadAttributeReference
x = 1
For Each obj In sset
Set objBlock = obj
If obj.HasAttributes Then
varAtts = obj.GetAttributes
For i = LBound(varAtts) To UBound(varAtts)
If Len(varAtts(i).TextString) = 4 Then
varAtts(i).Alignment = acAlignmentFit
End If
Next i
obj.Update
Next obj
ThisDrawing.SelectionSets.Item("SS1").Delete
End Sub
Would a better solution be to redefine all the blocks (approx. 15) in
the model using vba? In order to do this I would need to build a
selection set for each block, explode the block, change the text
alignment to fit, and then reinsert the block to redefine all similar
blocks in the drawing, correct?
Thanks, Sean
|
|
NeAnDuhTall
Joined: 24 Oct 2005
Posts: 1
Location: Tauranga, New Zealand
|
Posted:
Mon Oct 24, 2005 5:02 am Post subject:
selecting Blocks with SelectionSet... |
|
|
Hi Sean,
This is a late reply and you may have already solved this one (I'm new to this forum).
The first thing that I can see in your code is that your selection set filters are not quite correct for what you are trying to do.
You need to add another group code/value pair to your selectionset filter, so replace the following section of your code...
Dim FilterType(0) As Integer
Dim FilterData(0) As Variant
Set sset = ThisDrawing.SelectionSets.Add("SS1")
' Set your criteria
FilterType(0) = 2 'Looks for Block Name
FilterData(0) = "MFDG0624" 'Looks for MFDG0624 block in the dwg
...with this:-
Dim FilterType(0 To 1) As Integer
Dim FilterData(0 To 1) As Variant
Set sset = ThisDrawing.SelectionSets.Add("SS1")
' Set your criteria
FilterType(0) = 0 'Group code '0' specifies that we are going to filter by entity type
FilterType(1) = 2 'Group Code '2' specifies that we are also going to filter by name...
FilterData(1) = "INSERT" 'Specifically we are looking for entities of type AcDbBlockReference
FilterData(0) = "MFDG0624" ...whose name is 'MFDG0624'
From this point on your original code should work (no gaurantees though - I don't work with VBA/VB6 - only VB.NET).
The important point to note is that the instances of Blocks which you see scattered in your AutoCAD drawing are not actually the same as "Blocks" when you are working in VBA/VB. The visible instances of a Block in a drawing are actually "Block Reference" Entities, and a "Block" Entity is actually just the definition of the block stored within the drawing.
So, if you change the "Block" entity in a drawing, your just changing the definition. The changes won't be visible until you insert another instance of the block into the drawing. Changing the definition doesn't automatically update all the instances of a block in the drawing.
To do that , you need to change each instance of the block, and in VBA/VB an instance of a block is called a Block Reference - as you have picked up on I assume as you have correctly assigned your objBlock variable as an AcadBlockReference.
The only thing you were missing was that you Selection set filters weren't set up right. They are confusing I must admit, and some good references on the web are:-
http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=2768231
and:-
http://www.autodesk.com/techpubs/autocad/acad2000/dxf/
Hope this helps some (if you read it that is...) _________________ Glenn Laugesen
CAD User, Software guy and all 'round geek! |
|