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"  

Parents
  • Jon does this allow me to speak to you ?
    I put all that together as shown, but it will not run ?  I acknowledge I do not know If I am to put in that font name ? somewhere.
    I apologize for my ignorance and certainly happy you responded.

    Option Explicit
    Option Base 0
    Option Compare Text
    '
    '
    '
    ' ---------------------------------------------------------------------
    '   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
    'Here 's a VBA wrapper around that MDL function …

    ' ---------------------------------------------------------------------
    '   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 searchLibs argument instructs the MDL function to search in only the active design file,
    'or in the active design file and attached DGNLibs.
    'With that understanding, we can write methods that figure out where a Text Style
    'is defined. First, is the Text Style defined only in the DGN file …
    '============================================================


    ' ---------------------------------------------------------------------
    '   TextStyleExistsInDgnFile
    '   Test whether a named Text Style exists in the active design file
    '   Returns:    True if found
    ' ---------------------------------------------------------------------
    Public Function TextStyleExistsInDgnFile(ByVal name As String) As Boolean
        TextStyleExistsInDgnFile = TextStyleExists(name, False)
    End Function

    'Second, is the Text Style defined either in the DGN file or in a DGNLib …

    ' ---------------------------------------------------------------------
    '   TextStyleExistsInLibrary
    '   Test whether a named Text Style exists in an attached DGNLib or
    '   in the active design file
    '   Returns:    True if found
    ' ---------------------------------------------------------------------
    Public Function TextStyleExistsInLibrary(ByVal name As String) As Boolean
        TextStyleExistsInLibrary = TextStyleExists(name, True)
    End Function

    'Finally, is the Text Style defined only in a DGNLib …

    ' ---------------------------------------------------------------------
    '   TextStyleExistsOnlyInLibrary
    '   Test whether a named Text Style exists only in an attached DGNLib
    '   and not in the active design file
    '   Returns:    True if found in DGNLib but not in active DGN file
    ' ---------------------------------------------------------------------
    Public Function TextStyleExistsOnlyInLibrary(ByVal name As String) As Boolean
          Const Anywhere As Boolean = True
          Const InDgnFileOnly As Boolean = False
        TextStyleExistsOnlyInLibrary = _
                TextStyleExists(name, Anywhere) _
                And Not _
                TextStyleExists(name, InDgnFileOnly)
    End Function


    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

  • 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

Reply
  • 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

Children