0

私はプログラミングを始めたばかりで、これはこのサイトでの最初の質問の 1 つです。私は 3 週間以上 Pyhon を学んでいます。

プロジェクトでは、ifc ファイルで指定されたデータを簡単に取得できる IfcOpenShell というモジュールを使用します。Ifc ファイルは、建物データを記述する Express ベースの言語です。

ここで、照明分析に適したすべての関連マテリアル データを ifc ファイルから取得し、それらをラディアンス フォーマットに変換したいと考えています。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 ループの一部である行を示します。print ステートメントを 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 に答える