You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently working with the dict_to_path function to generate parametric meshes from dictionaries, I ran across a bug where passing Line objects raises AttributeError: property 'closed' of 'Line' object has no setter.
I managed to find a patch consisting in checking the entity type and forwarding the closedargument accordingly.
importtrimeshdefdict_to_path_patched(as_dict):
""" Turn a pure dict into a dict containing entity objects that can be sent directly to a Path constructor. Parameters ------------ as_dict : dict Has keys: 'vertices', 'entities' Returns ------------ kwargs : dict Has keys: 'vertices', 'entities' """# start kwargs with initial valueresult=as_dict.copy()
# map of constructorsloaders= {"Arc": trimesh.path.entities.Arc, "Line": trimesh.path.entities.Line}
# pre- allocate entity arrayentities= [None] *len(as_dict["entities"])
# run constructor for dict kwargsforentity_index, entityinenumerate(as_dict["entities"]):
# --- start of edited section ---ifentity["type"] =='Line':
entities[entity_index] =loaders[entity["type"]](
points=entity["points"]
)
else:
entities[entity_index] =loaders[entity["type"]](
points=entity["points"], closed=entity["closed"]
)
# --- end of edited section ---# --- start of original section ---entities[entity_index] =loaders[entity["type"]](
points=entity["points"], closed=entity["closed"]
)
# --- end of original section ---result["entities"] =entitiesreturnresult
Here is minimum working example demonstrating the issue and the proposed fix.
x, y, z=2, 3, 5path_2d_dict= {
'entities': [
{'type': 'Line', 'points': [0, 1, 2, 3, 0], 'closed': False},
],
'vertices': [
[-x/2, y/2],
[x/2, y/2],
[x/2, -y/2],
[-x/2, -y/2],
]
}
path_2d_from_dict=trimesh.path.exchange.load.load_path(
trimesh.path.exchange.misc.dict_to_path(path_2d_dict) # Default function -> raises AttributeError: property 'closed' of 'Line' object has no setter# dict_to_path_patched(path_2d_dict) # Patched function -> Works as expected
)
path_2d_from_dict.show()
Also removing closed: False from the entities list ('entities': [{'type': 'Line', 'points': [0, 1, 2, 3, 0]}],) raises KeyError: 'closed'.
System infos
Python 3.13.0
trimesh 4.5.0
The text was updated successfully, but these errors were encountered:
Currently working with the
dict_to_path
function to generate parametric meshes from dictionaries, I ran across a bug where passingLine
objects raisesAttributeError: property 'closed' of 'Line' object has no setter
.I managed to find a patch consisting in checking the entity type and forwarding the
closed
argument accordingly.Here is minimum working example demonstrating the issue and the proposed fix.
Also removing
closed: False
from theentities
list ('entities': [{'type': 'Line', 'points': [0, 1, 2, 3, 0]}],
) raisesKeyError: 'closed'
.System infos
trimesh 4.5.0
The text was updated successfully, but these errors were encountered: