Solar envelope and sunlight hours

Hello,
In my country there is a law about required sunlight hours for windows of residential buildings. That means that new buildings have to take that into account, making sure that windows of surrounfing buildings are not shaded for too long.

So - if the windows of surrounding buildings do not get at least X hours of sun on 21 March between 8.00-16.00 (as the effect of shading by designed building), the new building cannot be built.

I am trying to develop a definition that would decide what is the biggest possible building envelope on a given site that meets these requirements.

As far as I understand “Solar envelope” component allows to find a biggest volume that does not intersect given sun vectors.
What i need to find is a shape (biggest possible, in terms of volume) that allows for X number of minutes does not shade given windows.

Do you have any ideas how to encounter this problem? Thanks

Hey @Wujo
I have just uploaded script for this on hydra few days ago!
Take a look : http://hydrashare.github.io/hydra/viewer?owner=protactinium91&fork=hydra&id=Polish_Sunlight_Hours_Compliance&slide=0&scale=1&offset=0,0
Just add the part to modify the context cause I have internalised the geometry
Also this is for residential buildings so it’s 7-17 so just modify it to 8-16 for different use

This is a great script!
Can it be replicated in Dynamo?

Is there anyone who is familiar with both Dynamo and Grasshopper, and would know how to replicate this script in Dynamo?