Skip to content

Commit 5f20557

Browse files
committed
ouput tree object is no longer the active object
1 parent 44ad9ce commit 5f20557

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

python_classes/nodes/tree_function_nodes/tree_mesher_node.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class TreeMesherNode(bpy.types.Node, MtreeNode):
1313

1414
radial_resolution : bpy.props.IntProperty(name="Radial Resolution", default=32, min=3, update=on_update_prop)
1515
smoothness : bpy.props.IntProperty(name="smoothness", default=4, min=0, update=on_update_prop)
16+
tree_object : bpy.props.StringProperty(default="")
1617

1718
def init(self, context):
1819
self.add_output("mt_TreeSocket", "Tree", is_property=False)
@@ -24,19 +25,28 @@ def draw_generate(self, container):
2425
properties.function_name = "build_tree"
2526

2627

28+
def has_valid_tree_object(self):
29+
return bpy.context.scene.objects.get(self.tree_object, None) is not None
30+
31+
2732
def draw_properties(self, container):
2833
container.prop(self, "radial_resolution")
2934
container.prop(self, "smoothness")
3035

3136
def draw_distribute_leaves(self, container):
32-
properties = container.operator("mtree.add_leaves", text="Add leaves")
33-
properties.object_id = self.get_current_tree_object().name
37+
if self.has_valid_tree_object():
38+
properties = container.operator("mtree.add_leaves", text="Add leaves")
39+
properties.object_id = self.get_current_tree_object().name
40+
41+
def draw_current_tree_object(self, container, context):
42+
container.prop_search(self, property="tree_object", search_data=context.scene, search_property="objects", text="")
3443

3544
def draw(self, context, layout):
3645
valid_tree = self.get_tree_validity()
3746
generate_row = layout.row()
3847
generate_row.enabled = valid_tree
3948
self.draw_generate(generate_row)
49+
self.draw_current_tree_object(layout, context)
4050
self.draw_properties(layout)
4151
leaves_row = layout.row()
4252
leaves_row.enabled = valid_tree
@@ -60,11 +70,14 @@ def mesh_tree(self, tree):
6070
return mesh_data
6171

6272
def get_current_tree_object(self):
63-
tree_obj = bpy.context.object
73+
tree_obj = bpy.context.scene.objects.get(self.tree_object, None)
6474
if tree_obj is None:
6575
tree_mesh = bpy.data.meshes.new('tree')
6676
tree_obj = bpy.data.objects.new("tree", tree_mesh)
6777
bpy.context.collection.objects.link(tree_obj)
78+
self.tree_object = tree_obj.name
79+
bpy.context.view_layer.objects.active = tree_obj
80+
tree_obj.select_set(True)
6881
return tree_obj
6982

7083
def output_object(self, cp_mesh):

0 commit comments

Comments
 (0)