Latest revision |
Your text |
Line 61: |
Line 61: |
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
| import bpy | | import bpy |
− | from blenderbim.bim.ifc import IfcStore
| |
| | | |
− | obj = bpy.context.active_object
| + | bpy.context.active_object.BIMObjectProperties.attributes["GlobalId"].string_value |
− | IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id).GlobalId
| |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
Line 112: |
Line 110: |
| prop.string_value = "Hello World !" | | prop.string_value = "Hello World !" |
| </syntaxhighlight> | | </syntaxhighlight> |
− |
| |
− | =Clash Detection=
| |
− | ==Clash Detection on 2 sets of elements==
| |
− | Clash Detection on 3 cubes in two sets in this example:
| |
− | <syntaxhighlight lang="python">
| |
− | import bpy
| |
− | import collision
| |
− | import numpy as np
| |
− | import bmesh
| |
− | import ifcclash
| |
− |
| |
− |
| |
− | def get_collision_results(set_a=None, set_b=None):
| |
− | a_cm = collision.CollisionManager()
| |
− | b_cm = collision.CollisionManager()
| |
− | add_to_cm(a_cm, set_a)
| |
− | add_to_cm(b_cm, set_b)
| |
− | return a_cm.in_collision_other(b_cm, return_data=True)
| |
− |
| |
− |
| |
− | def add_to_cm(cm, object_names):
| |
− | for object_name in object_names:
| |
− | name = object_name.name
| |
− | obj = bpy.data.objects[name]
| |
− | triangulated_mesh = triangulate_mesh(obj)
| |
− | mat = np.array(obj.matrix_world)
| |
− | mesh = ifcclash.Mesh()
| |
− | mesh.vertices = np.array([tuple(v.co) for v in triangulated_mesh.vertices])
| |
− | mesh.faces = np.array([tuple(p.vertices) for p in triangulated_mesh.polygons])
| |
− | cm.add_object(name, mesh, mat)
| |
− |
| |
− |
| |
− | def triangulate_mesh(obj):
| |
− | mesh = obj.evaluated_get(bpy.context.evaluated_depsgraph_get()).to_mesh()
| |
− | bm = bmesh.new()
| |
− | bm.from_mesh(mesh)
| |
− | bmesh.ops.triangulate(bm, faces=bm.faces)
| |
− | bm.to_mesh(mesh)
| |
− | bm.free()
| |
− | del bm
| |
− | return mesh
| |
− |
| |
− |
| |
− | set_a = [
| |
− | bpy.data.scenes['Scene'].objects['Cube'],
| |
− | ]
| |
− | set_b = [
| |
− | bpy.data.scenes['Scene'].objects['Cube.001'],
| |
− | bpy.data.scenes['Scene'].objects['Cube.002'],
| |
− | ]
| |
− |
| |
− |
| |
− | err, results = get_collision_results(set_a=set_a, set_b=set_b)
| |
− |
| |
− | seen_pairs = set()
| |
− | for result in results:
| |
− | result_pair = result.names
| |
− | result_names_str = str(result_pair)
| |
− | if result_names_str in seen_pairs:
| |
− | continue
| |
− | seen_pairs.add(str(result_pair))
| |
− | print(35 * "-")
| |
− | print(result_names_str)
| |
− | </syntaxhighlight>
| |
− |
| |
| | | |
| [[Category:Blender]] [[Category:BlenderBIM Add-on]] | | [[Category:Blender]] [[Category:BlenderBIM Add-on]] |