For 循环覆盖一个范围(Python 2.7 + Ifc)



我对编程很陌生,这是我在这个网站上的第一个问题之一。我已经学习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种不同的材料定义

缩进显示哪些行是 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

相关内容

  • 没有找到相关文章

最新更新