Block with attribute vba

Block with attribute vba

calteq
Contributor Contributor
1,647 Views
3 Replies
Message 1 of 4

Block with attribute vba

calteq
Contributor
Contributor

Having a problem justifying the text of an attribute created in vb ...

 

here's an simple example ..

 

Sub BlkAttribute()

 

    Dim blockObj As AcadBlock
    Dim insertionPnt(0 To 2) As Double
    Dim txtstyle As AcadTextStyle
    Dim Pnts(0 To 9) As Double
   
    insertionPnt(0) = 0
    insertionPnt(1) = 5
    insertionPnt(2) = 0
   
    Set blockObj = ThisDrawing.Blocks.Add _
                     (insertionPnt, "BlockWithAttribute")
                    
    Pnts(0) = -7.5: Pnts(1) = 5
    Pnts(2) = -7.5: Pnts(3) = 10
    Pnts(4) = 7.5: Pnts(5) = 10
    Pnts(6) = 7.5: Pnts(7) = 5
    Pnts(8) = -7.5: Pnts(9) = 5

    ' Create a lightweight Polyline object in model space
    Set plineObj = blockObj.AddLightWeightPolyline(Pnts)

    ' Add an attribute to the block
    Dim attributeObj As AcadAttribute
    Dim height As Double
    Dim mode As Long
    Dim prompt As String
    Dim insertionPoint(0 To 2) As Double
    Dim tag As String
    Dim value As String
   
    height = 3.5
    mode = acAttributeModeVerify
    prompt = "New Prompt"
   
    insertionPoint(0) = 0
    insertionPoint(1) = 7.5
    insertionPoint(2) = 0
   
    tag = "New Tag"
    value = "New Value"
   
    Set attributeObj = blockObj.AddAttribute(height, mode, _
                          prompt, insertionPoint, tag, value)

 

    'attributeObj.Alignment = acAlignmentBottomCenter
    
    Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock _
               (insertionPnt, "BlockWithAttribute", 1#, 1#, 1#, 0)

End Sub

 

the attribute is created with a 'left' justification.

 

when the hi lited part of the code is used the attributes insertion point is changed to 0,0

 

Any suggestions!!!!

 

Regards

Geoff

 

 

 

 

 

 

 

0 Likes
Accepted solutions (1)
1,648 Views
3 Replies
Replies (3)
Message 2 of 4

arcticad
Advisor
Advisor

It's a known bug. You will need to move the attributes insertion point back to the known location after you change the justification.

 

---------------------------



(defun botsbuildbots() (botsbuildbots))
0 Likes
Message 3 of 4

calteq
Contributor
Contributor

Thx arcticad

 

probably an easy solution for the more knowledgable ....

 

Have trawled thro many web pages to no avail!

 

Have tried this after the alignment statement ....

 

    attributeObj.Move (origin,insertionPoint) .... get 'syntax error'

    attributeObj.Move(origin,insertionPoint)  ... get 'complie error' expected '='

    attributeObj.Move = insertionPoint .....        get 'complie error'   'argument not optional'

 

something I'm not doing correctly ....

 

Hope you don't mind pointing me in the right direction.

 

Geoff

0 Likes
Message 4 of 4

calteq
Contributor
Contributor
Accepted solution

Thx arcticad

 

I've managed to do it ...

 

        attributeObj.Move Origin, CtrPnt

 

Regards Geoff

 

0 Likes