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"
Richard Phillips said:can you use VBA to know there are styles loaded ?
Here are some ideas that use VBA to find information about Text Styles.
There are some things that VBA can't do, and for that reason the code calls an MDL function. I've provided a link to the MicroStation V8 article: if you are writing code for MicroStation CONNECT then see this article because the MDL wrappers are different.
Regards, Jon Summers LA Solutions
Version: MicroStation V8i SS 10
RJB Phillips III (Richard) Praise the Lord for His Mercy and grace in Christ Jesus
Richard Phillips said:I put all that together as shown, but it will not run ?
If you copied all that into your own VBA project, it should run OK.
You need to call one of the methods in your code. Here's an example...
Public Sub Main () Dim styleName As String styleName = "DFS_250x250UL" Dim msg As String If TextStyleExists (styleName) Then msg = "Found text style '" & styleName & "'" ShowMessage msdMessageCenterPriorityInfo, msg, msg, False Else msg = "Text style '" & styleName & "' is not available" ShowMessage msdMessageCenterPriorityWarning, msg, msg, False EndIf End Sub
Usage...
vba run modMain.Main ' Where modMain is the name of your VBA module
Jon thank you again, I copied the suggestion and when I ran I got the error message
'========================= ' Example from Jon Summers ' to botain if style exists '=========================== Public Sub Main() Dim styleName As String styleName = "DFS_250x250UL" Dim msg As String If TextStyleExists(styleName) Then msg = "Found text style '" & styleName & "'" ShowMessage msdMessageCenterPriorityInfo, msg, msg, False Else msg = "Text style '" & styleName & "' is not available" ShowMessage msdMessageCenterPriorityWarning, msg, msg, False End If End Sub
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
Richard Phillips said: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
Yes, Thank you so very much for the patient help on this subject
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 WingSenior Systems Analyst
Rod Wing said:I go low-tech...
There are two reasons why I took the longer approach...
Set ts = ActiveDesignFile.TextStyles.Item(styleName)
But, if those concerns don't apply, by all means take that simple route.