首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >范围循环(Python2.7+ Ifc)

范围循环(Python2.7+ Ifc)
EN

Stack Overflow用户
提问于 2015-01-22 21:27:48
回答 1查看 398关注 0票数 0

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

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

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

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

代码语言:javascript
复制
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种不同的材料。当我运行这段代码时,它会输出:

代码语言:javascript
复制
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

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

代码语言:javascript
复制
for x in range(0):

代码语言:javascript
复制
for x in range(0,100)

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

代码语言:javascript
复制
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个不同的材料定义

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-01-22 21:45:17

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

代码语言:javascript
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28099021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档