Session.ExpandMacros()
Session.ExpandEmbeddedVariables()
Session
ConfigurationManager
Hi Jon Summers,
Session::ExpandMacros and Session.ExpandEmbeddedVariables both produce similar results. Both expanding input strings provided containing any embedded macro names (starting with '$[' or '$(') to fully expanded values; where ExpandMacros calls the ConfigurationManager API directly and ExpandEmbeddedMacros via the MDL WString API.
I am unable to comment on why these methods were not provided in the ConfigurationManager API directly. However, to emulate either method's expansion capabilities the code would need to find the position of the first open variable expansion operators ('$[' or '$(') and the last close operator and while able to extract more paired items each one found call ConfigurationManager:GetVariable; to expand each.
HTH,
Bob
Answer Verified By: Jon Summers
Hi Bob,
thanks a lot for detail explanation!
Robert Hook said:Session::ExpandMacros and Session.ExpandEmbeddedVariables both produce similar results.
It would be great whether API author explain reasons for existence in help file. To have more methods providing similar functionality without knowing whether they are the same or different is confusing and often lead to wasted time.
It's not the only case in MicroStation API: E.g. there is no explanation when and why to use NotificationManager and when MessageCenter, even when they provide very similar functionality.
With regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Robert Hook said:to emulate either method's expansion capabilities the code would need to find the position of the first open variable expansion operators ('$[' or '$(') and the last close operator
Regular expressions (RegEx) are preferable. A RegEx can isolate matching tokens, where a token might be $(...). An API can typically extract multiple matches and replace each match with some other string.
$(...)
For example, given this string: abc $(cfgVar1) def $(cfgVar2), RegEx (\$\(.*?\)) matches $(cfgVar1) and $(cfgVar2).
abc $(cfgVar1) def $(cfgVar2)
(\$\(.*?\))
$(cfgVar1)
$(cfgVar2)
Here's some more info about regular expressions and a VBA example.
I notice that freeware developer tool LINQPad now has a built-in RegEx evaluator.
Regards, Jon Summers LA Solutions