55import json
66from dataclasses import dataclass , field
77
8+ # use a key and not all the sticky
9+ _STICKY_KEY = "df_poses"
10+
11+ def _get_store ():
12+ # returns private sub-dict inside rhino sticky
13+ return rh_sticky_dict .setdefault (_STICKY_KEY , {})
14+
815@dataclass
916class DFPose :
1017 """
@@ -29,14 +36,14 @@ class DFPosesBeam:
2936 This class contains the poses of a single beam, at different times in the assembly process.
3037 It also contains the number of faces detected for this element, based on which the poses are calculated.
3138 """
32- poses_dictionnary : dict
39+ poses_dictionary : dict
3340 n_faces : int = 3
3441
3542 def add_pose (self , pose : DFPose , step_number : int ):
3643 """
3744 Add a pose to the dictionary of poses.
3845 """
39- self .poses_dictionnary [f"pose_{ step_number } " ] = pose
46+ self .poses_dictionary [f"pose_{ step_number } " ] = pose
4047
4148 def set_n_faces (self , n_faces : int ):
4249 """
@@ -47,7 +54,7 @@ def set_n_faces(self, n_faces: int):
4754@dataclass
4855class DFPosesAssembly :
4956 n_step : int = 0
50- poses_per_element_dictionary : dict = field (default_factory = lambda : rh_sticky_dict )
57+ poses_per_element_dictionary : dict = field (default_factory = _get_store )
5158
5259 """
5360 This class contains the poses of the different elements of the assembly, at different times in the assembly process.
@@ -58,7 +65,7 @@ def __post_init__(self):
5865 """
5966 lengths = []
6067 for element in self .poses_per_element_dictionary :
61- lengths .append (len (self .poses_per_element_dictionary [element ].poses_dictionnary ))
68+ lengths .append (len (self .poses_per_element_dictionary [element ].poses_dictionary ))
6269 self .n_step = max (lengths ) if lengths else 0
6370
6471 def add_step (self , new_poses : list [DFPose ]):
@@ -78,15 +85,18 @@ def get_last_poses(self):
7885 return None
7986 last_poses = []
8087 for i in range (len (self .poses_per_element_dictionary )):
81- last_poses .append (self .poses_per_element_dictionary [f"element_{ i } " ].poses_dictionnary [f"pose_{ self .n_step - 1 } " ])
88+ last_poses .append (self .poses_per_element_dictionary [f"element_{ i } " ].poses_dictionary [f"pose_{ self .n_step - 1 } " ])
8289 return last_poses
8390
8491 def reset (self ):
8592 """
8693 Reset the assembly poses to the initial state.
8794 """
8895 self .n_step = 0
89- rh_sticky_dict .clear ()
96+ # clear only namespace
97+ rh_sticky_dict [_STICKY_KEY ] = {}
98+ # refresh the local reference to the (now empty) store
99+ self .poses_per_element_dictionary = _get_store ()
90100
91101 def save (self , file_path : str ):
92102 """
@@ -102,7 +112,7 @@ def to_gh_tree(self):
102112 list_of_poses = []
103113 for element , poses in self .poses_per_element_dictionary .items ():
104114 list_of_pose_of_element = []
105- for pose in poses .poses_dictionnary .values ():
115+ for pose in poses .poses_dictionary .values ():
106116 list_of_pose_of_element .append (pose .to_rh_plane () if pose is not None else None )
107117 list_of_poses .append (list_of_pose_of_element )
108118 return th .list_to_tree (list_of_poses )
0 commit comments