Skip to content

Commit d963eec

Browse files
patrickjahnsPatrick Jahns
authored andcommitted
fix: traveres from main take when setting a take for rendering
Prior to this change, the user would need to set/activate the main take first before submitting the file to deadline cloud. If the user did not select the Main/Base take, a take that is a sub-descent from the currently selected take would not be found. Signed-off-by: Patrick Jahns <kontakt@patrickjahns.de>
1 parent 8cb3154 commit d963eec

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

src/deadline/cinema4d_adaptor/Cinema4DClient/cinema4d_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ def get_child_takes(take):
420420
all_takes.extend(get_child_takes(child_take))
421421
return all_takes
422422

423-
main_take = take_data.GetCurrentTake()
423+
main_take = take_data.GetMainTake()
424424
all_takes = [main_take] + get_child_takes(main_take)
425425

426426
matched_take = None

test/unit/deadline_adaptor_for_cinema4d/Cinema4DClient/test_cinema4d_handler.py

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def test_set_take_not_found_raises_error(self, mock_get_doc: Mock):
8282
mock_take_a.GetChildren.return_value = []
8383

8484
mock_take_data = Mock()
85-
mock_take_data.GetCurrentTake.return_value = mock_main_take
85+
mock_take_data.GetMainTake.return_value = mock_main_take
8686
mock_main_take.GetChildren.return_value = [mock_take_a]
8787

8888
mock_doc = Mock()
@@ -109,7 +109,7 @@ def test_set_take_found_sets_take(self, mock_get_doc: Mock):
109109
mock_take_a.GetChildren.return_value = []
110110

111111
mock_take_data = Mock()
112-
mock_take_data.GetCurrentTake.return_value = mock_main_take
112+
mock_take_data.GetMainTake.return_value = mock_main_take
113113
mock_main_take.GetChildren.return_value = [mock_take_a]
114114

115115
mock_doc = Mock()
@@ -119,6 +119,50 @@ def test_set_take_found_sets_take(self, mock_get_doc: Mock):
119119
handler.set_take({"take": "A"})
120120
mock_take_data.SetCurrentTake.assert_called_once_with(mock_take_a)
121121

122+
@patch(
123+
"deadline.cinema4d_adaptor.Cinema4DClient.cinema4d_handler.c4d.documents.GetActiveDocument"
124+
)
125+
def test_set_take_from_non_parent_current_take(self, mock_get_doc: Mock):
126+
"""Verify that set_take finds and sets a take even if the active take is not an ancestor of the target take."""
127+
handler = Cinema4DHandler(mock_map_path)
128+
129+
# Hierarchy:
130+
# Main
131+
# / \
132+
# Take A Take B
133+
# |
134+
# Take A1 (current active take)
135+
mock_main_take = Mock()
136+
mock_main_take.GetName.return_value = "Main"
137+
138+
mock_take_a = Mock()
139+
mock_take_a.GetName.return_value = "Take A"
140+
141+
mock_take_a1 = Mock()
142+
mock_take_a1.GetName.return_value = "Take A1"
143+
mock_take_a1.GetChildren.return_value = []
144+
145+
mock_take_b = Mock()
146+
mock_take_b.GetName.return_value = "Take B"
147+
mock_take_b.GetChildren.return_value = []
148+
149+
mock_main_take.GetChildren.return_value = [mock_take_a, mock_take_b]
150+
mock_take_a.GetChildren.return_value = [mock_take_a1]
151+
152+
mock_take_data = Mock()
153+
# Current active take is Take A1 (which has no children)
154+
mock_take_data.GetCurrentTake.return_value = mock_take_a1
155+
# GetMainTake returns Main take, which roots the entire hierarchy
156+
mock_take_data.GetMainTake.return_value = mock_main_take
157+
158+
mock_doc = Mock()
159+
mock_doc.GetTakeData.return_value = mock_take_data
160+
mock_get_doc.return_value = mock_doc
161+
162+
# Setting take to "Take B" should succeed because search starts from GetMainTake()
163+
handler.set_take({"take": "Take B"})
164+
mock_take_data.SetCurrentTake.assert_called_once_with(mock_take_b)
165+
122166

123167
class TestShouldCacheText:
124168
"""Tests for the use_cached_text method"""

0 commit comments

Comments
 (0)