Parametric Models



I tried to model a (very simple) building that adapts to its orientation. I managed to put in a few drivers and constraints, which allow to modify “the roof”. What would be a good method to measure the area of the floors with a python script? Because at the moment it’s a ugly hack. (see attached file for more explanations).
Also it would be great if it would be possible to “drive” the building also by the measured area. That’s how a designer could constraint a design to a given area size. Is there a possibility to do this with python or should I think about writing a patch to add a constraint? (there’s always a first time…).

Thanks for your input!


pyDrivers_rotHeight.blend (447 KB)

I tried to play around with this a bit with 2.62 but I could not do much without it crashing Blender. It is not obvious from the file layout what the control mechanisms are supposed to be so I could not tell what I was supposed to be grabbing and moving.

I created the file with 2.62 on a Mac.

Please select object “Cube” and rotate it around Z-axis. When you move it, nothing special happens.

That just crashes my Blender. shrug

Weird… I tested it on my Parallels/Windows installation. It doesn’t crash there. :eek:

Let’s put it a bit more clear: Can I measure a modified mesh? Let’s say I have a plane with an area of 2. When I put an array modifier on it that multiplies it times 5 (e.g. 5 “floors”), is there a script/method/addon that measures the mesh area as being 10? If not, how should I start writing such a script? Is it possible with python?

The dimensions of the object represent the size of the bounding box with modifiers applied.

import bpy

ob =["Cube"]
dimX = ob.dimensions[0]
dimZ = ob.dimensions[2]

You can do something like this

import bpy
from bmesh import from_mesh

#select the plane object before running 

context = bpy.context
scene = context.scene
plane = context.object

mesh = plane.to_mesh(scene, True, 'RENDER')  # apply modifiers with rendersettings

areas = [f.area for i,f in enumerate(mesh.faces) if i % 6 == 0]

print("AREAS : %s" % areas)
print("Faces:%d Total area %.2f" % (len(areas),sum(areas)))

What i’ve found with the above is that “floors” effected by the boolean mod change their face order so looking at the top of the cubes ie every 6th face starting from zero gives a small side face instead. To get around this maybe you need to throw each face into a floor based on z height and get the max of each sublist as your floor area.

Thank you for your help!
I could not test yet the bmesh thing, because on my mac I get the error “No module named bmesh” with the latest BMesh build I can find on graphicall . Maybe it will work on a windows machine.
Where did you find the documentation on the to_mesh method? On the blender documentation sitethere seems to be no “RENDER” option documented. Does this option make Blender apply the modifier only for rendering, but leave the modifiers untouched?

Oops delete the bmesh import… not being used. Changed my mind. It was easier to do it the old way.

On the modifiers you have an option for preview and render setting values. Subsurf for instance. ‘RENDER’ and ‘PREVIEW’ tell which ones to use when modifying the mesh with to_mesh … object.to_mesh that is … this one

Would BMesh allow to measure the area without applying the modifiers? Because with this method I need to duplicate my mesh first, right? Since I don’t want to loose my modifiers.

No it doesn’t duplicate your mesh, it creates a new modified mesh.

Delete the from bmesh import from_mesh line and run the script with your plane selected. It spits out the areas of each floor until those that are modified by the boolean mod. See prev post for suggestion there.

Very nice! Thank you! :slight_smile: