Changing AttributeReference InsertionPoints

Changing AttributeReference InsertionPoints

Anonymous
Not applicable
486 Views
8 Replies
Message 1 of 9

Changing AttributeReference InsertionPoints

Anonymous
Not applicable
I am having difficulty changing AttributeReference InsertionPoints. My code is like:

varAttributes = bkrBlockRef.GetAttributes
For i = LBound(varAttributes) To UBound(varAttributes)
j = varattributes(i).InsertionPoint
j(1) = j(1) - 19.5
varAttributes(i).InsertionPoint = j
Next i

I get no error message, but the assignment
doesn't take. If I use subscripts like this:

For i = LBound(varAttributes) To UBound(varAttributes)
j = varattributes(i).InsertionPoint
j(1) = j(1) - 19.5
varAttributes(i).InsertionPoint(1) = j(1)
Next i

then I get an error "Object is not a collection"

Any help....?

--Wayne
0 Likes
487 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable
Hi Wayne,
I learned an important thing about insertion points a few months ago from a
post by Tony Tanzillo. VBA can't change insertion point coordinates
directly. (e.g. attRef.InsertionPoint(0) = 19) You need to copy the
insertion point to an array, change the values in the array, and finally,
set the insertion point to the modified array. This is demonstrated in the
following example.

'==========================================
Public Sub ChangeAttCoords()

Dim blkRef As AcadBlockReference
Dim varAtts As Variant
Dim attRef As AcadAttributeReference
Dim varP1 As Variant 'generic point
Dim intCnt As Integer

ThisDrawing.Utility.GetEntity blkRef, varP1, "Select Block:"
varAtts = blkRef.GetAttributes

For intCnt = LBound(varAtts) To UBound(varAtts)
Set attRef = varAtts(intCnt)
varP1 = attRef.insertionpoint
varP1(0) = varP1(0) + 2 'change the coordinate value
attRef .insertionpoint = varP1
Next intCnt

End Sub
'==========================================

Hope this helps, 🙂

- Adam <><

--
Enum SystemInfo
Cad_Software = "AutoCAD 14.01"
VB_Product = "VBA / VB6"
Platform = "WinNT4 SP5"
End Enum

"Wayneth" wrote in message
news:ef36b4e.-1@WebX.SaUCah8kaAW...
I am having difficulty changing AttributeReference InsertionPoints. My code
is like:
varAttributes = bkrBlockRef.GetAttributes
For i = LBound(varAttributes) To UBound(varAttributes)
j = varattributes(i).InsertionPoint
j(1) = j(1) - 19.5
varAttributes(i).InsertionPoint = j
Next i
I get no error message, but the assignment
doesn't take. If I use subscripts like this:
For i = LBound(varAttributes) To UBound(varAttributes)
j = varattributes(i).InsertionPoint
j(1) = j(1) - 19.5
varAttributes(i).InsertionPoint(1) = j(1)
Next i
then I get an error "Object is not a collection"
Any help....?
--Wayne
0 Likes
Message 3 of 9

Anonymous
Not applicable
Thanks Adam. What you're doing that I didn't do
was set the attributes to an AcadAttributeReference
variable. Your code isn't working for me either though.
The variant representing the insertionPoint (varP1)
is changing to the new value, but when I assign that
to the AcadAttributeReference variable (attRef)
with the statement: attRef .insertionpoint = varP1,
attRef's insertionPoint doesn't change. Have you tested
this code?

--Wayne
0 Likes
Message 4 of 9

Anonymous
Not applicable
Hi Wayne,
Yes, I did test the previous code. (using R14 VBA) It worked fine for me.
The following sub will loop through each attribute reference in a selected
block, and prompt you to change the insertion point to a selected point.
Paste the following code into a standard module.

'==========================================
Public Sub ChangeAttCoords()

Dim blkRef As AcadBlockReference
Dim varAtts As Variant
Dim attRef As AcadAttributeReference
Dim varP1 As Variant 'old point
Dim varP2 As Variant 'new point
Dim intCnt As Integer

ThisDrawing.Utility.GetEntity blkRef, varP1, "Select Block:"
varAtts = blkRef.GetAttributes

For intCnt = LBound(varAtts) To UBound(varAtts)
Set attRef = varAtts(intCnt)
'get the original insertion point for
'drawing the rubber band line.
varP1 = attRef.insertionpoint
'get the new insertion point
'for the attribute reference.
varP2 = ThisDrawing.Utility.GetPoint(varP1, "Select New Insertion
Point:")
'set the insertion point to the
'new coordinates.
attRef.insertionpoint = varP2
Next intCnt

End Sub
'==========================================

Let me know if this one works for you. 🙂

- Adam <><

"Wayneth" wrote in message
news:ef36b4e.1@WebX.SaUCah8kaAW...
Thanks Adam. What you're doing that I didn't do
was set the attributes to an AcadAttributeReference
variable. Your code isn't working for me either though.
The variant representing the insertionPoint (varP1)
is changing to the new value, but when I assign that
to the AcadAttributeReference variable (attRef)
with the statement: attRef .insertionpoint = varP1,
attRef's insertionPoint doesn't change. Have you tested
this code?
--Wayne
0 Likes
Message 5 of 9

Anonymous
Not applicable
Adam,
At first I thought the code still didn't work.
So far, however, it appears to work fine so long
as the attribute is left justified. The ones
that are middle-justified don't move. So I
modified your code with the line:

attRef.HorizontalAlignment = acHorizontalAlignmentLeft

and all the attributes are moving as desired.
Thanks for your assistance, you are the expert
of the day!

--Wayne
0 Likes
Message 6 of 9

Anonymous
Not applicable
Glad to help. 🙂

- Adam <><
0 Likes
Message 7 of 9

Anonymous
Not applicable
Wayne,

 

Use the property TextAlignmentPoint of the AcadText
object and you 'll have no problem with the alignment of the text.

 

Success,

Henk

 
0 Likes
Message 8 of 9

Anonymous
Not applicable
Hi Wayneth,
Your problem is also one of the typical problem which I also faced.
Below refer my code more or less similar to yours
use alignment as you need

attref.HorizontalAlignment = acHorizontalAlignmentRight
dpt(0) = Barloc(ii)
dpt(1) = PassY - 4#
dpt(2) = 0#
attref.TextAlignmentPoint = dpt
attref.Update
Bye
N.Murugan

Wayneth wrote:

> I am having difficulty changing AttributeReference InsertionPoints. My
> code is like:
>
> varAttributes = bkrBlockRef.GetAttributes
> For i = LBound(varAttributes) To UBound(varAttributes)
> j = varattributes(i).InsertionPoint
> j(1) = j(1) - 19.5
> varAttributes(i).InsertionPoint = j
> Next i
>
> I get no error message, but the assignment
> doesn't take. If I use subscripts like this:
>
> For i = LBound(varAttributes) To UBound(varAttributes)
> j = varattributes(i).InsertionPoint
> j(1) = j(1) - 19.5
> varAttributes(i).InsertionPoint(1) = j(1)
> Next i
>
> then I get an error "Object is not a collection"
>
> Any help....?
>
> --Wayne
0 Likes
Message 9 of 9

Anonymous
Not applicable

just have to use the .move method

 

attRef.Move attRef.insertionPoint, varP1

0 Likes