Named Expression Syntax

Using AECOSIM CONNECT UPDATE 1 | Windows 8.1

Trying to customize some ribbon buttons using Named expressions. What I want to do is recognize a portion of a file name and if it matches show a button and if not don't show a specific button.

I have spent a significant amount of time and tried many different possibilities (substring, length -, getfilenamewithoutextension and others)  and all have given me grief.

I feel the approaches below have been the most promising, because the individual pieces seem to work. However when I combine and click the Test button to evaluate, I get a "can not evaluate expression" error instead of a true or false.

System.String.IndexOf(ConfigVar.GetExpandedConfigVar("_DGNFILE"), ”_GUI.DGNLIB”) > 0

System.String.IndexOf(System.String.ToString(ConfigVar.GetExpandedConfigVar("_DGNFILE"), ”_GUI.DGNLIB”)) > 0

What am I doing wrong?

Thanks in advance

Keith

Parents
  • Figured out my own solution add to incorporate a system.string.substring and do a compare to the string returned. as shown below.

    System.String.SubString(ConfigVar.GetExpandedConfigVar("_DGNFILE"), System.String.IndexOf (ConfigVar.GetExpandedConfigVar("_DGNFILE") , "_GUI.DGNLIB"), -1)="_GUI.DGNLIB"

    Thanks to anyone who was looking into.

    Keith

  • Hi Keith,

    I was not able to answer earlier because of different time zone. It's good to know you found the solution, but in my opinion it can implemented in better way.

    I see two situation when the used approach will not work properly:

    • The comparison is not case insensitive, so "_GUI.DGNLIB" will work but "_gui.dgnlib" not. My experience is that it's hard to fulfill a policy whether the letter are always capitals, so it's better to use case insensitive comparisons.
    • It will not work with "crazy file names" like myfile_gui.dgnlib_test_gui.dgnlib, because you tested the first occurence of "_gui.dgnlib" string and not the last one. It can be solve using .LastIndexOf method instead of .IndexOf.

    There is another solution using different approach:

    System.String.CompareI(System.String.Substring (ConfigVar.GetExpandedConfigVar("_DGNFILE"),System.String.Length(ConfigVar.GetExpandedConfigVar("_DGNFILE"))-11, -1),"_GUI.DGNLIB")

    To decode this train wrack (which is usually treated as dirty code, but there is no other solution how to keep everything in one line ;-)

    1. ConfigVar.GetExpandedConfigVar("_DGNFILE") ... _DGNFILE is expanded to the full path
    2. System.String.Length(ConfigVar.GetExpandedConfigVar("_DGNFILE")) ... the full path length (number of characters)
    3. Length - 11 is an index where "_gui.dgnlib" substring starts.
    4. System.String.Substring(...) ... takes the whole path and produces substring from (length - 11) position to the end of the string, which is expected to be "_gui.dgnlib" or "_GUI.DGNLIB".
    5. System.String.CompareI(...) ... provides case insensitive string comparison, so a result is indifferent whether the substring is in capital letters or no.

    With regards,

      Jan

  • Thank you Jan! After reading and testing out your reply I have adjusted my solution to match yours because it is much more flexible.

Reply Children
No Data