CE - Named Expression to obtain part of file name

I have a Named Expression the will look to the name of the active file and and report true or false if the file name contains the characters defined in the expression

So a file name of xXX_RoadDesign will report True with this expression System.String.Compare(System.String.SubString(System.Path.GetFileNameWithoutExtension(ActiveFile.FileName),0,3),"xXX").

Is it possible to create a similar expression that will look a the active file name and look at the first 3 characters of the active file name and report what those characters are?

Ex, if the active file name is aAA_RoadDesign the named expression will look at the file name and return "aAA". If I switch to a file named bBB_RoadDesign the expression would return "bBB"?

I'm looking to create a vba that will obtain the first 3 characters of a file name, which determines the discipline, to change a configuration variable to True/False based on those first three file name characters.

Parents
  • I'm looking to create a vba that will obtain the first 3 characters of a file name, which determines the discipline, to change a configuration variable to True/False based on those first three file name characters.

    Why not just do the entire process in VBA then, it’s probably the easiest approach of all?

  • Why not just do the entire process in VBA then

    That's what I am looking to do, as I stated in my original question.

    Microstation CONNECT - 10.17.2.61

    ORD - 2021 R1 10.10.1.3

    ORD 2022 R1.1 - 10.11.3.2

    ORD 2022 R3 -  10.12.2.4

    Microstation v8i SS 10 - 08.11.09.919

    Power InRoads v8i - 08.11.09.615

    ProjectWise - 10.0.3.453

  • Hi mwlong,

    you may want to start with VBA code similar to this code snippet:

    Dim s As String
    If Len(ActiveDesignFile.name) >= 3 Then
        s = Left(ActiveDesignFile.name, 3) 
        Debug.Print s
        If s = "xxx" Then
            ActiveWorkspace.AddConfigurationVariable "NewVariable", "newValue", True
        End If
    End If
    

    Best regards,

    Artur

  • Thanks for the information.

    Microstation CONNECT - 10.17.2.61

    ORD - 2021 R1 10.10.1.3

    ORD 2022 R1.1 - 10.11.3.2

    ORD 2022 R3 -  10.12.2.4

    Microstation v8i SS 10 - 08.11.09.919

    Power InRoads v8i - 08.11.09.615

    ProjectWise - 10.0.3.453

  • Oh I see, well your entire post could have been condensed to just the last sentence and it would have made more sense. The rest about Named Expressions is really irrelevant and must have confused me, especially since 'returning X number of characters from the start of a string' is such a commonly asked VBA query.

    Anyway, Artur's given a perfect solution, although I would use a Select Case statement instead of an IF statement but that's just my personal preference.

  • No problem. I tend to overdue it with details and try to give as much information as possible to avoid many questions in regards to my question. Too many times people ask a question, we give suggestions only to get the response "I already did that". A times my details may be irrelevant.

    Select Case statement instead of an IF statement

    Ultimately, I will need to use IF statements because I will be changing the on/off state of custom ribbon menus. The initial variables are set by a vba. The current process is more basic than I need so once the necessary variables are set I need to check the current state and test to see if the on/off state is true or false. So IF, THEN, ELSE statements will need to be incorporated. Currently our funding is not active so I need to put this on the back burner for a while.

    Microstation CONNECT - 10.17.2.61

    ORD - 2021 R1 10.10.1.3

    ORD 2022 R1.1 - 10.11.3.2

    ORD 2022 R3 -  10.12.2.4

    Microstation v8i SS 10 - 08.11.09.919

    Power InRoads v8i - 08.11.09.615

    ProjectWise - 10.0.3.453

  • So IF, THEN, ELSE statements will need to be incorporated.

    I'm not sure if you are familiar with the Select Case statement, its an alternative to an IF statement but does essentially the same thing, I just find it makes the code better to read, nothing more than personal preference.

    e.g.

    Public Sub SetVariables()
        Select Case Left(ActiveDesignFile.Name, 3)
            Case "aAA"
                ActiveWorkspace.AddConfigurationVariable "aAA_Variable", "Value", True
            Case "bBB"
                ActiveWorkspace.AddConfigurationVariable "bBB_Variable", "Value", True
            Case Else
                'Do nothing?
        End Select
    End Sub

    My rule of thumb is, if I'm checking a single condition, then I use IF condition THEN/End If, but if its multiple conditions then I use Select Case.

    Currently our funding is not active so I need to put this on the back burner for a while.

    Curious, what do you need funding for exactly, especially since its just a simple VBA with most of the code needed already provided in this topic? I would have classed this as just a basic CAD management tweak, is there something more involved in your work environment?

  • I'm not sure if you are familiar with the Select Case statement

    No familiar at all. I know just enough about vba to modify some existing code. I do see what you are doing with that in your code. It will probably be applicable for I will eventually need to do.

    Curious, what do you need funding for exactly,

    Working on this for a client. Funding has not been secured for further work so it is an all stop at this point.

    Microstation CONNECT - 10.17.2.61

    ORD - 2021 R1 10.10.1.3

    ORD 2022 R1.1 - 10.11.3.2

    ORD 2022 R3 -  10.12.2.4

    Microstation v8i SS 10 - 08.11.09.919

    Power InRoads v8i - 08.11.09.615

    ProjectWise - 10.0.3.453

Reply
  • I'm not sure if you are familiar with the Select Case statement

    No familiar at all. I know just enough about vba to modify some existing code. I do see what you are doing with that in your code. It will probably be applicable for I will eventually need to do.

    Curious, what do you need funding for exactly,

    Working on this for a client. Funding has not been secured for further work so it is an all stop at this point.

    Microstation CONNECT - 10.17.2.61

    ORD - 2021 R1 10.10.1.3

    ORD 2022 R1.1 - 10.11.3.2

    ORD 2022 R3 -  10.12.2.4

    Microstation v8i SS 10 - 08.11.09.919

    Power InRoads v8i - 08.11.09.615

    ProjectWise - 10.0.3.453

Children
No Data