-
Notifications
You must be signed in to change notification settings - Fork 2
/
code_to_debug_import_rebar.py
433 lines (349 loc) · 15.3 KB
/
code_to_debug_import_rebar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
# ***************************************************************************
# * Copyright (c) 2020 Bernd Hahnebach <[email protected]> *
# * *
# * This program is free software; you can redistribute it and/or modify *
# * it under the terms of the GNU Lesser General Public License (LGPL) *
# * as published by the Free Software Foundation; either version 2 of *
# * the License, or (at your option) any later version. *
# * for detail see the LICENCE text file. *
# * *
# * This program is distributed in the hope that it will be useful, *
# * but WITHOUT ANY WARRANTY; without even the implied warranty of *
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
# * GNU Library General Public License for more details. *
# * *
# * You should have received a copy of the GNU Library General Public *
# * License along with this program; if not, write to the Free Software *
# * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
# * USA *
# * *
# ***************************************************************************
# code for debugging and implementation of rebar ifc importer
# code to copy for rebar import
# may be there are some HACK s
# there have been takes place renamming and moving methods and class
# ************************************************************************************************
# ifc import into rebar2 objects *****************************************************************
# ************************************************************************************************
# ************************************************************************************************
# use new rebar2 module
import ifcopenshell, rebar2, Part, Draft, os
import lattice2Placement, lattice2JoinArrays, lattice2Executer
from FreeCAD import Vector as vec
from ifcopenshell.geom import settings
prefs = settings()
prefs.set(prefs.USE_BREP_DATA, True)
prefs.set(prefs.USE_WORLD_COORDS, True)
prefs.set(prefs.INCLUDE_CURVES, True)
prefs.set(prefs.EXCLUDE_SOLIDS_AND_SURFACES, True)
path_to_rebar2 = rebar2.__file__.rstrip(os.path.basename(rebar2.__file__))
ifcfile = path_to_rebar2 + "example_01_two_stirrups.ifc" # imports :-)
# ifcfile = path_to_rebar2 + "example_02_channel_foundation.ifc" # imports :-)
# ifcfile = path_to_rebar2 + "example_03_crane_foundation.ifc" # does import crap, was exported with old Allplan exporter
# ifcfile = path_to_rebar2 + "example_04_vat.ifc" # imports :-)
f = ifcopenshell.open(ifcfile)
for rebar in f.by_type("IfcReinforcingBar"):
ifc_shape_representation = rebar.Representation.Representations[0]
ifc_swept_disk_solid = ifc_shape_representation.Items[0].MappingSource.MappedRepresentation.Items[0]
radius = ifc_swept_disk_solid.Radius
entity_polyline = ifc_swept_disk_solid.Directrix
# sweep path
cr = ifcopenshell.geom.create_shape(prefs, entity_polyline)
brep = cr.brep_data
sweep_path = Part.Shape()
sweep_path.importBrepFromString(brep)
sweep_path.scale(1000.0) # IfcOpenShell always outputs in meters
wire = Draft.makeWire(sweep_path.Wires[0])
# rebar shape
markno = rebar.id() # use ifc entity as mark number
rebar_shape = rebar2.makeRebarShape(wire, diameter=2*radius, mark=markno, name="RebarShape_No_"+str(markno))
# rebar distribution
# TODO mght be there is only the first distribution of many distributions of the MarkNumber rebar
# lattice2 placements
custom_pls = []
for ifc_mapped_item in ifc_shape_representation.Items:
ifc_cartesian_point = ifc_mapped_item.MappingTarget.LocalOrigin
coord = ifc_cartesian_point.Coordinates
custom_pl = lattice2Placement.makeLatticePlacement(name=str(ifc_cartesian_point.id()))
custom_pl.PlacementChoice = "Custom"
custom_pl.MarkerSize = 25
lattice2Executer.executeFeature(custom_pl)
custom_pl.Placement = FreeCAD.Placement(vec(coord[0], coord[1], coord[2]), FreeCAD.Rotation(vec(0,0,1),0), vec(0,0,0))
custom_pls.append(custom_pl)
# lattice2 array placement
cpa = lattice2JoinArrays.makeJoinArrays(name="CustomPlacementArray")
cpa.Links = custom_pls
cpa.MarkerSize = 25
for child in cpa.ViewObject.Proxy.claimChildren():
child.ViewObject.hide()
lattice2Executer.executeFeature(cpa)
ifc_cartesian_point_cpa = rebar.ObjectPlacement.RelativePlacement.Location
coord_cpa = ifc_cartesian_point_cpa.Coordinates
cpa_pl = FreeCAD.Placement(vec(coord_cpa[0], coord_cpa[1], coord_cpa[2]), FreeCAD.Rotation(vec(0,0,1),0), vec(0,0,0))
cpa.Placement = cpa_pl
# move rebar shape to the first bar of distribution
rebar_shape.Placement = cpa_pl
# rebar2 distribution
rebdistribution6 = rebar2.makeRebarDistributionLattice(rebar_shape, cpa, name="Distribution_No"+str(markno))
FreeCAD.ActiveDocument.recompute()
# ************************************************************************************************
# ifc import other debug code ********************************************************************
# ************************************************************************************************
# ************************************************************************************************
# TODO better path implementation
import os, rebar2
path_to_rebar2 = rebar2.__file__.rstrip(os.path.basename(rebar2.__file__))
print(path_to_rebar2)
# ************************************************************************************************
# length scale unit
import os, rebar2, ifcopenshell
path_to_rebar2 = rebar2.__file__.rstrip(os.path.basename(rebar2.__file__))
ifcfile = path_to_rebar2 + "example_01_two_stirrups.ifc" # imports :-)
# ifcfile = path_to_rebar2 + "example_03_crane_foundation.ifc"
f = ifcopenshell.open(ifcfile)
f.by_type('IfcProject')
prj_units = f.by_type('IfcProject')[0].UnitsInContext.Units
scale_length = 1.0
found_length_unit = False
for u in prj_units:
if u.UnitType == "LENGTHUNIT":
if found_length_unit is False:
found_length_unit = True
# print(u.Prefix)
# print(u.Name)
if u.Prefix == "MILLI" and u.Name == "METRE":
scale_length = 1.0
elif u.Prefix is None and u.Name == "METRE":
scale_length = 0.001
else:
print("Not known length unit found, set attribute length scale to 1.0")
print(u)
scale_length = 1.0
else:
print("Two LENGTHUNIT defined, this is not allowed in IFC-Standard.")
print(scale_length)
# ************************************************************************************************
import ifcopenshell, os, Part
# from importIFC
from ifcopenshell import geom
settings = ifcopenshell.geom.settings()
settings.set(settings.USE_BREP_DATA,True)
settings.set(settings.SEW_SHELLS,True)
settings.set(settings.USE_WORLD_COORDS,True)
from platform import system
if system() == "Windows":
ifcfile = 'C:/Users/BHA/Desktop/example_01_two_stirrups.ifc'
elif system() == "Linux":
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
# ifcfile = '/home/hugo/Desktop/example_01_two_stirrups.ifc'
else:
print("not known OS")
f = ifcopenshell.open(ifcfile)
f.by_type('IfcProject')
f.by_type('IfcPerson')
f.by_type('IfcReinforcingBar')
p = f.by_id(275)
r = p.Representation
print(p, '\n', r)
# to find the attribute names ...
print(p.attribute_name(0))
# make a new FreeCAD document
cr = ifcopenshell.geom.create_shape(settings, p)
brep = cr.geometry.brep_data
shape = Part.Shape()
shape.importBrepFromString(brep)
Part.show(shape)
# ***********************************************************************************
# https://sourceforge.net/p/ifcopenshell/discussion/1782716/thread/0d5d207b67/
# ***********************************************************************************
# all rebars of specific mark number, curve
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
import ifcopenshell
f = ifcopenshell.open(ifcfile)
f.by_type('IfcReinforcingBar')
p = f.by_id(275)
from ifcopenshell.geom import settings
prefs = settings()
prefs.set(prefs.USE_BREP_DATA, True)
prefs.set(prefs.SEW_SHELLS, True)
prefs.set(prefs.USE_WORLD_COORDS, True)
prefs.set(prefs.INCLUDE_CURVES, True)
prefs.set(prefs.EXCLUDE_SOLIDS_AND_SURFACES, True)
cr = ifcopenshell.geom.create_shape(prefs, p)
# ***********************************************************************************
# polyline curve
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
import ifcopenshell
f = ifcopenshell.open(ifcfile)
f.by_type('IfcPolyline')
p = f.by_id(83)
from ifcopenshell.geom import settings
prefs = settings()
prefs.set(prefs.USE_BREP_DATA, True)
prefs.set(prefs.USE_WORLD_COORDS, True)
prefs.set(prefs.INCLUDE_CURVES, True)
prefs.set(prefs.EXCLUDE_SOLIDS_AND_SURFACES, True)
cr = ifcopenshell.geom.create_shape(prefs, p)
brep = cr.brep_data
shape.importBrepFromString(brep)
shape.scale(1000.0) # IfcOpenShell always outputs in meters
Part.show(shape)
# ***********************************************************************************
# verteilung
import ifcopenshell
# ifcfile = 'C:/Users/BHA/Desktop/example_01_two_stirrups.ifc'
#ifcfile = 'C:/Users/BHA/Desktop/example_04_vat.ifc'
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
f = ifcopenshell.open(ifcfile)
f.by_type('IfcReinforcingBar')
for rebar in f.by_type('IfcReinforcingBar'):
rs = rebar.Representation.Representations[0]
print(rs)
target = rs.Items[0].MappingSource
print(target) # swept solid
for item in rs.Items:
if item.MappingSource != target:
print(item.MappingSource)
mt = item.MappingTarget
# mt
# mt.Axis2
mt.LocalOrigin
print('\n')
p = f.by_id(275)
#p = f.by_id(366)
p
r = p.Representation
rs = r.Representations[0]
rs.Items
target = rs.Items[0].MappingSource
print(target) # swept solid
for item in rs.Items:
if item.MappingSource != target:
print(item.MappingSource)
mt = item.MappingTarget
mt
mt.Axis2
mt.LocalOrigin
p = f.by_id(275)
r = p.Representation
rs = r.Representations[0].item1 = rs.Items[0]
item1.MappingSource
mt1 = item1.MappingTarget
mt1.Axis2
print(p, '\n', r)
# to find the attribute names ...
print(rs.attribute_name(0))
p.get_info().keys()
# ***********************************************************************************
# create a rebar from polyline curve
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
import ifcopenshell, Part
f = ifcopenshell.open(ifcfile)
entity_polyline = f.by_id(215).Directrix # the polyline to sweep allong
radius = f.by_id(215).Radius
# radius = f.by_id(215).Radius * 0.999 # to get a Shape without self intersections
from ifcopenshell.geom import settings
prefs = settings()
prefs.set(prefs.USE_BREP_DATA, True)
prefs.set(prefs.USE_WORLD_COORDS, True)
prefs.set(prefs.INCLUDE_CURVES, True)
prefs.set(prefs.EXCLUDE_SOLIDS_AND_SURFACES, True)
cr = ifcopenshell.geom.create_shape(prefs, entity_polyline)
brep = cr.brep_data
sweep_path = Part.Shape()
sweep_path.importBrepFromString(brep)
sweep_path.scale(1000.0) # IfcOpenShell always outputs in meters
Part.show(sweep_path)
wire = sweep_path.Wires[0]
e = wire.Edges[0]
pnt1 = e.firstVertex().Point
pnt2 = e.lastVertex().Point
direction = pnt2 - pnt1
circle = Part.makeCircle(radius, pnt1, direction)
Part.show(circle)
circle = Part.Wire(circle)
try:
bar = wire.makePipeShell([circle],True,False,2)
except Part.OCCError:
print("Arch: error sweeping rebar profile along the base sketch")
Part.show(bar)
# ***********************************************************************************
# create a rebar from polyline curve, improved
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
import ifcopenshell
f = ifcopenshell.open(ifcfile)
es = f.by_id(275).Representation.Representations[0].Items[0].MappingSource.MappedRepresentation.Items[0]
es.Radius
es.Directrix
es = f.by_id(366).Representation.Representations[0].Items[0].MappingSource.MappedRepresentation.Items[0]
es.Radius
es.Directrix
# ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
ifcfile = 'C:/Users/BHA/Desktop/example_04_vat.ifc'
import ifcopenshell
f = ifcopenshell.open(ifcfile)
for rebar in f.by_type('IfcReinforcingBar'):
es = rebar.Representation.Representations[0].Items[0].MappingSource.MappedRepresentation.Items[0]
es.Radius
es.Directrix
# ***********************************************************************************
# create a rebar from polyline curve, for all rebars of a file
import ifcopenshell, Part
from ifcopenshell.geom import settings
prefs = settings()
prefs.set(prefs.USE_BREP_DATA, True)
prefs.set(prefs.USE_WORLD_COORDS, True)
prefs.set(prefs.INCLUDE_CURVES, True)
prefs.set(prefs.EXCLUDE_SOLIDS_AND_SURFACES, True)
# ifcfile = 'C:/Users/BHA/Desktop/example_04_vat.ifc'
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
f = ifcopenshell.open(ifcfile)
for rebar in f.by_type('IfcReinforcingBar'):
es = rebar.Representation.Representations[0].Items[0].MappingSource.MappedRepresentation.Items[0]
radius = es.Radius
entity_polyline = es.Directrix
# sweep path
cr = ifcopenshell.geom.create_shape(prefs, entity_polyline)
brep = cr.brep_data
sweep_path = Part.Shape()
sweep_path.importBrepFromString(brep)
sweep_path.scale(1000.0) # IfcOpenShell always outputs in meters
Part.show(sweep_path)
wire = sweep_path.Wires[0]
# sweep profile
e = wire.Edges[0]
pnt1 = e.firstVertex().Point
pnt2 = e.lastVertex().Point
direction = pnt2 - pnt1
circle = Part.makeCircle(radius, pnt1, direction)
Part.show(circle)
circle = Part.Wire(circle)
# make rebar by sweep
try:
bar = wire.makePipeShell([circle],True,False,2)
except Part.OCCError:
print("Arch: error sweeping rebar profile along the base sketch")
Part.show(bar)
# :-)
# ***********************************************************************************
import ifcopenshell
ifcfile = '/home/hugo/.FreeCAD/Mod/archrebarnew/example_01_two_stirrups.ifc'
f = ifcopenshell.open(ifcfile)
for rebar in f.by_type('IfcReinforcingBar'):
rs = rebar.Representation.Representations[0]
print(rs)
target = rs.Items[0].MappingSource
print(target) # swept solid
for item in rs.Items:
if item.MappingSource != target:
print(item.MappingSource)
mt = item.MappingTarget
# mt
# mt.Axis2
mt.LocalOrigin
print('\n')
for rebar in f.by_type('IfcReinforcingBar'):
print(rebar)
rebar.ObjectPlacement
rebar.ObjectPlacement.PlacementRelTo.RelativePlacement.Location # should be 0,0,0 ... #68=IfcCartesianPoint((0.,0.,0.))
rebar.ObjectPlacement.RelativePlacement.Location # is the placement of the array distribution as IfcCartesianPoint