@@ -25,24 +25,33 @@ module IfcJson
2525 class IfcJsonExporter
2626 attr_accessor :root_objects
2727 def initialize ( entities )
28+ @id_objects = [ ]
29+ @ifc_objects = Array . new
2830 @geometry = Array . new
31+
32+ # get timestamp
33+ time = Time . new
34+ timestamp = time . strftime ( "%Y-%m-%dT%H:%M:%S" )
35+
36+ # get originating_system
37+ originating_system = "SketchUp"
38+ if Sketchup . is_pro?
39+ originating_system = originating_system << " Pro"
40+ end
41+ number = Sketchup . version_number /100000000 . floor
42+ originating_system = originating_system << " 20" << number . to_s
43+ originating_system = originating_system << " (" << Sketchup . version << ")"
44+
45+ # get preprosessor versions
46+ preprocessor_version = "IFC-manager for SketchUp (#{ VERSION } )"
47+
2948 @root_objects = {
30- "header" => {
31- "file_description" => {
32- "description" => "ViewDefinition [CoordinationView]" ,
33- "implementation_level" => "2;1"
34- } ,
35- "file_name" => {
36- "name" => "7m900_tue_hello_wall_with_door.json" ,
37- "time_stamp" => "2020-02-22T11:10:04" ,
38- "author" => "" ,
39- "organization" => "" ,
40- "preprocessor_version" => "IFC-manager for SketchUp (ifcjson-3.1.0)" ,
41- "originating_system" => "SketchUp Pro 2020 (20.0.373)" ,
42- "authorization" => ""
43- } ,
44- "file_schema" => "IFC2X3"
45- } ,
49+ "type" => "ifcjson" ,
50+ "schema" => "IFC.JSON5a" ,
51+ "description" => "ViewDefinition [CoordinationView]" ,
52+ "timeStamp" => timestamp ,
53+ "preprocessorVersion" => preprocessor_version ,
54+ "originatingSystem" => originating_system ,
4655 "data" => [ ]
4756 }
4857 export_path = get_export_path ( )
@@ -52,6 +61,7 @@ def initialize( entities )
5261 @root_objects [ "data" ] . concat ( collect_objects ( entities , Geom ::Transformation . new ( ) ) [ 0 ] )
5362 end
5463
64+ @root_objects [ "data" ] . concat ( @ifc_objects )
5565 @root_objects [ "data" ] . concat ( @geometry )
5666
5767 to_file ( export_path )
@@ -68,30 +78,30 @@ def collect_objects(entities, parent_transformation, parent_guid=nil)
6878 object_hash . merge! get_properties ( entity )
6979
7080 # create unique guid
71- guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( object_hash [ "GlobalId " ] )
81+ guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( object_hash [ "globalId " ] )
7282 if parent_guid
7383 guid . set_parent_guid ( parent_guid )
7484 end
75- object_hash [ "GlobalId " ] = guid . to_json ( )
85+ object_hash [ "globalId " ] = guid . to_json ( )
7686
7787 # add volume if object is manifold
7888 if entity . volume > 0
79- object_hash [ "Volume " ] = entity . volume
89+ object_hash [ "volume " ] = entity . volume
8090 end
8191
8292 isDecomposedBy , child_faces = collect_objects ( entity . definition . entities , transformation , guid . to_s )
8393
8494 unless isDecomposedBy . empty?
85- object_hash [ "IsDecomposedBy " ] = isDecomposedBy
95+ object_hash [ "isDecomposedBy " ] = isDecomposedBy
8696 end
8797
8898 # only add representation if there are any faces
8999 if child_faces . length > 0
90100 obj = OBJ . new ( child_faces , parent_transformation )
91101 representation_guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( ) . to_json
92- object_hash [ "Representations " ] = [
102+ object_hash [ "representations " ] = [
93103 {
94- "Class " : "ShapeRepresentation" ,
104+ "type " : "ShapeRepresentation" ,
95105 "ref" : representation_guid
96106 }
97107 ]
@@ -109,14 +119,23 @@ def collect_objects(entities, parent_transformation, parent_guid=nil)
109119
110120 # add geometry as seperate objects at the end of the file
111121 @geometry << {
112- "Class " => "ShapeRepresentation" ,
113- "GlobalId " => representation_guid ,
114- "RepresentationIdentifier " => "Body" ,
115- "RepresentationType " => "OBJ" ,
116- "Items " => [ obj . to_s ]
122+ "type " => "ShapeRepresentation" ,
123+ "globalId " => representation_guid ,
124+ "representationIdentifier " => "Body" ,
125+ "representationType " => "OBJ" ,
126+ "items " => [ obj . to_s ]
117127 }
118128 end
119- child_objects << object_hash
129+ if object_hash [ "type" ]
130+ if !@id_objects . include? object_hash [ "globalId" ]
131+ @ifc_objects << object_hash
132+ end
133+ object_hash = {
134+ "type" => object_hash [ "type" ] ,
135+ "globalId" => object_hash [ "globalId" ]
136+ }
137+ child_objects << object_hash
138+ end
120139 elsif entity . is_a? ( Sketchup ::Face )
121140 faces << entity
122141 end
@@ -129,7 +148,16 @@ def get_properties(entity)
129148 definition = entity . definition
130149 ifc_type = definition . get_attribute "AppliedSchemaTypes" , "IFC 2x3"
131150 if ifc_type
132- properties [ "Class" ] = ifc_type [ 3 ..-1 ]
151+
152+ # hack to remove IfcWallStandardCase
153+ if ifc_type == "IfcWallStandardCase"
154+ ifc_type = "IfcWall"
155+ end
156+
157+ # Strip "Ifc" prefix
158+ properties [ "type" ] = ifc_type [ 3 ..-1 ]
159+
160+ # Collect IFC attributes from Sketchup object
133161 if definition . attribute_dictionaries [ 'IFC 2x3' ]
134162 if props_ifc = definition . attribute_dictionaries [ 'IFC 2x3' ] . attribute_dictionaries
135163 props_ifc . each do |prop_dict |
@@ -141,7 +169,8 @@ def get_properties(entity)
141169 if val_dict [ "value" ] && !val_dict [ "is_hidden" ]
142170 value = val_dict [ "value" ]
143171 if value != ""
144- properties [ prop_dict . name ] = val_dict [ "value" ]
172+ property_name = prop_dict . name [ 0 ] . downcase + prop_dict . name [ 1 ..-1 ]
173+ properties [ property_name ] = val_dict [ "value" ]
145174 end
146175 end
147176 end
0 commit comments