Error Creating Mesh Representation

Hi,
I'm trying to create mesh representation following code examples from the docs:

# Let's create a new project using millimeters with a single furniture element at the origin.
model = run("project.create_file")
run("root.create_entity", model, ifc_class="IfcProject")
run("unit.assign_unit", model)

# We want our representation to be the 3D body of the element.
# This representation context is only created once per project.
# You must reuse the same body context every time you create a new representation.
model3d = 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=model3d)

# Create our element with an object placement.
element = run("root.create_entity", model, ifc_class="IfcFurniture")
run("geometry.edit_object_placement", model, product=element)

# Let's create our representation!
# See below sections for examples on how to create representations.
# These vertices and faces represent a 2m square 1m high pyramid in SI units.
# Note how they are nested lists. Each nested list represents a "mesh". There may be multiple meshes.
vertices = [[(0.,0.,0.), (0.,2.,0.), (2.,2.,0.), (2.,0.,0.), (1.,1.,1.)]]
faces = [[(0,1,2,3), (0,4,1), (1,4,2), (2,4,3), (3,4,0)]]
representation = run("geometry.add_mesh_representation", model, context=body, vertices=vertices, faces=faces)

# Assign our new body representation back to our element
run("geometry.assign_representation", model, product=element, representation=representation)

I have the latest ifcopenshell version: 0.7.0.240521 - pypi_0

The Error:

TypeError Traceback (most recent call last)
Cell In[50], line 23
21 vertices = [[(0.,0.,0.), (0.,2.,0.), (2.,2.,0.), (2.,0.,0.), (1.,1.,1.)]]
22 faces = [[(0,1,2,3), (0,4,1), (1,4,2), (2,4,3), (3,4,0)]]
---> 23 representation = run("geometry.add_mesh_representation", model, context=body, vertices=vertices, faces=faces)
25 # Assign our new body representation back to our element
26 run("geometry.assign_representation", model, product=element, representation=representation)

File c:\Users\Markus\anaconda3\envs\gnn2\Lib\site-packages\ifcopenshell\api__init__.py:184, in run(usecase_path, ifc_file, should_run_listeners, **settings)
182 CACHED_USECASES[usecase_path] = usecase_function
183 if ifc_file:
--> 184 return usecase_function(ifc_file, should_run_listeners=should_run_listeners, **settings)
185 return usecase_function(should_run_listeners=should_run_listeners, **settings)
187 if should_run_listeners:

File c:\Users\Markus\anaconda3\envs\gnn2\Lib\site-packages\ifcopenshell\api__init__.py:344, in wrap_usecase..wrapper(should_run_listeners, *args, **settings)
341 usecase_path, settings = ARGUMENTS_DEPRECATION[usecase_path](usecase_path, settings)
343 try:
--> 344 result = usecase(*args, **settings)
345 except NotImplementedError as e:
346 if not e.args[0].startswith(f"{usecase.__name__}()"):
347 # signature errors typically start with function name
348 # e.g. "TypeError: edit_library() got an unexpected keyword argument 'test'"
349 # otherwise it's an error inside api call and we shouldn't get in the way

TypeError: add_mesh_representation() missing 1 required positional argument: 'edges'

Tagged:

Comments

  • I cant find 'edges' in the docs..

  • Solved: Add an empty list

    vertices = [[(0.,0.,0.), (0.,2.,0.), (2.,2.,0.), (2.,0.,0.), (1.,1.,1.)]]
    faces = [[(0,1,2,3), (0,4,1), (1,4,2), (2,4,3), (3,4,0)]]
    edges = [[]]  # Empty edges list
    
    # Create the mesh representation
    representation = run("geometry.add_mesh_representation", model, context=body, vertices=vertices, faces=faces, edges=edges)
    
    John
Sign In or Register to comment.