# Example: Search Printer Objects

**URL:** <https://klipper.discourse.group/t/example-search-printer-objects/164>\
**Category:** Macros\
**Created:** [April 20, 2021, 3:03am UTC](https://klipper.discourse.group/t/example-search-printer-objects/164 "2021-04-20T03:03:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mental](https://yyz2.discourse-cdn.com/free1/user_avatar/klipper.discourse.group/mental/32/11_2.png) [@mental](https://klipper.discourse.group/u/mental)\
**Post date:** [April 20, 2021, 3:03am UTC](https://klipper.discourse.group/t/example-search-printer-objects/164/1 "2021-04-20T03:03:40Z")

</div>

This macro will allow you to type `SEARCH_VARS S={some word}` from the terminal and  
it will respond with all of the matching items in the `printer` object.

Say I wanted to know what the name and path of for the value of the currently loaded bed  
mesh. I could do type `search_vars s=profile` in my terminal and it will respond with  
any items containing the word ‘profile’.

```auto
$ SEARCH_VARS s="profile"
// printer.bed_mesh.profile_name : default

```

Additionally, omitting the “s” parameter will just dump out literally everything and probably catch fire.  
You have been warned.

```auto
[gcode_macro SEARCH_VARS]
gcode:
    {% set search = params.S|lower %}
    {% set ns = namespace() %}
    {% for item in printer %}
        {% if ' ' in item %}
            {% set ns.path = ['printer', "['%s']" % (item), ''] %}
        {% else %}
            {% set ns.path = ['printer.', item, ''] %}   
        {% endif %} 

        {% if search in ns.path|lower %}
            { action_respond_info(ns.path|join) }
        {% endif %} 

        {% if printer[item].items() %}
            {% for childkey, child in printer[item].items() recursive %}
                {% set ns.path = ns.path[:loop.depth|int + 1] %}

                {% if ' ' in childkey %}
                    {% set null = ns.path.append("['%s']" % (childkey)) %}
                {% else %}
                    {% set null = ns.path.append(".%s" % (childkey)) %}
                {% endif %} 

                {% if child is mapping %}
                    { loop(child.items()) }
                {% else %}
                    {% if search in ns.path|lower %}
                        { action_respond_info("%s : %s" % (ns.path|join, child)) }   
                    {% endif %} 
                {% endif %} 
                
            {% endfor %}
        {% endif %} 
    {% endfor %}

```

---

<div class="post-metadata">

**Author:** ![trxgt05](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@trxgt05](https://klipper.discourse.group/u/trxgt05)\
**Post date:** [June 6, 2024, 3:49pm UTC](https://klipper.discourse.group/t/example-search-printer-objects/164/2 "2024-06-06T15:49:54Z")

</div>

I know this is really old, but I think it is close to what I need for something I’m working on. See:  
[Indirectly indexing through extruder objects - General Discussion - Klipper](https://klipper.discourse.group/t/indirectly-indexing-through-extruder-objects/16869)

It makes sense somewhat (I’m still a novice) that what I was trying to do is different from how you can do macros because this involves paths. It looks like this could be what I need to build the path, but I think the last piece I need to figure out is how do I capture the value that the path references.

So say I had something like below. What would I put where the ???s are to pull the value that the ns.path|join references? i.e. the value of printer.extruder1.temperature

```auto
[gcode_macro test]
variable_temp: 0
variable_ext: "extruder1"
gcode:
    {% set ns = namespace() %}
    {% set ns.path = ['printer.', ext, 'temperature'] %}

    SET_GCODE_VARIABLE MACRO=test VARIABLE=temp VALUE=???

```

---

<div class="post-metadata">

**Author:** ![trxgt05](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@trxgt05](https://klipper.discourse.group/u/trxgt05)\
**Post date:** [June 6, 2024, 4:58pm UTC](https://klipper.discourse.group/t/example-search-printer-objects/164/3 "2024-06-06T16:58:25Z")

</div>

Well I found what I needed and it actually had nothing to do with paths. See the solution of my post linked above.

---

<div class="post-metadata">

**Author:** ![LupusTheCanine](https://avatars.discourse-cdn.com/v4/letter/l/c0e974/32.png) [@LupusTheCanine](https://klipper.discourse.group/u/LupusTheCanine)\
**Post date:** [December 28, 2025, 11:04pm UTC](https://klipper.discourse.group/t/example-search-printer-objects/164/4 "2025-12-28T23:04:35Z")

</div>

Hi, I tried to dump the printer variable (for science 😅 ) but it fails on this very macro

```auto
Error evaluating 'gcode_macro SEARCH_VARS:gcode': TypeError: argument of type 'int' is not iterable
Traceback (most recent call last):
  File "/home/biqu/klipper/klippy/extras/gcode_macro.py", line 70, in render
    return str(self.template.render(context))
  File "/home/biqu/klippy-env/lib/python3.9/site-packages/jinja2/environment.py", line 1090, in render
    self.environment.handle_exception()
  File "/home/biqu/klippy-env/lib/python3.9/site-packages/jinja2/environment.py", line 832, in handle_exception
    reraise(*rewrite_traceback_stack(source=source))
  File "/home/biqu/klippy-env/lib/python3.9/site-packages/jinja2/_compat.py", line 28, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 16, in top-level template code
  File "<template>", line 26, in template
  File "<template>", line 19, in template
TypeError: argument of type 'int' is not iterable
Error evaluating 'gcode_macro SEARCH_VARS:gcode': TypeError: argument of type 'int' is not iterable

```
