AA

Featured products

    Popular categories

      Trending searches

        Articles

          Blog

            Products

              Categories

                Suggested searches

                  Searching…
                  No results
                  Something went wrong.
                  ↑↓ Select↵ OpenEsc Close search
                  • English
                  • Čeština
                  • Deutsch
                  • Español
                  • Français
                  • Italiano
                  • Polski
                  • 日本語
                  • Orders
                  • Address
                  • In-stock Alerts
                  • My Courses
                  • Subscription
                  • Edit Account
                  • 3D printers9+▾

                    3D printersnew

                    newPrusa CORE One L+Learn more
                    newPrusa CORE One+ (Gen 2)Learn more
                    newPrusa CORE One L+ INDX 8-ToolnewPrusa CORE One+ (Gen 2) INDX 8-ToolPrusa CORE One L+: Critical InfrastructureOriginal Prusa MK4SnewOriginal Prusa XL+Original Prusa XL+: Critical Infrastructure

                    Printer upgrades

                    newINDX Conversion KitsnewPrusa CORE One L to CORE One L+ upgradenewPrusa CORE One+ to Prusa CORE One+ (Gen 2)newPrusa XL to Prusa XL+ Upgrade
                    Prusa Reward ProgramLove your Prusa printer? Share your experience and earn $30 Prusa e-shop vouchers.
                    How to Choose a 3D Printer?We’ll walk you through the basics to find the exact machine for your space, budget, and ideas.
                    Free E-bookDownload a free e-book Basics of 3D Printing with Josef Prusa and make your first steps in 3D printing world
                    Original Prusa Printable PartsCollections of printable spare parts for Original Prusa 3D printers and upgrades.
                    Shipping informationRegularly updated info about the current manufacturing capacity and delivery times of our printers.
                    Custom 3D PrintingProfessional custom 3D printing from various materials according to your requirements.
                  • Materials▾

                    Filaments

                    PrusamentPLAPETGASA / ABSPC (Polycarbonate)PA (Nylon)FlexCompositesSpecialMaterials clearance sale

                    Resin

                    Prusament ResinResin Cleaner
                    Filament GuideCheck my Prusament Spool
                    Prusament.com
                  • Parts & Accessories▾

                    Accessories

                    EnclosuresNozzlesPrint SheetsEssential AccessoriesCameras & AddonsTools & CraftingAdhesives

                    Spare parts

                    Merchandise

                    Spare parts - All PrintersCORE OneMK4/S & MK3.9/SMK3/S/+XL
                    Merch
                  • For Business▾
                    Prusa Pro HT90Prusa Pro SLXPrusa Pro AFSPrusa Pro Medical OneOriginal Prusa XLOriginal Prusa XL: Critical Infrastructure
                    Prusa CORE One+Learn more
                    Prusa CORE One LLearn more
                    Prusa CORE One L: Critical Infrastructure Edition

                    3D Printing for

                    Manufacturing and R&DAutomotive IndustryHealthcareEducation and Academic ResearchArchitects and DesignersFilm IndustryCritical Infrastructure

                    3D Printing Stories

                    • How 3D printing started: About Rep-rap and open-source with Adrian Bowyer
                    • Teaching mathematics redefined with 3D printing at JKU Linz
                    • The story behind the LTT screwdriver
                    • Victoria Hand Project: Changing Prosthetic Care with 3D Printing
                    Official Prusa Resellers
                    Sustainability
                    Prusa Education
                    Contact and Inquiry
                    Custom 3D Printing
                    ISO Certified
                  • Software▾
                    PrusaSlicer

                    PrusaSlicerPrusaSlicer

                    PrusaSlicer is an open-source, feature-rich, frequently updated tool that contains everything you need to export the perfect print files for your 3D printer.

                    WindowsMacOSLinux
                    Prusa Connect

                    Prusa Connect

                    Prusa Connect is a cloud service enabling remote control and monitoring of your 3D printers, offering secure data handling, easy setup, and support for managing multiple printers from anywhere.

                    Log in to Connect
                    Prusa.app

                    Prusa.app

                    Control your printer/s remotely from anywhere using the Prusa Connect technology behind. Prusa.app brings a new level of Prusa printer experience to Android and iOS phones.

                    Try it now!
                    Drivers & FirmwareDownload the latest firmware and drivers for your 3D printer.
                    PrusaSlicer Support
                    Prusa Connect Support
                  • 3D Models▾
                    3D PrintersArt & DesignHobby & MakersHouseholdTabletop MiniaturesToys & GamesPrintables Store

                    Popular 3D models

                    • Strong garden hose holder
                    • Prusa Spool Bot
                    • Build Tray — Modular Organizer for Assembly, Disassembly and Maintenance
                    • Broom Holder
                    • Octagon Fabric
                    • Prusa CORE One ? (Mimic Skin)

                    Design Contests

                    • Réutilisation de la carte mère Framework Laptop 129/1/2026 – 9/30/2026
                    • 🏆 Défi du designer : Tours de magie !9/1/2026 – 9/22/2026
                    • Organisateurs de maquillage9/4/2026 – 9/20/2026
                  • Community▾

                    Upcoming Events

                    • 3D Printopia 20269/26/2026 – 9/27/2026 · Pennsylvania, United States · Prusa Team
                    • Maker Faire Bay Area9/25/2026 – 9/27/2026 · Kalifornie, United States · Prusa Team
                    • Hobby Messe10/2/2026 – 10/4/2026 · Sachsen, Germany · Prusa Team
                    • Mezinárodní strojírenský veletrh10/6/2026 – 10/9/2026 · Jihomoravský kraj, Czechia · Prusa Team

                    Prusa Forum

                    • LDC Screen Locked Up on Progress Screen during Print?
                    • Prusa slicer can't use multiple filaments with difference shrinkage rates?!
                    • Front Fan Wiring route
                    Prusa World MapPrusa World MapFind local 3D printing users and explore the community around you.
                  • Help▾
                    Guides & TutorialsPrusaSlicerPrusa ConnectMaterials

                    Printer Model

                    CORE One INDXCORE One LCORE One+CORE One

                    Hardware Troubleshooting

                    • Selftest failed (CORE One/+)
                    • Clogged nozzle (CORE One, CORE One L, XL, MK4/S, MK3.9/S)
                    • Adjusting belt tension (CORE One/+, CORE One INDX, CORE One L/+)
                    • Prusa Connect and PrusaLink explained

                    Drivers & Firmware

                    INDX familyCORE One familyMK4 familyXL familyMMU familyPRO family
                  • Courses▾

                    Become an expert in 3D printing

                    Prusa Academy offers online courses on various 3D printing related topics. Each course features:

                    • easy-to-read text with many pictures and short videos
                    • links for inspiration and further study
                    • quizzes for testing your knowledge along the way
                    • certificate of completion
                    Browse all coursesMy courses library
                    • 3D Modeling in Autodesk Fusion
                    • PrusaSlicer Masterclass – Beginner to Advanced
                    • Complete Guide to 3D Print Postprocessing, Painting, and Detailing
                    • Beginner's Guide to Blender for 3D Printing: Edit and Remix STLs
                  • Blog▾
                    • Prusament PLA ColorMix: Print 45 color shades using just five filament spools (and more)
                    • Back-to-School 2026 Deals Are Here!
                    • PrusaSlicer 3.0 Preview – Built for the Future of 3D Printing
                    E-Book: Basics of 3D Printing
                  • Company▾

                    About Prusa Research

                    We are the largest maker of 3D printers in Europe and the United States.

                    Founded as a one-man startup in 2012 by Josef Prusa, a Czech hobbyist, maker, and inventor. In just 15 years, we've grown into a company of more than 1,200 people. Every month, we design, build, and ship over 10,000 innovative and secure 3D printers from our headquarters in Prague, Czech Republic, and Delaware, USA, to users in more than 160 countries.

                    Watch a video and find out how Prusa Research was born and what we achieved within only 10 years!

                    About UsTimelineSustainabilityOpen-source
                    About Us
                    Contact Us
                    Logo and Photos
                    ISO Certified
                  1. Support
                  2. Other (PrusaSlicer)
                  3. Macros
                   

                  Contents

                  • Constructs
                  • Operators
                  • Functions
                  • Variables (placeholders)

                  Blog

                  • Prusament PLA ColorMix: Print 45 color shades using just five filament spools (and more)
                  • Back-to-School 2026 Deals Are Here!
                  • PrusaSlicer 3.0 Preview – Built for the Future of 3D Printing

                  Newsletter

                  Signup and get our monthly squeeze on updates, blog, printables and much more.

                  By clicking, you agree to receive our newsletter.

                  This site is protected by reCAPTCHA Enterprise and the Google Privacy Policy and Terms of Service apply.

                  Strong garden hose holder
                  E-shop
                  • 3D Printers
                  • Printer Upgrades
                  • Filaments
                  • Accessories
                  • Prusa Merchandise

                  © Prusa Research a.s.

                  Printables
                  • 3D Models
                  • Store
                  • Clubs
                  • 3D Design Contests
                  • Brands
                  Community
                  • World Map
                  • Forum
                  • User Groups
                  • Events
                  Help
                  • Prusa Help
                  • Prusa Academy
                  • 3D Printing Calculators
                  Software
                  • PrusaSlicer
                  • Prusa.app
                  • Prusa Connect
                  • Drivers and Software
                  Company
                  • About Us
                  • Blog
                  • Official Prusa Resellers
                  • Contact Us
                  • Certified for ISO 9001, ISO 14001, ISO 45001
                  • General Terms and Conditions
                  • General Terms and Conditions of Use of the PRUSA Websites
                  • Privacy Policy
                  • Information about cookies
                  • Customer Complaints Policy
                  • Status Page
                  • Do Not Sell or Share My Personal Information
                  • Supplemental Statements
                  • General Terms and Conditions
                  • General Terms and Conditions of Use of the PRUSA Websites
                  • Privacy Policy
                  • Information about cookies
                  • Customer Complaints Policy
                  • Status Page
                  • Do Not Sell or Share My Personal Information
                  • Supplemental Statements

                  © Prusa Research a.s.

                  JOSEF PRUSA®, PRUSA RESEARCH®, PRUSA POLYMERS®, PRUSA ORANGE®, PRUSA 3D ® AND PRUSAMENT® are registered trademarks of Prusa Development a.s. used by Prusa Research a.s. under licence from Prusa Development a.s.

                  Macros

                  Relevant for

                  MMU family
                  MINI family
                  MK3 family
                  OLD PRODUCTS
                  SLA family
                  +
                  15 comments
                  Article is also available in following languages
                  English
                  Čeština
                  Polski
                  Deutsch
                  Français
                  Español
                  Italiano
                  日本語

                  Macros allow you to create conditions and evaluate math equations in the Custom G-code fields.

                  PrusaSlicer macro language is not compatible with Slic3r conditional expressions.

                  Constructs

                  Conditional evaluation

                  Expression evaluation

                  Legacy Placeholder syntax

                  or

                  Inside either construct, PrusaSlicer configuration variables can be accessed by their names

                  and elements of vector variables can be accessed by using square braces

                  refers to the temperature of the first extruder.

                  Multidimensional vectors can currently be only accessed as a simple vector variable resulting in a string value (e.g. if the extruder_variable[1] resulting in [n,0] string value -- can be posted in g-code but can not be used in arithmetic operations).

                  Strings are identified by double quotes and regular expressions by slashes  Strings are not parsed recursively, i.e. curly and square brackets inside strings will appear in the output. This allows constructs such as

                  Operators

                  The following operators are allowed:

                  1. Comparison
                    • Example:
                  2. Boolean logic or, equivalently,  
                    • Example
                  3. Arithmetics
                    • Example: (Note that first_layer_temperature is a vector)
                  4. Ternary operator This needs to be enclosed in parentheses to work.
                    • Example: This expression sets the extruder temperature to either 230 or 200 depending on whether the first layer needs to be above 220°.
                  5. Regular expression matching
                  6. Regular expressions are enclosed in slashes /
                    • Example:

                  Functions

                  Minimum

                  Maximum

                  Casting to integer

                  Rounding to an integer

                  Rounding / padding with spaces: rounds fractional part to num_decimals digits (adding trailing zeros if needed), then left fills with spaces so the number has num_digits characters in total (including a decimal point if present). Last argument can be omitted, defaults to zero.

                  Rounding / padding with zeros: same as above, only left filled with zeros

                  Check if the configuration option is active

                   

                  Variables (placeholders)

                  You can use variables inside customs scripts and in the output file name template.

                  Check the List of all PrusaSlicer placeholders, grouped according to their scope.

                   

                  Scalar variables

                  These values are scalar and can be directly referenced.

                  • printer_notes (string)
                  • layer_z (only available in layer change GCode)
                  • layer_num (only available in layer change GCode)
                  • toolchange_z (available in custom toolchange GCode since version 2.4.0)

                  Some variables are defined by complex formulas. For example, the perimeter_extrusion_width if left to zero takes the value of extrusion_width if non zero, otherwise a default perimeter_extrusion_width is calculated for the current layer_height. These substitutions are only done for the new syntax expressions (enclosed in curly braces {}), while the expressions written using the old placeholder syntax (enclosed in square braces []) are interpreted verbatim.

                  Vector (array variables)

                  These variables are arrays and need to be accessed as such (e.g. temperature[0]).

                  • temperature
                  • first_layer_temperature
                  • bed_temperature (note that this is a vector, even though only one value makes sense: bed_temperature[0])
                  • first_layer_bed_temperature (same as above!)

                  Multidimensional vector

                  These variables can only be accessed as simple vectors and can not be used in arithmetic expressions.

                  • extruder_offset
                  • bed_shape

                  Examples

                  Temp tower

                  You can use the "Before layer change" custom G-code to slowly decrease hot end temperatures. First, one may use the if/elsif/else expression:

                   The same result may be achieved by a shorter if/else/endif expression together with a linear interpolation:

                  Or one may use the ternary operator:

                  Faster heat up with weak bed heaters before print

                  If you have a bed that takes a very long time to get up to temperature you can shave off a little bit of waiting time by using "Start G-code" to heat up the bed to the destination temperature minus 5 degrees and then starting to warm up the hot end while the bed continues to heat to the target value:

                   

                  Was this article helpful?
                  This action is available only to registered users. Please log-in.

                  Topics

                  • PrusaSlicer 2.9 (Legacy)
                    • Other (PrusaSlicer)
                      • 3Dconnexion devices
                      • Sending files to Octoprint/Duet
                      • Macros
                      • Export toolpaths as OBJ
                      • PrusaSlicer G-code viewer
                      • List of placeholders
                      • How to lift object from the print bed
                      • Opening models in PrusaSlicer from supported websites
                    • About PrusaSlicer
                    • Configuration and profiles
                    • User interface
                    • Input/output
                    • Left toolbar
                    • Top toolbar
                    • Print settings
                    • Filament settings
                    • Printer settings
                    • Advanced features
                    • Multi-material slicing
                    • SLA slicing

                  11 comments

                  Log in  to post a comment
                  jep17
                  •
                  Is there any way to call an external script with each layer change?
                  Reply
                  RyanC
                  •
                  For those wondering, you can use modulus / mod with macros by utilizing the percent % symbol.
                  E.g., to perform something every N layers:
                  {if layer_num % N == 0}; something{endif}
                  Reply
                  nivekmai
                  •
                  Now that custom variables are supported (since 2.6, see https://github.com/prusa3d/PrusaSlicer/commit/c28585ab7fa62a56a1f188284b8bf782b734003f), could you please update this page with references on how to use them? Some example gcode would be nice, e.g.:{local myBoolean = true}{local myXVariable = 200}{local myYVariable = 100}{if myBoolean == true}G0 X{myXVariable} Y{myYVariable}{endif}--edit-- The editor doesn't let me get good formatting, code should be each line separately
                  Reply
                  J
                  •
                  bed_temperature: "(note that this is a vector, even though only one value makes sense" This is misleading. The bed_temperature vector contains print temps per loaded filament. Also many of the variables on this page are missing on the placeholders page, that made setting up macros quite frustrating
                  Reply
                  MartinD
                  •
                  Can I ask for a clarification? 
                  The if/elseif/else expression - is the spelling of the command correct in this article, that is, is the elseif command spelled "elsif" without the "e"?
                  Reply