diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 167a7987a7..e91a8e46d0 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -729,6 +729,9 @@ static std::vector get_path_of_change_filament(const Print& print) gcode += gcodegen.writer().unlift(); // Make sure there is no z-hop (in most cases, there isn't). double current_z = gcodegen.writer().get_position().z(); + gcode += gcodegen.writer().travel_to_z(current_z); + + if (z == -1.) // in case no specific z was provided, print at current_z pos z = current_z; @@ -4516,10 +4519,8 @@ std::string GCode::change_layer(coordf_t print_z) comment << "move to next layer (" << m_layer_index << ")"; gcode += m_writer.travel_to_z(z, comment.str()); } - else { - //BBS: set m_need_change_layer_lift_z to be true so that z lift can be done in travel_to() function - m_need_change_layer_lift_z = true; - } + + m_need_change_layer_lift_z = true; m_writer.get_position().z() = z; @@ -6036,6 +6037,11 @@ std::string GCode::travel_to(const Point& point, ExtrusionRole role, std::string } this->set_last_pos(travel.points.back()); } + if (m_need_change_layer_lift_z) { + gcode += m_writer._travel_to_z(m_writer.get_position().z(), comment + " travel_to_z"); + m_need_change_layer_lift_z = false; + } + return gcode; } diff --git a/src/libslic3r/GCodeWriter.hpp b/src/libslic3r/GCodeWriter.hpp index 5e5182014e..78c93cb92e 100644 --- a/src/libslic3r/GCodeWriter.hpp +++ b/src/libslic3r/GCodeWriter.hpp @@ -119,6 +119,7 @@ public: // Returns whether this flavor supports separate print and travel acceleration. static bool supports_separate_travel_acceleration(GCodeFlavor flavor); + std::string _travel_to_z(double z, const std::string &comment); private: // Extruders are sorted by their ID, so that binary search is possible. std::vector m_extruders; @@ -172,7 +173,6 @@ public: Print }; - std::string _travel_to_z(double z, const std::string &comment); std::string _spiral_travel_to_z(double z, const Vec2d &ij_offset, const std::string &comment); std::string _retract(double length, double restart_extra, const std::string &comment); std::string set_acceleration_internal(Acceleration type, unsigned int acceleration);