Probably you do not want to define Shape Scripts directly in the stereotypes. More likely you are going to deploy them along with an MDG Technology file. I can not explain how to create MDGs in this book as it would lead much too far. So you either know already how to do that, or you need some outside help.
Another advanced usage is when you simply need more than Shape Script can deliver in respect to querying model contexts. That is where add-ins come into play.
7.1 Shape Script in MDG
Any Shape Script for a profile element must be defined by adding a property named _image and clicking the ellipsis button next to the Initial Value field. This will open the Shape Script editor.
7.2 Add-in
Since Shape Script is so limited in performing algorithms there is an escape through the use of external code hosted in an add-in. If you want to use this feature you need to know how to write add-ins at all. I can not explain how to do that so you need to get outside help for that. But if you know it then here is what you need to take advantage of this escape.
Basically you can retrieve a string value from your add-in which you can evaluate by HasProperty or by directly printing it using a properties. The format is
where <addin_name> is the name you had chosen for your add-in (the identifier) and <function_name> is the name of the function inside your add-in. An arbitrary list of comma separated parameters can be supplied which are passed by value to the called add-in procedure where the repository, the element-GUID and the additional parameters14 are passed. Since Shape Script knows neither variables nor string substitution you need to write those by hand in any case. So a single parameter will usually suffice – or you just have named functions. The called function must return a string as result.
E.g.
1 print("#addin:myAddIn,pFunc1#")
will print the result returned by the function pFunc1 inside your add-in framework.
Similarly
1 hasproperty('addin:myAddIn,pFunc2', '1')
will evaluate to true if your function pFunc2 returns the string value 1.