Obtaining if Text Style name exists

Running Select 10

How can I via VBA find out the name of the text file in a current .dgn

I do know how to do manually by Element>Text Styles and see them , but can you use VBA to know there are styles loaded ?

Example: I know if they are there is a Style name DFS_250x250UL  without manually looking is it possible to get VBA to check its existance

than if it was not the macro would import the .dgnlib  which is named "DupontFontStyles.dgnlib"  

  • This problem is now solved and MicroStation is again working properly

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

    Answer Verified By: Robert Hook 

  • Rod this is what I have but nothing happens if you attempt to run this function?


    Public Function TextStyleExists(DFS_250x250 As String) As Boolean
    On Error GoTo NO_STYLE
    Dim ts As TextStyle

    Set ts = ActiveDesignFile.TextStyles.Item(DFS_250x250)
    TextStyleExists = Not (ts Is Nothing)

    Exit Function

    NO_STYLE:
    TextStyleExists = False
    End Function

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Rod, Tech support fixed my MicroStation:

    could you explain a little what to do after 

    set ts = ActiveDesignFile.TextStyles.Item(styleName)



    my style name in example 1: DFS_250x250 - This is basic Text Files

    my style name in Example 2: DFS_250x250UL - This is Custom Text Files

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Thank you very much for the reply. I had a MicroStation Crash and now I no longer have an Import feature for Textstyles or Dim Styles ?
    I am trying for support, It a problem, myself (76 yrs old) and a brother in Australia  was unable to figure it out. So at this point the macro will not help me
    So thank you for taking the time to help me.


    Praise the Lord for His Mercy and Grace in  Christ Jesus
    Richard, Gmail.com


    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Thanks, I'll check it out. 

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • I go low-tech...

    There are two reasons why I took the longer approach...

    Set ts = ActiveDesignFile.TextStyles.Item(styleName)
    • At some stage in the past that failed when the text style doesn't exist.  I think in one version (V8 era) of MicroStation the error wasn't caught and everything stopped.  Maybe it's OK with CONNECT
    • It doesn't work when the text style exists in a DGNLib and hasn't yet been copied to the active file.  My code example shows how to get the text style from a DGNLib

    But, if those concerns don't apply, by all means take that simple route.

     
    Regards, Jon Summers
    LA Solutions

  • Sorry for being late to the party. 

    I go low-tech on these kind of tests, keeping it all VBA and avoiding MDL calls if I can.

    Here is my example for how to accomplish it.

    Public Function TextStyleExists(styleName As String) As Boolean
        On Error GoTo NO_STYLE
        Dim ts As TextStyle
        
        Set ts = ActiveDesignFile.TextStyles.Item(styleName)
        TextStyleExists = Not (ts Is Nothing)
        
        Exit Function
        
    NO_STYLE:
        TextStyleExists = False
    End Function

    Rod Wing
    Senior Systems Analyst

  • Yes, Thank you so very much for the patient help on this subject

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus

  • Should I add Dim SUCCESS as something ?

    Look at the article with the code you copied.  There's a definition for SUCCESS just after the MDL function declaration...

    ' ---------------------------------------------------------------------
    '   MDL function declarations
    ' ---------------------------------------------------------------------
    Declare Function mdlTextStyle_getByName Lib "stdmdlbltin.dll" ( _
        ByRef pStyle As Long, _
        ByRef pTextStyleId As Long, _
        ByVal pStyleName As Long, _
        ByVal modelRef As Long, _
        ByVal SearchLibrary As Long) As Long
    Private Const SUCCESS                       As Long = 0

     
    Regards, Jon Summers
    LA Solutions

  • Jon when I first ran Debug on this example

    I am getting Variable not defined on the word SUCCESS ?

    Should I add Dim SUCCESS as something ?


    ' ---------------------------------------------------------------------
    '   TextStyleExists
    '   Wraps MDL function that searches for a Text Style in DgnLibs
    '   as well as the active DGN file
    '   Returns: True if style is found
    ' ---------------------------------------------------------------------
    Public Function TextStyleExists(ByVal name As String, ByVal searchLibs As Boolean) As Boolean
        Dim styleAddress                        As Long
        Dim styleIdAddress                      As Long
        styleIdAddress = -1
        TextStyleExists = (SUCCESS = mdlTextStyle_getByName( _
                      styleAddress, styleIdAddress, StrPtr(name), _
                      ActiveModelReference.MdlModelRefP, searchLibs))
        Debug.Print "style ID=" & CStr(styleIdAddress)
    End Function

    The 

    Version: MicroStation V8i SS 10

    RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus