Generating a virtual city

Hey guys!

Here’s a small experiment with Blender Python… a script to generate a city street map.

Pic of the output:

Blend file with the script:
EDIT: a blooper on my part - in the script put “#” in the beginning of the line with “import Substrate”…

My ultimate goal is to try and generate a crowded victorian London slum. In the process this should blossom into a nice content-generation tool, useful for things other than virtual cities…

Tell me what ya think!

By the way, search Google for “CityEngine” - some folks have already done this, although I don’t like some parts of their implementation.

Error no module named substrate?


Hey, thats’s a great script! Nice work!

btw. I also got the same error… now I’m a noob concerning python, but I just put an # in front of the “import Substrate” line and it worked… :stuck_out_tongue:

Keep it going MyIS, I love this and it’ll come in handy for sure!

Put an # in fornt of the subtrate line, and got a console error for random ‘module’. Pretty new to me all of this - phyton especially. Very curious about city building script, and hope to get get working soon! Good luck to us all :wink:

couldn’t you have come up with this 1month ago…could have needed it! haha…it sounds pretty good, will have a look at it for sure!

could you post the script without it being in a blend file. blender crashes when i try to open it… using 2.37a.

Edit: ok redownloaded and it worked. looks good. i’ll test run it and try to give feed back, definately interesting and useful

Thanks for the kind replies! Sorry again about that silly “Substrate” mistake… At first I tried to build a generic L-system under the whole thing, but removed it eventually - somehow that leftover “import” never came up as an error…

At the moment, though, I am trying to rewrite the whole thing as an extended L-system again; this time using Prolog, though. The goal is to make it easier to integrate separate stages of workflow (e.g. street generator, house lot generator, architectural elements). Also, some algorithms can be reused in different stages (e.g. splitting up a block polygon into smaller lots, etc). Of course, Python has hooks to Prolog, so it should be easy to integrate this back into Blender.

I wish the current script showed something more than just simple lines… I’m sure more people would become interested then ;).

Thanks MyIs! Was detrmined to see the script in action, and now finally have. Recently installed Phython 24 and changed the path = don’t work in Blender. Now 23 re-instated & all back up and running. Hope you keep working at it :slight_smile: Thanks…

your script is very nice indeed, although i find it hard to under stand how to control the final output. lets say i want just one main street with two smaller streets crossing it, then all the little streets between. is there a method to control that or is it a random system?

put basically more control would be great.

Nope, no control over individual roads, except for a few global variables like road widths and such. I definitely agree, though, that there should be a way to tweak the big roads before the rest of the city is done, or maybe clear out and manually recreate parts of the city…

Before that’s possible, I would have to finish the rest of the process - house lots and buildings - to at least have a proper beta version. Until then, it’s pretty much a useless toy …although I admit I already spent a lot of time just zooming in on the street map and tracing out routes, heh.

Until then, it’s pretty much a useless toy
:expressionless: i’d hardly call it useless.

i didn’t realise you planned on including automatic building placement. i thought it was just to generate a good city layout.

if the user could create his/her own template building set for the script to use (like the old pre-beast script) it would be a fantastic tool.

sorry if i’m asking too much too soon or whatever.

keep up the good work

Good coding, I don’t exactly know what every button does, but it’s much fun seeing the city grow. Very nice script!

This is waaay cool. I love the random sort of streets this lays out, much more character than we are used to here in the states with out city blocks :stuck_out_tongue: (Reminds me of the thief game too) One question: how do I get it to render? I see the geometry, but it dosn’t seem to have genarated valid faces for rendering, is there a way to have it generate quads so it can render or am I just missing something super simple here?


Hi Trevj,

To fill the mesh, use SHIFT+F. If you want the buildings as well, first duplicate the mesh and delete the outer ring, press L on one of the vertices. Then SHIFT+F again et voila.

Yeah, what wavk said.

Ultimately, to have really useful results, one should probably tweak the output code to produce what they want. There are many possible output formats, so I couldn’t predict which one is the right one.

That said, I actually modified the script later to be used with another tool to generate detailed mesh buildings: