# Generate Bounding Box as a Subprogramm

**URL:** <https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282>\
**Category:** Uncategorized\
**Created:** [May 25, 2024, 7:48pm UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282 "2024-05-25T19:48:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![enhydra](https://forum.grid.space/user_avatar/forum.grid.space/enhydra/32/1000_2.png) [@enhydra](https://forum.grid.space/u/enhydra)\
**Post date:** [May 25, 2024, 7:48pm UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282/1 "2024-05-25T19:48:57Z")

</div>

![bb](https://forum.grid.space/uploads/default/original/2X/9/9bfdfc532165fcb8b6a5ee58bbfc4dfcb29c32c2.png)

Since the controller of our China CNC does not have a function to generate the bounding box from the loaded gcode, I wrote a small web application that does exactly that: [Bounding Box](https://3km.ch/boundingbox/)

Today I had the idea that Kiri could easily generate it and embed it into the nc-file. Have you already done such a function or can you point me in this direction?

---

<div class="post-metadata">

**Author:** ![enhydra](https://forum.grid.space/user_avatar/forum.grid.space/enhydra/32/1000_2.png) [@enhydra](https://forum.grid.space/u/enhydra)\
**Post date:** [May 25, 2024, 7:54pm UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282/2 "2024-05-25T19:54:08Z")

</div>

CNC.js offers such a function:

```auto
G90
G0 Z10 ; go to z-safe
G0 X[xmin] Y[ymin]
G0 X[xmax]
G0 Y[ymax]
G0 X[xmin]
G0 Y[ymin]

```

---

<div class="post-metadata">

**Author:** ![stewart](https://forum.grid.space/user_avatar/forum.grid.space/stewart/32/21_2.png) [@stewart](https://forum.grid.space/u/stewart)\
**Post date:** [May 26, 2024, 12:56am UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282/3 "2024-05-26T00:56:16Z")

</div>

Kiri has these vars internally. I could surface them in the [gcode macro vars](https://docs.grid.space/projects/kiri-moto/gcode-macros) and then you could add that to your device header.

---

<div class="post-metadata">

**Author:** ![enhydra](https://forum.grid.space/user_avatar/forum.grid.space/enhydra/32/1000_2.png) [@enhydra](https://forum.grid.space/u/enhydra)\
**Post date:** [May 26, 2024, 3:37pm UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282/4 "2024-05-26T15:37:41Z")

</div>

Thank you for your reply. I’ll check how the machine handles macros and subroutines. I’ll let you know when I have some news. 🙂

---

<div class="post-metadata">

**Author:** ![stewart](https://forum.grid.space/user_avatar/forum.grid.space/stewart/32/21_2.png) [@stewart](https://forum.grid.space/u/stewart)\
**Post date:** [May 26, 2024, 4:12pm UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282/5 "2024-05-26T16:12:57Z")

</div>

to be clear, this will require some changes on my part. I’m in the middle of some refactoring, so it could be a couple of weeks.

---

<div class="post-metadata">

**Author:** ![enhydra](https://forum.grid.space/user_avatar/forum.grid.space/enhydra/32/1000_2.png) [@enhydra](https://forum.grid.space/u/enhydra)\
**Post date:** [May 26, 2024, 7:49pm UTC](https://forum.grid.space/t/generate-bounding-box-as-a-subprogramm/1282/6 "2024-05-26T19:49:05Z")

</div>

That’s fine for me. As I mentioned, I have a workaround with my webapp. So there is no hurry. 😉
