Set Line spacing on textnode using VBA

I am placing textnodes in a drawing using VBA and having issues in setting the line spacing value and type.  Seeing as textnodeelementtype does not have a textstyle property, I cannot set it directly.  I need to set the active text settings prior to adding my text node.  This is where my problem exists, as it seems when I try to set the height, width, nodespacingtype and nodespacing, MicroStation changes the spacing to be different by itself.

I want to set the values to be exact, and 0.5, which will make my line spacing half the text height.  but as soon as I change the text height, it changes my spacing.  Once the spacing has been adjusted by MicroStation, any repeated attempts in my code to change the spacing are ignored.

After studying the result Mstn changes my spacing to, it seems it is factoring the current spacing by the factor of the text height change.  changing text height from 1.0 to 3.5 will cause the nodespacing to change from 0.5 to 0.142857  (ie 1 / 3.5 * 0.5).  My drawing is metric.

The VBA code I am using to set Mstn settings is ....

  CadInputQueue.SendKeyin "textstyle active none "
  ActiveSettings.TextStyle.Height = 3.5
  ActiveSettings.TextStyle.Width = 3.5
  ActiveSettings.TextStyle.NodeLineSpacingType = msdTextNodeLineSpacingTypeExact
  ActiveSettings.TextStyle.NodeLineSpacing = 0.5

I have attempted to use other code here on the forum using a propertyhandler, to fix the element before adding to the drawing, but it refuses on the setvalue line.
 have no info on the propertyhandler structure until running the debugger, and that is only structure not explanations.

    Dim tnPH As PropertyHandler
    
        Set tnPH = CreatePropertyHandler(oTextNodeElement)
        tnPH.SelectByAccessString "LineSpacing"
        tnPH.SetValue 0.5
        tnPH.SelectByAccessString "LineSpacingType"
        tnPH.SetValue 0

Any help would be appreciated.

Parents
  • Fixed  - dont you hate it when you find the answer right after asking the question.

    If you type the linespacing into the textstyles dialog, it processes the number (you see it blink) and it returns to be what you typed.  If you type the command into MicroStation or using VBA, it will adjust it by the text height, so wont be what you ask it to be (unless your current text height is 1.0).  As a workaround, I have multiplied the line spacing by the required text height (already set) and after Mstn adjusts it, it comes out right.  The line of code now reads ..

     ActiveSettings.TextStyle.NodeLineSpacing = 0.5 * (<required_text_height>)

    Hope this helps someone someday

Reply
  • Fixed  - dont you hate it when you find the answer right after asking the question.

    If you type the linespacing into the textstyles dialog, it processes the number (you see it blink) and it returns to be what you typed.  If you type the command into MicroStation or using VBA, it will adjust it by the text height, so wont be what you ask it to be (unless your current text height is 1.0).  As a workaround, I have multiplied the line spacing by the required text height (already set) and after Mstn adjusts it, it comes out right.  The line of code now reads ..

     ActiveSettings.TextStyle.NodeLineSpacing = 0.5 * (<required_text_height>)

    Hope this helps someone someday

Children