discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

Align text with import

ME
Mark Erbaugh
Sat, Apr 18, 2026 2:13 PM

The model has a multi-color background imported from a SVG file and text specified in OpenSCAD. Is there a way to programmaticly align the two?

The text can be centered using the halign and valign options.

The SVG file contains one item for each color. Each is imported using the id option.

The center option of import can't be used as each of the different colored items are different sizes.

One thing that works is to render just the SVG file and copy the bounding box coordinates displayed in the console to the model code and use that. The downside is that the process has to be repeated if the SVG file is changed.

Recent versions of OpenSCAD have added the textmetrics function that can be used to calculate the bounding box of text. Are there any plans to add something similar for import? Or is there already a way to do this?

Thanks,
Mark

The model has a multi-color background imported from a SVG file and text specified in OpenSCAD. Is there a way to programmaticly align the two? The text can be centered using the halign and valign options. The SVG file contains one item for each color. Each is imported using the id option. The center option of import can't be used as each of the different colored items are different sizes. One thing that works is to render just the SVG file and copy the bounding box coordinates displayed in the console to the model code and use that. The downside is that the process has to be repeated if the SVG file is changed. Recent versions of OpenSCAD have added the textmetrics function that can be used to calculate the bounding box of text. Are there any plans to add something similar for import? Or is there already a way to do this? Thanks, Mark
JB
Jordan Brown
Sat, Apr 18, 2026 2:37 PM

On 4/18/2026 7:13 AM, Mark Erbaugh via Discuss wrote:

The model has a multi-color background imported from a SVG file and text specified in OpenSCAD. Is there a way to programmaticly align the two?

No.

Recent versions of OpenSCAD have added the textmetrics function that can be used to calculate the bounding box of text. Are there any plans to add something similar for import? Or is there already a way to do this?

We've talked about having a way to extract information from an import,
but nobody has been interested enough to implement it.  One could also
imagine import-centering options that would help - not just centering
the selected layer/object but centering based on the full SVG.  But
again it requires somebody (actually, a couple of somebodies, given the
need for review) who have the interest and time.

PR #4478 has a general solution to the problem, but stalled for lack of
time for people to review it.  (And at this point would require
non-trivial work to revive.)

On 4/18/2026 7:13 AM, Mark Erbaugh via Discuss wrote: > The model has a multi-color background imported from a SVG file and text specified in OpenSCAD. Is there a way to programmaticly align the two? No. > Recent versions of OpenSCAD have added the textmetrics function that can be used to calculate the bounding box of text. Are there any plans to add something similar for import? Or is there already a way to do this? We've talked about having a way to extract information from an import, but nobody has been interested enough to implement it.  One could also imagine import-centering options that would help - not just centering the selected layer/object but centering based on the full SVG.  But again it requires somebody (actually, a couple of somebodies, given the need for review) who have the interest and time. PR #4478 has a general solution to the problem, but stalled for lack of time for people to review it.  (And at this point would require non-trivial work to revive.)