how to Text place above the element using vba?

Dear all,

          I am using Microstation v8i(SS3) and vba. i have linestring and i place the text(height of the vertex)  every vertex of the LineString its working fine but it's coming irregular like some text comes above the linestring and some text below the line but i need above the line.How to i get it any method is available for do it.

Thanks & Regards,

Karthik M

Parents
  • Hi Karthik,

    I agree with Frank more details would be helpful, both VBA code and also DGN file or at least a screen capture what situations you want to solve.

    Unknown said:
    but it's coming irregular like some text comes above the linestring and some text below the line

    It's not quite clear from your text if it's because the text is always in the same position and the line segment is crossing the text or the text itself is positioned irregularly in relation to the line string vertices.

    Unknown said:
    but i need above the line

    Can you provide an example what do you mean by "above the line". I can imagine "above line segment", but you wrote texts are placed at vertices.

    Unknown said:
    How to i get it any method is available for do it.

    I guess you will have to implement own method. VBA (in fact all MicroStation APIs) are usually "low level" and provide access to DGN format and related functions, but not to users functions like Place text (which are itself implemented using the same API).

    Depending on your conditions and requirements it can be quite easy (just to move text somewhere outside line string) or very complex (analyze best with with e.g. potential text rotation).

    With regards,

      Jan

  • hi jan&Frank,

                            Thanks for your response and sorry for insufficient information. Here i attached my sample dgn and paste my vba code please find it.

    Private Sub CreateText(ele As Element)
    Dim txtele As Element
    Dim hgt As Double
    Dim verts() As Point3d
    Dim i As Integer
    Dim pnt As Point3d
    Dim txtstr As String
    
    verts = ele.AsLineElement.GetVertices
    
    On Error Resume Next
    
    For i = 0 To UBound(verts)
        pnt = verts(i)
        hgt = pnt.Z
        txtstr = CStr(Round(hgt, 2))
        Set txtele = CreateTextElement1(Nothing, txtstr, pnt, Matrix3dIdentity)
        ActiveModelReference.AddElement txtele
        txtele.AsTextElement.TextStyle.Height = 0.2
        txtele.AsTextElement.TextStyle.Width = 0.2
        txtele.Rewrite
    Next i
    
    End Sub

    Thanks & Regards,
    Karthik M

    Text.dgn

  • Hi Karthik,

    my recommendations are:

    • Use Text Style, which allows to define all text parameters (namely line spacing and justification) exactly and text can be changed all together.
    • For every vertex, calculate angle axis (bisector of the angle), which defines text rotation. Take care about endpoints that have no angle bisector.
    • Place text using defined text style to vertex using the rotation.

    ... and it should be enough.

    But be aware this approach is too simple and does not solve situation when the angle is small (sharp), so text will not fit inside empty space. In such case the first enhancement can be to test angle orientation, so text will be placed abow or below the line depending on angle at vertex. More complex enhancement can be to test text bounding box and moving the text to empty space ... but it easily can lead to complex code.

    With regards,

      Jan

  • Hi jan,

               I am change my code for calculate angle then place the text its working but its come based on the line direction so some place text is coming different direction please see my dgn.

    3683.Text.dgn

    Thanks & Regards,

    Karthik M

  • What about to check the rotation angle and if it's too big (over PI) to convert it back to interval <0..PI> ?

    Regards,

    Jan
  • hi jan,
    Thanks jan now its working fine..
    Thanks & Regards,
    Karthik M
Reply Children
No Data