Skip to content

Commit

Permalink
properly update attributes and check for guids
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Sep 9, 2024
1 parent 81f8ded commit 73f08e1
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions src/compas_rui/scene/meshobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def select_vertices(self):
elif option == "Degree":
D = rs.GetInteger(message="Vertex Degree", number=2, minimum=1)
D = D or 0
vertices = self.mesh.vertices_where(vertex_degree=D)
vertices = list(self.mesh.vertices_where(vertex_degree=D))

elif option == "EdgeLoop":
self.show_edges = True
Expand All @@ -48,7 +48,7 @@ def select_vertices(self):
rs.Redraw()

guids = compas_rhino.objects.select_lines(message="Select Edges")
edges = [self._guid_edge.get(guid) for guid in guids] if guids else []
edges = [self._guid_edge[guid] for guid in guids if guid in self._guid_edge] if guids else []
temp = []
for edge in edges:
for u, v in self.mesh.edge_loop(edge):
Expand All @@ -64,7 +64,7 @@ def select_vertices(self):

elif option == "Manual":
guids = compas_rhino.objects.select_points(message="Select Vertices")
vertices = [self._guid_vertex.get(guid) for guid in guids] if guids else []
vertices = [self._guid_vertex[guid] for guid in guids if guid in self._guid_vertex] if guids else []

return vertices

Expand All @@ -91,7 +91,7 @@ def select_edges(self):

elif option == "Manual":
guids = compas_rhino.objects.select_lines(message="Select Edges")
edges = [self._guid_edge.get(guid) for guid in guids] if guids else []
edges = [self._guid_edge[guid] for guid in guids if guid in self._guid_edge] if guids else []

return edges

Expand Down Expand Up @@ -138,6 +138,9 @@ def update_attributes(self):
def update_vertex_attributes(self, vertices, names=None):
# type: (list[int], list[str] | None) -> bool

if not vertices:
return False

names = names or sorted(self.mesh.default_vertex_attributes.keys())
names = sorted([name for name in names if not name.startswith("_")])

Expand All @@ -148,17 +151,23 @@ def update_vertex_attributes(self, vertices, names=None):
if values[i] != self.mesh.vertex_attribute(vertex, name):
values[i] = "-"
break
values = map(str, values)
values = list(map(str, values))

form = NamedValuesForm(names=names, values=values)
if form.show():
self.mesh.attributes.update(form.attributes)
for name, value in form.attributes.items():
if value == "-":
continue
self.mesh.vertices_attribute(name=name, value=value, keys=vertices)
return True
return False

def update_face_attributes(self, faces, names=None):
# type: (list[int], list[str] | None) -> bool

if not faces:
return False

names = names or sorted(self.mesh.default_face_attributes.keys())
names = sorted([name for name in names if not name.startswith("_")])

Expand All @@ -169,17 +178,23 @@ def update_face_attributes(self, faces, names=None):
if values[i] != self.mesh.face_attribute(face, name):
values[i] = "-"
break
values = map(str, values)
values = list(map(str, values))

form = NamedValuesForm(names=names, values=values)
if form.show():
self.mesh.attributes.update(form.attributes)
for name, value in form.attributes.items():
if value == "-":
continue
self.mesh.faces_attribute(name=name, value=value, keys=faces)
return True
return False

def update_edge_attributes(self, edges, names=None):
# type: (list[tuple[int, int]], list[str] | None) -> bool

if not edges:
return False

names = names or sorted(self.mesh.default_edge_attributes.keys())
names = sorted([name for name in names if not name.startswith("_")])

Expand All @@ -190,11 +205,14 @@ def update_edge_attributes(self, edges, names=None):
if values[i] != self.mesh.edge_attribute(edge, name):
values[i] = "-"
break
values = map(str, values)
values = list(map(str, values))

form = NamedValuesForm(names=names, values=values)
if form.show():
self.mesh.attributes.update(form.attributes)
for name, value in form.attributes.items():
if value == "-":
continue
self.mesh.edges_attribute(name=name, value=value, keys=edges)
return True
return False

Expand Down

0 comments on commit 73f08e1

Please sign in to comment.