Edit -As noted in the comments below – the original post had a typo in the line of code, SUBTR should actually be SUBSTR. Yet another reason to have values auto populate.  🙂

Scene: There we are, reviewing the title block and someone asks, can the title block have text be automatically generated based on a portion of the file path?

Mission: find a way to make the scene happen….

My first thought was to ignore the obvious – enter the desired text by hand into the appropriate sheet set field and move on. But that simply defeats the “automatically generated” aspect. Then, I thought, how do I build an expression in a field?

Several help and forum searches guided me to the ancient AutoCAD language of DIESEL, which stands for – I have no idea. According to Dietmar Rudolph, it stands for “Dumb Interpretively Evaluated String Expression Language” which you can download apparently and include in your apps if you so desire.  I soon found myself browsing the different functions to see which could help me.

After some trial and error, I again turned to the Google Genie.  And there it was, a link that used a similar reference. Although in his case, the desired text string has variable length, making it a bit more difficult. My solution had a fixed length and place in the file path. Here’s an example:

K:\50\610302\Design\2_BIModels\3_Civil3D\

We want to grab the 2 digit number and 6 digit number and have it display like this:

xx-xxxx-xx

So, re-using his methodology, I tested to see if I could just grab the first 2 digits. My expression began like this:

$(SUBSTR,$(GETVAR, DWGPREFIX),4,2) and yielded 50

Success! That worked? So, now I can grab the remaining digits but how do I get the dash to display? At first I tried using “-” after the field.

That gave me 50″-” as a result. Ah hah! I’m on to you DIESEL. So I took out the quotes and ran with my expression:

$(SUBSTR,$(GETVAR, DWGPREFIX),4,2)-$(SUBSTR,$(GETVAR, DWGPREFIX),7,4)-$(SUBSTR,$(GETVAR, DWGPREFIX),11,2)

The field returned 50-6103-02, exactly what was desired! Now, I can simply place this field in the title block and not have to populate the sheet set property.  Moving forward though, it would be extra beneficial to grab this value and place it in the sheet set ProjectNumber property so I can search based on project number in the Vault…. but that’s another day.