VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Change Block Attribute Insertion point

7 REPLIES 7
Reply
Message 1 of 8
poflynn
2271 Views, 7 Replies

Change Block Attribute Insertion point

In need to modify an attributes insertion point in an existing block (ACAD 2002)

(part code)

CurrInsrt = attr.InsertionPoint
insrt(0) = 100 + CurrInsrt(0)
insrt(1) = 100+ CurrInsrt(1)
insrt(2) = 0 + CurrInsrt(2)
attr.InsertionPoint= insrt

dosen't work and I can't figure out why. CurrInsrt is a variant, insrt is a double(0 to 2)


I saw the entry about using TextAlignmentPoint but if the attribute is rotated it is rotated around the insertion point not the TextAlignmentPoint

phill
7 REPLIES 7
Message 2 of 8
Bryco
in reply to: poflynn

Do it in cad first then code it.
If you are updating the block, you still have to reinsert all the blockreferences to see the new attribute positions, just like doing it in cad.If you are finding each blockreference and moving the att without updating the block, you better read up on matricies
Message 3 of 8
poflynn
in reply to: poflynn

Yes I am updating it with attr.update.

But as far as I cantell I am essentially following the example in the help file

I have tested the other lines and all seems correct.

"attr.InsertionPoint= insrt
attr.update"

is not working and I can't figure out why
Message 4 of 8
NathTay
in reply to: poflynn

Are you modifying the block definition or each individual block reference. If you are modifying the def only then in AutoCAD try the command ATTSYNC.

Regards - Nathan
Message 5 of 8
poflynn
in reply to: poflynn

I am actually just trying to change each block reference attribute individually.

the way I have been doing it is by using the move command to reposition the attribute.

Is the insertionpoint property a global thing ie applies to the block not the block referenece? that would mean i'd have to sync it for the changes to take affect. In which case I won't use it because the changes will be applied to all blocks

Phill
Message 6 of 8
arcticad
in reply to: poflynn

I'm sure there is an easier way but this has worked fine for me.

You just need to set the xyz of the attribute. You do not use move.

since you can't reference the insertionpoint with att.insertionpoint(0) i just run it through a simple convertion

dim pt(2) as double
pt(0) = convertpt(att.insertionpoint,0)
pt(1) = convertpt(att.insertionpoint,1)
pt(2) = convertpt(att.insertionpoint,2)

then you can just add say an x distance to the value or whatever to move the attributes around.

then assign the new point to your att.insertionpoint

[code]

Function convertpt(pt, pos) As Variant
Dim k As Integer
Dim newpt(2) As Double
For Each item In pt
If j = pos Then
k = k + 1
If k = 1 Then
convertpt = item
End If
If k = 2 Then
convertpt = item
End If
If k = 3 Then
convertpt = item
End If
End If
j = j + 1
Next

End Function

[/code]
---------------------------



(defun botsbuildbots() (botsbuildbots))
Message 7 of 8
Anshu
in reply to: poflynn

Hi Poflynn
I am not sure but try to regenerate your drawing at end of your code might be it work.
Thanks
Message 8 of 8
Bryco
in reply to: poflynn

Guess I was wrong about matricies for the 2d stuff

[code]Sub moveatt(B As AcadBlockReference, Dist As Double)

Dim Att As AcadAttributeReference
Dim Atts, Pt
Dim Rot As Double

Set B = EntSel
Atts = B.GetAttributes
Set Att = Atts(0)
' Att.LockPosition check that
Rot = Att.Rotation
Pt = Att.TextAlignmentPoint
Pt(0) = Pt(0) + Cos(Rot) * Dist
Pt(1) = Pt(1) + Sin(Rot) * Dist
Att.TextAlignmentPoint = Pt

End Sub
[/code]

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost