@@ -25,24 +25,33 @@ module IfcJson
25
25
class IfcJsonExporter
26
26
attr_accessor :root_objects
27
27
def initialize ( entities )
28
+ @id_objects = [ ]
29
+ @ifc_objects = Array . new
28
30
@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
+
29
48
@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 ,
46
55
"data" => [ ]
47
56
}
48
57
export_path = get_export_path ( )
@@ -52,6 +61,7 @@ def initialize( entities )
52
61
@root_objects [ "data" ] . concat ( collect_objects ( entities , Geom ::Transformation . new ( ) ) [ 0 ] )
53
62
end
54
63
64
+ @root_objects [ "data" ] . concat ( @ifc_objects )
55
65
@root_objects [ "data" ] . concat ( @geometry )
56
66
57
67
to_file ( export_path )
@@ -68,30 +78,30 @@ def collect_objects(entities, parent_transformation, parent_guid=nil)
68
78
object_hash . merge! get_properties ( entity )
69
79
70
80
# create unique guid
71
- guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( object_hash [ "GlobalId " ] )
81
+ guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( object_hash [ "globalId " ] )
72
82
if parent_guid
73
83
guid . set_parent_guid ( parent_guid )
74
84
end
75
- object_hash [ "GlobalId " ] = guid . to_json ( )
85
+ object_hash [ "globalId " ] = guid . to_json ( )
76
86
77
87
# add volume if object is manifold
78
88
if entity . volume > 0
79
- object_hash [ "Volume " ] = entity . volume
89
+ object_hash [ "volume " ] = entity . volume
80
90
end
81
91
82
92
isDecomposedBy , child_faces = collect_objects ( entity . definition . entities , transformation , guid . to_s )
83
93
84
94
unless isDecomposedBy . empty?
85
- object_hash [ "IsDecomposedBy " ] = isDecomposedBy
95
+ object_hash [ "isDecomposedBy " ] = isDecomposedBy
86
96
end
87
97
88
98
# only add representation if there are any faces
89
99
if child_faces . length > 0
90
100
obj = OBJ . new ( child_faces , parent_transformation )
91
101
representation_guid = BimTools ::IfcManager ::IfcGloballyUniqueId . new ( ) . to_json
92
- object_hash [ "Representations " ] = [
102
+ object_hash [ "representations " ] = [
93
103
{
94
- "Class " : "ShapeRepresentation" ,
104
+ "type " : "ShapeRepresentation" ,
95
105
"ref" : representation_guid
96
106
}
97
107
]
@@ -109,14 +119,23 @@ def collect_objects(entities, parent_transformation, parent_guid=nil)
109
119
110
120
# add geometry as seperate objects at the end of the file
111
121
@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 ]
117
127
}
118
128
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
120
139
elsif entity . is_a? ( Sketchup ::Face )
121
140
faces << entity
122
141
end
@@ -129,7 +148,16 @@ def get_properties(entity)
129
148
definition = entity . definition
130
149
ifc_type = definition . get_attribute "AppliedSchemaTypes" , "IFC 2x3"
131
150
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
133
161
if definition . attribute_dictionaries [ 'IFC 2x3' ]
134
162
if props_ifc = definition . attribute_dictionaries [ 'IFC 2x3' ] . attribute_dictionaries
135
163
props_ifc . each do |prop_dict |
@@ -141,7 +169,8 @@ def get_properties(entity)
141
169
if val_dict [ "value" ] && !val_dict [ "is_hidden" ]
142
170
value = val_dict [ "value" ]
143
171
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" ]
145
174
end
146
175
end
147
176
end
0 commit comments