For 在一个范围内循环 (Python 2.7 + Ifc)
For loop over a range (Python 2.7 + Ifc)
我对编程还很陌生,这是我在这个网站上的第一个问题。我已经学习 Pyhon 三个多星期了。
对于一个项目,我使用了一个名为 IfcOpenShell 的模块,它可以轻松检索 ifc 文件中指定的数据。 Ifc 文件是一种基于表达语言的建筑数据描述语言。
现在我想从 ifc 文件中检索适合照明分析的所有相关 material 数据,并将它们转换为 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 个不同的 material。当我 运行 这段代码时,它输出:
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)
它只输出范围的最后一个 material:
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 个不同的 material 定义
缩进显示哪些行是 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
我对编程还很陌生,这是我在这个网站上的第一个问题。我已经学习 Pyhon 三个多星期了。
对于一个项目,我使用了一个名为 IfcOpenShell 的模块,它可以轻松检索 ifc 文件中指定的数据。 Ifc 文件是一种基于表达语言的建筑数据描述语言。
现在我想从 ifc 文件中检索适合照明分析的所有相关 material 数据,并将它们转换为 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 个不同的 material。当我 运行 这段代码时,它输出:
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)
它只输出范围的最后一个 material:
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 个不同的 material 定义
缩进显示哪些行是 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