To get you into the right frame of mind, it may be useful to read the AD issue, called 'Programming Cultures'. It is accessible here:
Tuesday, January 12, 2010
Monday, January 11, 2010
Houdini Modelling 101 v2
I have created an introduction to modelling with Houdini for beginners. This is version 2, and I will update it every now and then. There will also be an introductio to Houdini Scripting coming soon.
This intro is to be used in conjunction with the videos available on line - not as a replacement. The intro focuses mainly on the concepts you need to get started with Houdini. It does not teach you in detail where to click and how to use specific tools.
This intro is to be used in conjunction with the videos available on line - not as a replacement. The intro focuses mainly on the concepts you need to get started with Houdini. It does not teach you in detail where to click and how to use specific tools.
Friday, January 8, 2010
Python and EnergyPlus
Here is the script from todays session. This script generates the IDF input file for EnergyPlus. Note that this script requires a base file, i.e. rather than generating the whole IDF file, the script only generates the surfaces and appends these to the base file. To run this script, you will have to make the base file - just open 1ZoneEvapCooler.idf, save it as base.idf, and delete all the BuildingSurface objects in this file.
#======================================================================
# Imports
#======================================================================
#======================================================================
# Functions
#======================================================================
#Function to write a ep surface
def write_ep_surface(
idf_file, name, srf_type,
const,zone,boundry,boundry_obj,
sun_exp,wind_exp,view_fact,
points):
idf_file.write("! Building Surface\n")
idf_file.write("BuildingSurface:Detailed,\n")
idf_file.write(" "+name+",\n")
idf_file.write(" "+srf_type+",\n")
idf_file.write(" "+const+",\n")
idf_file.write(" "+zone+",\n")
idf_file.write(" "+boundry+",\n")
idf_file.write(" "+boundry_obj+",\n")
idf_file.write(" "+sun_exp+",\n")
idf_file.write(" "+wind_exp+",\n")
idf_file.write(" "+view_fact+",\n")
idf_file.write(" "+str(len(points))+",\n")
for counter in range(len(points)):
point = points[counter]
text_point = str(point[0])+","+str(point[1])+","+str(point[2])
if counter < len(points)-1:
idf_file.write(" "+text_point+",\n" )
else:
idf_file.write(" "+text_point+";\n\n" )
#======================================================================
# Main Script
#======================================================================
# Create a simple box
box = (
(0,0,0),(15,0,0),(15,15,0),(0,15,0),
(0,0,10),(15,0,10),(15,15,10),(0,15,10),
)
floor_points = (box[3], box[2], box[1], box[0])
wall1_points = (box[1], box[5], box[4], box[0])
wall2_points = (box[2], box[6], box[5], box[1])
wall3_points = (box[3], box[7], box[6], box[2])
wall4_points = (box[0], box[4], box[7], box[3])
roof_points = (box[4], box[5], box[6], box[7])
#Create the idf file
idf_file_1 = open("D:/box.idf", "w")
base_file = open("D:/base.idf", "r")
base_stuff = base_file.read()
idf_file_1.write(base_stuff)
idf_file_1.write("!- ========================= \n\n\n")
# Add the surfaces
write_ep_surface(idf_file_1,
"zn001:floor", "Floor", "FLOOR", "Main Zone", "Surface",
"zn001:floor", "NoSun", "NoWind", "1.00", floor_points)
write_ep_surface(idf_file_1,
"zn001:wall1", "Wall", "R13WALL", "Main Zone", "Outdoors",
"", "SunExposed", "WindExposed", "0.50", wall1_points)
write_ep_surface(idf_file_1,
"zn001:wall2", "Wall", "R13WALL", "Main Zone", "Outdoors",
"", "SunExposed", "WindExposed", "0.50", wall2_points)
write_ep_surface(idf_file_1,
"zn001:wall3", "Wall", "R13WALL", "Main Zone", "Outdoors",
"", "SunExposed", "WindExposed", "0.50", wall3_points)
write_ep_surface(idf_file_1,
"zn001:wall4", "Wall", "R13WALL", "Main Zone", "Outdoors",
"", "SunExposed", "WindExposed", "0.50", wall4_points)
write_ep_surface(idf_file_1,
"zn001:roof", "Roof", "ROOF31", "Main Zone", "Outdoors",
"", "SunExposed", "WindExposed", "0.00", roof_points)
#Close the file
idf_file_1.close()
base_file.close()
Two ways of looping
Here are two ways of looping...
Lets say you have a list like this:
Lets say you have a list like this:
x = ("a", "b", "c", "d")
One way to loop through the list is like this:for item in x:
print "item = ", item
Another way of looping is like this:for counter in range(len(x)):
print "item = ", x[counter]
Thursday, January 7, 2010
Python and Radiance
Here is the script from todays session:
#======================================================================
# Imports
#======================================================================
import os
import random
#======================================================================
# Functions
#======================================================================
#Function to write a light
def write_material_light(rad_file, name, rgb_e):
rad_file.write("# Light material\n")
rad_file.write("void light " + name + "\n")
rad_file.write("0\n")
rad_file.write("0\n")
rad_file.write("3 " +
str(rgb_e[0])+ " " +
str(rgb_e[1]) + " " +
str(rgb_e[2]) + " " + "\n\n")
def write_material_plastic(rad_file, name, rgb, spec, rough):
rad_file.write("# Plastic material\n")
rad_file.write("void plastic " + name + "\n")
rad_file.write("0\n")
rad_file.write("0\n")
rad_file.write("5 " +
str(rgb[0])+ " " +
str(rgb[1]) + " " +
str(rgb[2]) + " " +
str(spec) + " " +
str(rough) + "\n\n")
def write_surf_sphere(rad_file, name, material, position, radius):
rad_file.write("# Sphere \n")
rad_file.write(material + " sphere " + name + "\n")
rad_file.write("0\n")
rad_file.write("0\n")
rad_file.write("4 " +
str(position[0])+ " " +
str(position[1]) + " " +
str(position[2]) + " " +
str(radius) + "\n\n")
#======================================================================
# Main script
#======================================================================
#Create the scene file
rad_file_1 = open("D:/scene.rad", "w")
write_material_light( rad_file_1, "mat_light_1", (100, 100, 100))
write_material_plastic( rad_file_1, "mat_red", (0.7, 0.05, 0.05), 0.05, 0.05)
for i in range(2):
position = (random.random() * 5, random.random() * 5, random.random() * 5)
radius = random.random()
write_surf_sphere(rad_file_1, "light_"+str(i), "mat_light_1", position, radius)
for i in range(20):
position = (random.random() * 5, random.random() * 5, random.random() * 5)
radius = random.random()
write_surf_sphere(rad_file_1, "ball_"+str(i), "mat_red", position, radius)
rad_file_1.close()
#Run radiance using oconv and rpict
#os.system("C:/Radiance/bin/oconv D:/scene.rad > D:/scene.oct")
#os.system("C:/Radiance/bin/rpict -vp 10 10 10 -vd -10 -10 -10 -av .5 .5 .5 D:/scene.oct > D:/scene.pic")
#Run radiance using rad
rif_file_1 = open("D:/scene.rif", "w")
rif_file_1.write("ZONE = I 0 5 0 5 0 5\n")
rif_file_1.write("scene = D:/scene.rad\n")
rif_file_1.close()
os.system("C:/Radiance/bin/rad D:/scene.rif")
Wednesday, January 6, 2010
Python functions
Here is the example of creating a Python function from todays workshop:
rec1 = [20,2]
rec2 = [24,9]
rec3 = [6,2]
def area(rec):
area = rec[0] * rec[1]
print(area)
return area
area1 = area(rec1)
area2 = area(rec2)
area3 = area(rec3)
print("===")
print(area1)
print(area2)
print(area3)
Tuesday, January 5, 2010
Learning Python
Python is the scripting language we will be using. You can download Python for free and install it on your own computer. We will be using version 2.5.4
There is lots of online help for Python.There is a list of the most popular tutorials for beginners, and here are a few good ones:
The standard Python docs are also useful. Although we are using version 2.5, we will use the documentation for 2.6. The 2.6 docs are formatted in a better way, so it makes our life easier:
There is lots of online help for Python.There is a list of the most popular tutorials for beginners, and here are a few good ones:
The standard Python docs are also useful. Although we are using version 2.5, we will use the documentation for 2.6. The 2.6 docs are formatted in a better way, so it makes our life easier:
Subscribe to:
Posts (Atom)