Set code prefix based on start of name

In our project we needed standard prefixes in our tables but we wanted to have complete names in the entities. Powerdesigner supports custom name to code scripts but they have to be written in GTL and not everything from GTL seems supported. For my use case, write vba scripts was much easier.

This code takes the name of an entity and checks the left part for a pattern and then replaces it with an abbreviation. We couldn't use the standard conversion table option because that would change the codes halfway the names too.

Make sure you enable the 'Enable conversions' checkbox in the naming conventions options if you want to use the script. If your script doesn't seem to work, you probably have a syntax error in your code. PowerDesigner won't give you an error when that happens.

.set_value(_name, %Name%, new)
.vbscript(%_name%)
   Dim Name
   Dim Code

   Name = UCase(ScriptInputArray(0))
   If Left(Name,10) = "REFERENTIE" Then 
     Code = "REF" & Right(Name,Len(Name)-10)
   ElseIf Left(Name,3) = "HUB" Then
     Code = "H" & Right(Name,Len(Name)-3)
   ElseIf Left(Name,4) = "LINK" Then
     Code = "L" & Right(Name,Len(Name)-4)
   ElseIf Left(Name,16) = "SAT HUB BUSINESS" Then
     Code = "SHB" & Right(Name,Len(Name)-16)
   ElseIf Left(Name,17) = "SAT LINK BUSINESS" Then
     Code = "SLB" & Right(Name,Len(Name)-17)
   ElseIf Left(Name,7) = "SAT HUB" Then
     Code = "SH" & Right(Name,Len(Name)-7)
   ElseIf Left(Name,8) = "SAT LINK" Then
     Code = "SL" & Right(Name,Len(Name)-8)
   Else
     Code = Name
   End If
   ScriptResult = Code
.endvbscript