mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-13 02:47:48 +00:00
Replace all ifcopenshell.api.run with ifcopenshell.api static functions.
This commit is contained in:
@@ -56,7 +56,7 @@ def add_style(
|
||||
.. code:: python
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
"""
|
||||
|
||||
kwargs = {"Name": name}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
from typing import Any, Optional, Literal
|
||||
|
||||
|
||||
@@ -99,17 +99,17 @@ def add_surface_style(
|
||||
.. code:: python
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Create a simple shading colour and transparency.
|
||||
ifcopenshell.api.run("style.add_surface_style", model,
|
||||
ifcopenshell.api.style.add_surface_style(model,
|
||||
style=style, ifc_class="IfcSurfaceStyleShading", attributes={
|
||||
"SurfaceColour": { "Name": None, "Red": 1.0, "Green": 0.8, "Blue": 0.8 },
|
||||
"Transparency": 0., # 0 is opaque, 1 is transparent
|
||||
})
|
||||
|
||||
# Alternatively, create a rendering style.
|
||||
ifcopenshell.api.run("style.add_surface_style", model,
|
||||
ifcopenshell.api.style.add_surface_style(model,
|
||||
style=style, ifc_class="IfcSurfaceStyleRendering", attributes={
|
||||
# A surface colour and transparency is still supplied for
|
||||
# viewport display only. This will supersede the shading
|
||||
@@ -130,7 +130,7 @@ def add_surface_style(
|
||||
settings = {"style": style, "ifc_class": ifc_class, "attributes": attributes or {}}
|
||||
|
||||
style_item = file.create_entity(settings["ifc_class"])
|
||||
ifcopenshell.api.run("style.edit_surface_style", file, style=style_item, attributes=settings["attributes"])
|
||||
ifcopenshell.api.style.edit_surface_style(file, style=style_item, attributes=settings["attributes"])
|
||||
styles = list(settings["style"].Styles or [])
|
||||
|
||||
select_class = settings["ifc_class"]
|
||||
@@ -138,7 +138,7 @@ def add_surface_style(
|
||||
select_class = "IfcSurfaceStyleShading"
|
||||
duplicate_items = [s for s in styles if s.is_a(select_class)]
|
||||
for duplicate_item in duplicate_items:
|
||||
ifcopenshell.api.run("style.remove_surface_style", file, style=duplicate_item)
|
||||
ifcopenshell.api.style.remove_surface_style(file, style=duplicate_item)
|
||||
|
||||
styles = list(settings["style"].Styles or [])
|
||||
styles.append(style_item)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
@@ -59,41 +59,41 @@ def assign_material_style(
|
||||
.. code:: python
|
||||
|
||||
# A model context is needed to store 3D geometry
|
||||
model3d = ifcopenshell.api.run("context.add_context", model, context_type="Model")
|
||||
model3d = ifcopenshell.api.context.add_context(model, context_type="Model")
|
||||
|
||||
# Specifically, we want to store body geometry
|
||||
body = ifcopenshell.api.run("context.add_context", model,
|
||||
body = ifcopenshell.api.context.add_context(model,
|
||||
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)
|
||||
|
||||
# Let's create a new wall. The wall does not have any geometry yet.
|
||||
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||
|
||||
# Let's use the "3D Body" representation we created earlier to add a
|
||||
# new wall-like body geometry, 5 meters long, 3 meters high, and
|
||||
# 200mm thick
|
||||
representation = ifcopenshell.api.run("geometry.add_wall_representation", model,
|
||||
representation = ifcopenshell.api.geometry.add_wall_representation(model,
|
||||
context=body, length=5, height=3, thickness=0.2)
|
||||
|
||||
# Assign our new body geometry back to our wall
|
||||
ifcopenshell.api.run("geometry.assign_representation", model,
|
||||
ifcopenshell.api.geometry.assign_representation(model,
|
||||
product=wall, representation=representation)
|
||||
|
||||
# Place our wall at the origin
|
||||
ifcopenshell.api.run("geometry.edit_object_placement", model, product=wall)
|
||||
ifcopenshell.api.geometry.edit_object_placement(model, product=wall)
|
||||
|
||||
# Let's prepare a concrete material. Note that our concrete material
|
||||
# does not have any colours (styles) at this point.
|
||||
concrete = ifcopenshell.api.run("material.add_material", model, name="CON01", category="concrete")
|
||||
concrete = ifcopenshell.api.material.add_material(model, name="CON01", category="concrete")
|
||||
|
||||
# Assign our concrete material to our wall
|
||||
ifcopenshell.api.run("material.assign_material", model,
|
||||
ifcopenshell.api.material.assign_material(model,
|
||||
products=[wall], type="IfcMaterial", material=concrete)
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Create a simple grey shading colour and transparency.
|
||||
ifcopenshell.api.run("style.add_surface_style", model,
|
||||
ifcopenshell.api.style.add_surface_style(model,
|
||||
style=style, ifc_class="IfcSurfaceStyleShading", attributes={
|
||||
"SurfaceColour": { "Name": None, "Red": 0.5, "Green": 0.5, "Blue": 0.5 },
|
||||
"Transparency": 0., # 0 is opaque, 1 is transparent
|
||||
@@ -101,7 +101,7 @@ def assign_material_style(
|
||||
|
||||
# Now any element (like our wall) with a concrete material will have
|
||||
# a grey colour applied.
|
||||
ifcopenshell.api.run("style.assign_material_style", model, material=concrete, style=style, context=body)
|
||||
ifcopenshell.api.style.assign_material_style(model, material=concrete, style=style, context=body)
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
@@ -143,8 +143,8 @@ class Usecase:
|
||||
continue
|
||||
|
||||
for rep in shape_aspect.ShapeRepresentations:
|
||||
ifcopenshell.api.run(
|
||||
"style.assign_representation_styles", self.file, shape_representation=rep, styles=[self.style]
|
||||
ifcopenshell.api.style.assign_representation_styles(
|
||||
self.file, shape_representation=rep, styles=[self.style]
|
||||
)
|
||||
|
||||
def modify_existing_definition_representation(self):
|
||||
|
||||
@@ -64,40 +64,40 @@ def assign_representation_styles(
|
||||
.. code:: python
|
||||
|
||||
# A model context is needed to store 3D geometry
|
||||
model3d = ifcopenshell.api.run("context.add_context", model, context_type="Model")
|
||||
model3d = ifcopenshell.api.context.add_context(model, context_type="Model")
|
||||
|
||||
# Specifically, we want to store body geometry
|
||||
body = ifcopenshell.api.run("context.add_context", model,
|
||||
body = ifcopenshell.api.context.add_context(model,
|
||||
context_type="Model", context_identifier="Body", target_view="MODEL_VIEW", parent=model3d)
|
||||
|
||||
# Let's create a new wall. The wall does not have any geometry yet.
|
||||
wall = ifcopenshell.api.run("root.create_entity", model, ifc_class="IfcWall")
|
||||
wall = ifcopenshell.api.root.create_entity(model, ifc_class="IfcWall")
|
||||
|
||||
# Let's use the "3D Body" representation we created earlier to add a
|
||||
# new wall-like body geometry, 5 meters long, 3 meters high, and
|
||||
# 200mm thick
|
||||
representation = ifcopenshell.api.run("geometry.add_wall_representation", model,
|
||||
representation = ifcopenshell.api.geometry.add_wall_representation(model,
|
||||
context=body, length=5, height=3, thickness=0.2)
|
||||
|
||||
# Assign our new body geometry back to our wall
|
||||
ifcopenshell.api.run("geometry.assign_representation", model,
|
||||
ifcopenshell.api.geometry.assign_representation(model,
|
||||
product=wall, representation=representation)
|
||||
|
||||
# Place our wall at the origin
|
||||
ifcopenshell.api.run("geometry.edit_object_placement", model, product=wall)
|
||||
ifcopenshell.api.geometry.edit_object_placement(model, product=wall)
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Create a simple grey shading colour and transparency.
|
||||
ifcopenshell.api.run("style.add_surface_style", model,
|
||||
ifcopenshell.api.style.add_surface_style(model,
|
||||
style=style, ifc_class="IfcSurfaceStyleShading", attributes={
|
||||
"SurfaceColour": { "Name": None, "Red": 0.5, "Green": 0.5, "Blue": 0.5 },
|
||||
"Transparency": 0., # 0 is opaque, 1 is transparent
|
||||
})
|
||||
|
||||
# Now specifically our wall only will be coloured grey.
|
||||
ifcopenshell.api.run("style.assign_representation_styles", model,
|
||||
ifcopenshell.api.style.assign_representation_styles(model,
|
||||
shape_representation=representation, styles=[style])
|
||||
"""
|
||||
usecase = Usecase()
|
||||
|
||||
@@ -39,10 +39,10 @@ def edit_presentation_style(
|
||||
.. code:: python
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Change the name of the style to "Foo"
|
||||
ifcopenshell.api.run("style.edit_presentation_style", model, style=style, attributes={"Name": "Foo"})
|
||||
ifcopenshell.api.style.edit_presentation_style(model, style=style, attributes={"Name": "Foo"})
|
||||
"""
|
||||
settings = {"style": style, "attributes": attributes or {}}
|
||||
|
||||
|
||||
@@ -47,14 +47,14 @@ def edit_surface_style(
|
||||
.. code:: python
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Create a blank rendering style.
|
||||
rendering = ifcopenshell.api.run("style.add_surface_style", model,
|
||||
rendering = ifcopenshell.api.style.add_surface_style(model,
|
||||
style=style, ifc_class="IfcSurfaceStyleRendering")
|
||||
|
||||
# Edit the attributes of the rendering style.
|
||||
ifcopenshell.api.run("style.edit_surface_style", model,
|
||||
ifcopenshell.api.style.edit_surface_style(model,
|
||||
style=rendering, attributes={
|
||||
# A surface colour and transparency is still supplied for
|
||||
# viewport display only. This will supersede the shading
|
||||
|
||||
@@ -15,7 +15,8 @@
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
|
||||
import ifcopenshell.api
|
||||
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
@@ -34,10 +35,10 @@ def remove_style(file: ifcopenshell.file, style: ifcopenshell.entity_instance) -
|
||||
.. code:: python
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Not anymore!
|
||||
ifcopenshell.api.run("style.remove_style", model, style=style)
|
||||
ifcopenshell.api.style.remove_style(model, style=style)
|
||||
"""
|
||||
usecase = Usecase()
|
||||
usecase.file = file
|
||||
@@ -49,7 +50,7 @@ class Usecase:
|
||||
def execute(self):
|
||||
self.purge_styled_items(self.settings["style"])
|
||||
for style in self.settings["style"].Styles or []:
|
||||
ifcopenshell.api.run("style.remove_surface_style", self.file, style=style)
|
||||
ifcopenshell.api.style.remove_surface_style(self.file, style=style)
|
||||
self.file.remove(self.settings["style"])
|
||||
|
||||
def purge_styled_items(self, style):
|
||||
|
||||
@@ -34,7 +34,7 @@ def remove_styled_representation(file: ifcopenshell.file, representation: ifcope
|
||||
.. code:: python
|
||||
|
||||
# Remove a styled representation
|
||||
ifcopenshell.api.run("style.remove_styled_representation", model, representation=representation)
|
||||
ifcopenshell.api.style.remove_styled_representation(model, representation=representation)
|
||||
"""
|
||||
settings = {"representation": representation}
|
||||
|
||||
|
||||
@@ -33,17 +33,17 @@ def remove_surface_style(file: ifcopenshell.file, style: ifcopenshell.entity_ins
|
||||
.. code:: python
|
||||
|
||||
# Create a new surface style
|
||||
style = ifcopenshell.api.run("style.add_style", model)
|
||||
style = ifcopenshell.api.style.add_style(model)
|
||||
|
||||
# Create a simple shading colour and transparency.
|
||||
shading = ifcopenshell.api.run("style.add_surface_style", model,
|
||||
shading = ifcopenshell.api.style.add_surface_style(model,
|
||||
style=style, ifc_class="IfcSurfaceStyleShading", attributes={
|
||||
"SurfaceColour": { "Name": None, "Red": 1.0, "Green": 0.8, "Blue": 0.8 },
|
||||
"Transparency": 0., # 0 is opaque, 1 is transparent
|
||||
})
|
||||
|
||||
# Remove the shading item
|
||||
ifcopenshell.api.run("style.remove_surface_style", model, style=shading)
|
||||
ifcopenshell.api.style.remove_surface_style(model, style=shading)
|
||||
"""
|
||||
|
||||
to_delete = set()
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.api
|
||||
import ifcopenshell.api.style
|
||||
import ifcopenshell.util.element
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ def unassign_material_style(
|
||||
|
||||
.. code:: python
|
||||
|
||||
ifcopenshell.api.run("style.unassign_material_style", model, material=concrete, style=style, context=body)
|
||||
ifcopenshell.api.style.unassign_material_style(model, material=concrete, style=style, context=body)
|
||||
"""
|
||||
settings = {
|
||||
"material": material,
|
||||
@@ -100,9 +100,6 @@ def unassign_material_style(
|
||||
continue
|
||||
|
||||
for rep in shape_aspect.ShapeRepresentations:
|
||||
ifcopenshell.api.run(
|
||||
"style.unassign_representation_styles",
|
||||
file,
|
||||
shape_representation=rep,
|
||||
styles=[settings["style"]],
|
||||
ifcopenshell.api.style.unassign_representation_styles(
|
||||
file, shape_representation=rep, styles=[settings["style"]]
|
||||
)
|
||||
|
||||
@@ -49,7 +49,7 @@ def unassign_representation_styles(
|
||||
|
||||
.. code:: python
|
||||
|
||||
ifcopenshell.api.run("style.unassign_representation_styles", model,
|
||||
ifcopenshell.api.style.unassign_representation_styles(model,
|
||||
shape_representation=representation, styles=[style])
|
||||
"""
|
||||
usecase = Usecase()
|
||||
|
||||
Reference in New Issue
Block a user