Hi All, I am having an issue trying to modify text styles in a dgnlib programatically. I have tried both a VB and a BASIC Macro and getting the same results. I am trying to change the font on all the textstyles then save them. The macro makes the change but does not save the styles. I have tried the selectall and tried iterating through the styles.
The strange thing is if I step through the macro it will save and if I run the macro twice from the basic editor or vb editor it will save the styles. Running it twice outside the editors and it will not save. It also works using the key ins manually. Here is the basic code I am using,
Sub main Dim startPoint As MbePoint Dim point As MbePoint, point2 As MbePoint
' Start a command MbeSendCommand "MDL KEYIN textstyle textstyle dialog open"
' Send a keyin that can be a command string MbeSendKeyin "textstyle selectall" MbeSendKeyin "textstyleset font 1" MbeSendKeyin "textstyle saveall" End Sub
The VB code is similar.
Sub Macro1() Dim startPoint As Point3d Dim point As Point3d, point2 As Point3d Dim lngTemp As Long
' Start a command CadInputQueue.SendCommand "MDL KEYIN textstyle textstyle dialog open"
CadInputQueue.SendCommand "TEXTSTYLE DESELECT ALL"
CadInputQueue.SendCommand "TEXTSTYLE SELECT ""Style (none)"""
CadInputQueue.SendCommand "TEXTSTYLE SELECT ""Large"""
CadInputQueue.SendCommand "TEXTSTYLE SELECT ""Small"""
CadInputQueue.SendCommand "TEXTSTYLESET Font ""font001.rsc"" ""None"" ""Large"" ""Small"""
CadInputQueue.SendCommand "TEXTSTYLE Save"
CommandState.StartDefaultCommandEnd Sub
Any wisdom or guidance is greatly appreciated. Thank you
Hi Don,
at first, please use Syntaxhighlighter tool when you post a code and set the syntax to "VB", so it will be displayed and colored properly ... and will make your code much easier readable.
Also please read and follow MicroStation Programming Forum Best Practices, e.g. an information about MicroStation version is missing.
Unknown said:I have tried both a VB and a BASIC Macro
Don't use MicroStation BASIC. Never ever. It's deprecated from MicroStation V8.0 (15 years!) and is not supported, only maintained because of backward compatibility. And removed from MicroStation CONNECT Edition.
Unknown said:It also works using the key ins manually.
It is weird, because if I use e.g. TEXTSTYLE DESELECT ALL is unknown if MicroStation V8i (SELECTseries 4) is used. I also see no TEXTSTYLE SELECT key-in
Unknown said:Any wisdom or guidance is greatly appreciated.
In general to use macros to interact with dialogs leads to fragile and not always working code. It's always recommended to check if a proper API exists for the particular topic.
Quick example (not any testing done, but it should work ;-) how font in textstyles can be changed in batch (of course in active file only):
Sub ChangeFontInTextStyle() Dim newFont As Font Set newFont = ActiveDesignFile.Fonts.Find(msdFontTypeWindowsTrueType, "Arial") Dim ts As TextStyle For Each ts In ActiveDesignFile.TextStyles ts.Font = newFont Next End Sub
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Unknown said:unfortunately my mystery still remains.
Why? Your answer provides no information :-(
You tried to use macro in not very fine and not recommended way. To use VBA to change TextStyle parameters (Font in this case) works fine and without any problem. So why and what mistery does remain?
Unknown said: texstyle saveall is available, but unfortunately it does not change the main issue: It doesn't work correctly
Thanks for pointing that out. I've updated our web page to include a comment about that.
That begs the question, "How do we save a text style programmatically (using either VBA or MDL)?" Does CONNECT behave any better?
Regards, Jon Summers LA Solutions
I don't know whether it is helpful to add a COMPRESS DESIGN keyin for every dgnlib?
This keyin can make save file explicitly.