PDA

View Full Version : VBA Block population



Barry Clark
21st Jan 2005, 03:37 pm
Sub block_populate()
Dim attributeObj As AcadAttribute
Dim insertionPoint(0 To 2) As Double
insertionPoint(0) = 0
insertionPoint(1) = 0
insertionPoint(2) = 0
attributeObj = ThisDrawing.ModelSpace.AddAttribute(4, acAttributeModeConstant, "prompt", insertionPoint, "tag", "value")
End Sub
Hendi, can you tell me what is wrong here?

hendie
21st Jan 2005, 05:15 pm
try changing your last line to :


Set attributeObj = ThisDrawing.ModelSpace.AddAttribute(4, acAttributeModeConstant, "prompt", insertionPoint, "tag", "value")

Barry Clark
21st Jan 2005, 06:47 pm
That worked great. Thanks!

What about justification?

Also, I have never been clear on the most simple way to convert Variant to Double. Any thoughts?

hendie
21st Jan 2005, 07:04 pm
use the alignment property

attributeObj.Alignment =acAlignmentMiddleCenter

if you're asking what I think you're asking, I normally just use something like
(assuming you've already returned a variant)


dim mypoint (0 to 2) as double
mypoint(0)=myvariant(0) : mypoint(1)=myvariant(1) : mypoint(2)=myvariant(2)

Barry Clark
21st Jan 2005, 07:25 pm
Yeah, that is what I did as far as variant to double.

Thanks on the justification!

You can always count on the Scottish. :wink:


added later: for those referencing this thread, justify after insertion:

Set attributeObj = ThisDrawing.ModelSpace.AddAttribute(3 / 32, acAttributeModeConstant, "prompt", insertionPoint, "tag", "value")
attributeObj.Alignment = acAlignmentMiddleCenter

Barry Clark
21st Jan 2005, 07:38 pm
Crap.

This

Sub block_populate()
Dim inspnt As Variant
inspnt = ThisDrawing.Utility.GetPoint(, vbCr & "Pick insertion point: ")
Dim attributeObj As AcadAttribute
Dim insertionPoint(0 To 2) As Double
insertionPoint(0) = inspnt(0)
insertionPoint(1) = inspnt(1)
insertionPoint(2) = inspnt(2)
Set attributeObj = ThisDrawing.ModelSpace.AddAttribute(3 / 32, acAttributeModeConstant, "prompt", insertionPoint, "tag", "value")
attributeObj.Alignment = acAlignmentMiddleCenter
End Sub keeps inserting my tag at 0,0. I am sure it is something simple that I am overlooking but it is escaping me at the moment.

hendie
21st Jan 2005, 08:21 pm
it's a buggy feature of VBA
btw, I've changed your variable name from Insertionpoint as that is already a property of the acadattribute


Dim inspnt As Variant
inspnt = ThisDrawing.Utility.GetPoint(, vbCr & "Pick insertion point: ")
Dim attributeObj As AcadAttribute
Dim Ipnt(0 To 2) As Double
Ipnt(0) = inspnt(0)
Ipnt(1) = inspnt(1)
Ipnt(2) = inspnt(2)
Set attributeObj = ThisDrawing.ModelSpace.AddAttribute(3 / 32, acAttributeModeConstant, "prompt", Ipnt, "tag", "value")
attributeObj.Alignment = acAlignmentMiddleCenter
attributeObj.TextAlignmentPoint = Ipnt


when you change the alignment, the object for some reaon "loses" it's insertion point and resets to 0,0 as you discovered. After you have set the alignment you need to feed it the insertion point again as a TextAlignmentPoint

Barry Clark
21st Jan 2005, 08:27 pm
when you change the alignment, the object for some reaon "loses" it's insertion point and resets to 0,0 as you discovered. After you have set the alignment you need to feed it the insertion point again as a TextAlignmentPointThank you, sir. Worked like a charm.