0

我对编程很陌生,这是我在这个网站上的第一个问题。我已经学习 Pyhon 三个多星期了。

对于一个项目,我使用了一个名为 IfcOpenShell 的模块,它可以轻松检索 ifc 文件中指定的数据。Ifc 文件是一种基于表达的语言,用于描述建筑数据。

现在我想从 ifc 文件中检索适合照明分析的所有相关材料数据,并将它们转换为 Radiance 格式。Radiance 是开源照明分析软件

到目前为止,我已经编写了这个脚本:

import ifcopenshell

ifc_file = ifcopenshell.open('Example_A.ifc')

materials = ifc_file.by_type('IfcMaterial')

print 'There are ' + str(len(materials)) + ' different types of  materials in the file:' + '\n'

for x in range(0):
    materials = ifc_file.by_type('IfcMaterial')[x] 
    colour = ifc_file.by_type('IfcColourRgb')[x]
    styles = ifc_file.by_type('IfcStyledItem')[x]
    surfacestyles = ifc_file.by_type('IfcSurfaceStyleRendering')[x]

#DECLARING THE VARIABLES FOR RADIANCE DEFINTION
rad_material = materials.Name
rad_red = colour.Red
rad_green = colour.Green
rad_blue = colour.Blue
rad_specular = surfacestyles.SpecularColour
rad_roughness = 0.1 #<- Roughness is not defined in IFC, the value of 0.1 is  merely put there as an example


print 'RETRIEVES DATA FROM IFC FILE PRINTS THEM ACCORDING TO A RADIANCE READABLE DEFINITION'
print ''

print '#material name: ' + rad_material
print '#material type: ' + 'No definition found in the specified ifc file'
print 'void ' + ' plastic ' + rad_material
print '0'
print '0'
print rad_red , rad_green, rad_blue,rad_specular[0], rad_roughness

我发现 ifc 文件中指定了 100 种不同的材料。当我运行这段代码时,它会输出:

There are 100 different types of  materials in the file:

RETRIEVES DATA FROM IFC FILE PRINTS THEM ACCORDING TO A RADIANCE READABLE DEFINITION

#material name: SH_resin Floor
#material type: No definition found in the specified ifc file
void  plastic SH_resin Floor
0
0
1.0 1.0 1.0 0.5 0.1

然而,当我改变时,这正是我想做的:

for x in range(0):

for x in range(0,100)

它只输出范围的最后一个材料:

There are 100 different types of  materials in the file:

RETRIEVES DATA FROM IFC FILE PRINTS THEM ACCORDING TO A RADIANCE READABLE DEFINITION

#material name: Juice
#material type: No definition found in the specified ifc file
void  plastic Juice
0
0
0.956862745098 0.956862745098 0.956862745098 0.5 0.1

我不明白我在哪里犯了错误,或者我是否正在使用正确的功能来满足我的需求。我的意图是输出所有 100 种不同的材料定义

4

1 回答 1

0

缩进显示了哪些行是 for 循环的一部分。如果您希望打印语句发生 100 次,您也必须缩进它们。

import ifcopenshell

ifc_file = ifcopenshell.open('Example_A.ifc')

materials = ifc_file.by_type('IfcMaterial')

print 'There are ' + str(len(materials)) + ' different types of  materials in the file:' + '\n'

for x in range(0):
    materials = ifc_file.by_type('IfcMaterial')[x] 
    colour = ifc_file.by_type('IfcColourRgb')[x]
    styles = ifc_file.by_type('IfcStyledItem')[x]
    surfacestyles = ifc_file.by_type('IfcSurfaceStyleRendering')[x]

    #DECLARING THE VARIABLES FOR RADIANCE DEFINTION
    rad_material = materials.Name
    rad_red = colour.Red
    rad_green = colour.Green
    rad_blue = colour.Blue
    rad_specular = surfacestyles.SpecularColour
    rad_roughness = 0.1 #<- Roughness is not defined in IFC, the value of 0.1 is  merely put there as an example


    print 'RETRIEVES DATA FROM IFC FILE PRINTS THEM ACCORDING TO A RADIANCE READABLE DEFINITION'
    print ''

    print '#material name: ' + rad_material
    print '#material type: ' + 'No definition found in the specified ifc file'
    print 'void ' + ' plastic ' + rad_material
    print '0'
    print '0'
    print rad_red , rad_green, rad_blue,rad_specular[0], rad_roughness
于 2015-01-22T21:45:17.977 回答