-
Creating a Representation of Electrical Cables with IFCopenshellMy goal is to draw a representation of an electrical cable in an IFC file, and I'm having trouble reading through the documentation (as the python user guide detailing creating entities has not been completed. There are detailed examples for how to create walls and doors, but there are not examples on creating/assigning geometry to other objects. The following Is the code I have tried:
I figured I could create an IfcCableSegment, then assign the geometry data to this, but when I try, I get this error
This is not a dependency for the IfcOpenshell project. Even when I install this with pip, I get a different package missing error:
This module is not in the documentation and does not seem to exist yet. If you exclude the last two lines of code, it does create a cable object, at (0,0,0) without any attributes.
I'm a little at a loss of how to create objects to represent cables. TLDR
Orion |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hi Orion, I can see that geometry.add_representation depends on blender's data model and blender object. Not sure how the workflow is though. Would love to explore this further. |
Beta Was this translation helpful? Give feedback.
-
Indeed, while most of the API is indeed agnostic to blender, for the geometry-heavy bits, creating a proper layer of isolation between would be challenging. Any help on this front is appreciated, but I think for now it is simplest to just use the lower level direct instance manipulation and create a representation manually.
It does seem to exist, but probably is recent. IfcOpenShell on pip is sometimes a bit outdated. Maybe copy manually from here IfcOpenBot@b33e58f#comments |
Beta Was this translation helpful? Give feedback.
-
As @aothms said, the majority of the API is agnostic to Blender. However the There are hundreds of ways to create geometry. The API only handles the most common ways like parametric layered and profile extrusions and arbitrary meshes (but maybe as you say "cable-like" or "rebar-like" geometry should be added to the API for convenience). Once you start deviating and wanting to add your own geometry, you have two options: either go down to the core level and create swept disk solids etc from scratch as @aothms is suggesting, or alternatively, and this is what I'd recommend: use the ShapeBuilder utility instead, which is an API somewhat in-between the high-level API and the low-level total manual approach. This is a solution using the ShapeBuilder utility: import ifcopenshell
import ifcopenshell.geom
import ifcopenshell.util.shape_builder
from ifcopenshell.api import run
# Create a blank model
model = run("project.create_file", version="IFC4")
project = run("root.create_entity", model, ifc_class="IfcProject", name="My Project")
run("unit.assign_unit", model)
context = run("context.add_context", model, context_type="Model")
body = run("context.add_context", model, context_type="Model",
context_identifier="Body", target_view="MODEL_VIEW", parent=context)
site = run("root.create_entity", model, ifc_class="IfcSite", name="My Site")
run("aggregate.assign_object", model, relating_object=project, product=site)
# Let's create a cable
cable = run("root.create_entity", model, ifc_class="IfcCableSegment")
sb = ifcopenshell.util.shape_builder.ShapeBuilder(model)
curve = sb.polyline([(0., 0., 0.), (1000., 0., 0.), (1707., 293., 0.), (2000., 1000., 0.), (2000., 2000., 0.)], arc_points=[2])
swept_curve = sb.create_swept_disk_solid(curve, 5) # 5 is radius
representation = sb.get_representation(body, swept_curve)
# Add a new cable-like body geometry, from sample cable
run("geometry.assign_representation", model, product=cable, representation=representation)
run("spatial.assign_container", model, relating_structure=site, product=cable)
# Write out to a file
model.write("/home/dion/test.ifc") It produces this:
That's what the IFC documentation is for, and you can see a list of IFC entities here: https://ifc43-docs.standards.buildingsmart.org/IFC/RELEASE/IFC4x3/HTML/annex-c.html - I'd also say our API docs do a pretty good job of explaining things too: https://blenderbim.org/docs-python/autoapi/ifcopenshell/api/index.html which is less technical and comes with lots of code examples. Do you have any specific questions?
Unfortunately writing docs about creating geometry takes a lot of effort. There's a lot of functionality, just a bit hidden and constantly being updated. Our docs have improved drastically in the past year, and I suspect over time we'll get even better docs dedicated to geometry. Would you like to help? |
Beta Was this translation helpful? Give feedback.
As @aothms said, the majority of the API is agnostic to Blender. However the
add_representation
API depends on Blender. This is a bit historic and we should really rename it toadd_blender_representation
to prevent confusion.There are hundreds of ways to create geometry. The API only handles the most common ways like parametric layered and profile extrusions and arbitrary meshes (but maybe as you say "cable-like" or "rebar-like" geometry should be added to the API for convenience).
Once you start deviating and wanting to add your own geometry, you have two options: either go down to the core level and create swept disk solids etc from scratch as @aothms is suggesting, or alternatively, a…