diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 9e1638cae..5808b196d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1827,6 +1827,7 @@ struct Plater::priv const Selection& get_selection() const; Selection& get_selection(); int get_selected_object_idx() const; + int get_selected_instance_idx() const; int get_selected_volume_idx() const; void selection_changed(); void object_list_changed(); @@ -2967,6 +2968,17 @@ int Plater::priv::get_selected_object_idx() const return (0 <= idx && idx < int(model.objects.size())) ? idx : -1; } +int Plater::priv::get_selected_instance_idx() const +{ + const int obj_idx = get_selected_object_idx(); + if (obj_idx >= 0) { + const int inst_idx = get_selection().get_instance_idx(); + return (0 <= inst_idx && inst_idx < int(model.objects[obj_idx]->instances.size())) ? inst_idx : -1; + } + else + return -1; +} + int Plater::priv::get_selected_volume_idx() const { auto& selection = get_selection(); @@ -6062,7 +6074,8 @@ void Plater::increase_instances(size_t num, int obj_idx/* = -1*/) } ModelObject* model_object = p->model.objects[obj_idx]; - ModelInstance* model_instance = model_object->instances.back(); + const int inst_idx = p->get_selected_instance_idx(); + ModelInstance* model_instance = (inst_idx >= 0) ? model_object->instances[inst_idx] : model_object->instances.back(); bool was_one_instance = model_object->instances.size()==1;