Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
OpenBuildings | AECOsim | Speedikon
  • Product Communities
  • Building
  • OpenBuildings | AECOsim | Speedikon
  • Cancel
OpenBuildings | AECOsim | Speedikon
OpenBuildings | AECOsim | Speedikon Wiki Extracting a text string between specific characters using Named Expressions
    • Building Design - Wiki
    • +OpenBuildings Designer
    • +OpenBuildings Energy Simulator
    • +GenerativeComponents
    • OpenBuildings Station Designer
    • +OpenBuildings Speedikon
    • +OpenBuildings Speedikon + Bentley Speedikon V8i
    • +Bentley Facilities Space Planner CONNECT Edition
    • -AECOsim Building Designer
      • +Annotation - AECOsim Building Designer
      • +Architectural Design - AECOsim Building Designer
      • +ASM (Analytical Space Model)
      • +Configuration - AECOsim Building Designer
      • +DataGroup System - AECOsim Building Designer
      • +Dataset and Content - AECOsim Building Designer
      • +Drawing Extraction - AECOsim Building Designer
      • +Drawing Views - AECOsim Building Designer
      • +Electrical Annotation and Design - AECOsim Building Designer
      • +Floors - AECOsim Building Designer
      • +Form Modeling - AECOsim Building Designer
      • +General - AECOsim Building Designer
      • +Grid Systems - AECOsim Building Designer
      • +HVAC Design - AECOsim Building Designer
      • +i-model - AECOsim Building Designer
      • +Import/Export - AECOsim Building Designer
      • +Installation - AECOsim Building Designer
      • +Modify - AECOsim Building Designer
      • -Platform Tools - AECOsim Building Designer
        • .NET error when selecting elements with manually attached EC data in the Item Browser
        • CONNECT Edition - Dimensions Are Larger Than Model
        • CONNECT Edition - Disrupted projection with Create Region tool
        • CONNECT Edition - How to change Z levels while moving elements
        • CONNECT Edition - Point Cloud not respecting visualization style
        • CONNECT Edition - Reference files don't allow color override setting
        • CONNECT Edition : Unable to find the Cell Library Dialog
        • Custom Linestyles change scale when using Copy to Clipboard and Paste to Clipboard
        • Dimensioning of Features on Walls
        • Extracting a text string between specific characters using Named Expressions
        • How to create 2D element array with variable
        • How to Create Parametric Objects using CEL (Parametric)
        • How to Determine the Placement Point of a Cell after it is placed?
        • How to Export from Item Browser to Excel
        • How to Manipulate a Reference
        • How to Open SKP Files in AECOsim Building Designer
        • How to reduce mesh faceting for cleaner drawing output
        • How to set reference sequence in AECOSim
        • Importing levels from an older version
        • Large Element Selections Slow to Move/Copy - Resolved in ABD SS6
        • Level in a reference file will not turn off using the Level Display tool
        • Material Editor is Missing Material Palette
        • Merge Design File
        • Plan view appears as a perspective orientation
        • Reference Level Display Manipulation
        • Save Relative Path function
        • Set Multi-Snap as default
        • Snap the corner of a structural beam or column
        • Snapping to Referenced Reality Meshes in AECOsim
      • +Plumbing Design - AECOsim Building Designer
      • +Print/Plot - AECOsim Building Designer
      • +ProjectWise Integration - AECOsim Building Designer
      • +Settings/Attributes - AECOsim Building Designer
      • +Space Planner - AECOsim Building Designer
      • +Structural Design - AECOsim Building Designer
      • +Utilities - AECOsim Building Designer
      • +Workspace - AECOsim Building Designer
    • +iModel Plugin for Revit
    • +Social Distance Assessments
    • Working from home with OpenBuildings products
    • Working from home with Speedikon
    • +Special Interest Group (SIG) FAQs
    • +Structural Modeler_PS
    • +Configuration Explorer
    • +Legacy Products
    • Learning Content for OpenBuildings Designer

     
     Questions about this article, topic, or product? Click here. 

    Extracting a text string between specific characters using Named Expressions

    Product(s): AECOsim Building Designer
    Version(s): 08.11.09.866
    Environment: N\A
    Area: Platform Tools
    Subarea: N\A

    Problem Description

    I've been able to successfully set up a Named Expression to parse my DGN file names, however I can't find a way to extract a specific variable length text string that consistently falls between specific characters.  For example, I have a DGN file named "MV_A01_Proyecto__Project.dgn where the first characters are the project code, the next set is the sheet number, and the next two represent a bi-lingual version of "Project". 

    I am able to get the project code extracted since it always uses three characters:
    System.String.Substring(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),3,3)

    The second set of characters are extracted beginning with the "_" until the end of the file name:
    IIf (System.String.Indexof (System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__") >= 0,System.String.Substring (System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), System.String.Indexof (System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__") +2, -1),System.Path.GetFileNameWithoutExtension (ActiveFile.FileName))

    However, that middle Spanish translation may change character lengths so I would like to parse the text string that falls between "_" and "_".   Is this possible?

    Steps to Resolve

    Yes, if you can change the file naming convention to use a double "__" on both sides of that text string, the following expressions may work when plugged into your IF statement:

    FileName_Last

    System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.LastIndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__")+2, -1)

    FileName_Next Last

    System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.IndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__")+2, Session.EvalNEAsInt ("FileName_NextLastMinusLast",0)  )

    FileName_NextLastMinusLast

    System.String.Length(System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.IndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__")+2, -1))
    -
    System.String.Length(System.String.SubString(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName),System.String.LastIndexOf(System.Path.GetFileNameWithoutExtension (ActiveFile.FileName), "__"), -1))


    The "FileName_NextLastMinusLast" expression essentially returns a number difference between Proyecto__Project "and" Project and is used in the expression "FileName_Next Last".   Expressions could also be adjusted to potentially trim mv_A01_Situación-Situation.dgn.

    See Also

    http://communities.bentley.com/products/microstation/microstation_printing/f/19568/p/113250/349437#349437

      Original Author: Steve Cocchi
    • Named Expressions
    • 08.11.09.866
    • AECOsim
    • en
    • AECOsim Building Designer
    • SELECTsupport
    • Platform Tools
    • Share
    • History
    • More
    • Cancel
    • Steve Cocchi Created by Bentley Colleague Communities MVP Steve Cocchi
    • When: Thu, Sep 29 2016 5:50 PM
    • Steve Cocchi Last revision by Bentley Colleague Communities MVP Steve Cocchi
    • When: Thu, Sep 29 2016 5:53 PM
    • Revisions: 2
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies