Skip to content

Commit cd7dbfc

Browse files
committed
handle name and kwargs on assembly/part
1 parent 9e90f2c commit cd7dbfc

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/compas/datastructures/assembly/assembly.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,23 @@ def JSONSCHEMANAME(self):
3333
def __init__(self, name=None, **kwargs):
3434
super(Assembly, self).__init__()
3535
self.attributes = {'name': name or 'Assembly'}
36+
self.attributes.update(kwargs)
3637
self.graph = Graph()
3738
self._parts = {}
3839

3940
def __str__(self):
4041
tpl = "<Assembly with {} parts and {} connections>"
4142
return tpl.format(self.graph.number_of_nodes(), self.graph.number_of_edges())
4243

44+
@property
45+
def name(self):
46+
"""str : The name of the assembly."""
47+
return self.attributes.get('name') or self.__class__.__name__
48+
49+
@name.setter
50+
def name(self, value):
51+
self.attributes['name'] = value
52+
4353
@property
4454
def data(self):
4555
"""dict : A data dict representing the assembly data structure for serialization.

src/compas/datastructures/assembly/part.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,11 @@ def DATASCHEMA(self):
7474
def JSONSCHEMANAME(self):
7575
return 'part'
7676

77-
def __init__(self, name, frame=None, shape=None, features=None, **kwargs):
77+
def __init__(self, name=None, frame=None, shape=None, features=None, **kwargs):
7878
super(Part, self).__init__()
7979
self._frame = None
8080
self.attributes = {'name': name or 'Part'}
81+
self.attributes.update(kwargs)
8182
self.key = None
8283
self.frame = frame
8384
self.shape = shape or Shape([], [])
@@ -88,6 +89,15 @@ def __str__(self):
8889
tpl = "<Part with shape {} and features {}>"
8990
return tpl.format(self.shape, self.features)
9091

92+
@property
93+
def name(self):
94+
"""str : The name of the part."""
95+
return self.attributes.get('name') or self.__class__.__name__
96+
97+
@name.setter
98+
def name(self, value):
99+
self.attributes['name'] = value
100+
91101
@property
92102
def data(self):
93103
"""dict : A data dict representing the part attributes, the assembly graph identifier, the local coordinate system,

0 commit comments

Comments
 (0)