Skip to content

Conversation

@wjcarpenter
Copy link
Contributor

@wjcarpenter wjcarpenter commented Jan 25, 2026

Introduces fragment {color(green)} to be able to make color changes within a label spec. See COLOR_NOTES.md for details and examples. The ColorFragment class is a subclass of ModifierFragment. A ModifierFragment is not itself rendered in any way. Instead, it modifies the rendering of fragments that follow it on a line.

CAD labels are applied to all nodes in the CAD model hierarchy. Unnecessary nodes (those with only a single child) are squeezed out of the model. The idea is to allow precise and meaningful selection in outside tools that can deal with CAD model assemblies.

Coloring and CAD model labels are exported in STEP files, SVG files, and VSCode viewing. There is a command line option to do SVG in monochrome.

Reworks the software layering to extrude Parts at the lowest level instead of at the highest level.

Re-implements the command line scaling options in a way that preserves in a way that preserves colors and CAD model labels.

Many other small changes.

WJCarpenter and others added 30 commits January 8, 2026 13:58
This is useful not only for better visualizing, but it can help with
selecting things when importing into a slicer or other tool for further
manipulation.

For example, if you create a STEP file and convert it to a OBJ file
(with any convenient converter tool), you can add the OBJ file to Bambu
Studio, at which point Bambu Studio prompts you to map the colors in
the OBJ file to filament colors. (Unfortunately, Bambu Studio doesn't
preserve colors on STL, STEP, nor 3MF files at the moment. Maybe someday.)
adds a sketch for T-slot nuts
implement overall scale factors for when you need a little nudge to m…
…respectively

This is useful not only for better visualizing, but it can help with selecting things when importing into a slicer or other tool for further manipulation.

For example, if you create a STEP file and convert it to a OBJ file (with any convenient converter tool), you can add the OBJ file to Bambu Studio, at which point Bambu Studio prompts you to map the colors in the OBJ file to filament colors. (Unfortunately, Bambu Studio doesn't preserve colors on STL, STEP, nor 3MF files at the moment. Maybe someday.)

Partial help for issue ndevenish#19
Solution for issue #9

I discovered that this online STEP converter creates 3MF files that Bambu Studio likes (and preserves colors if the STEP file has them):

https://convert3d.org/step-to-3mf/app

A workflow could be:

  - create STEP file via gflabel, either with the default colors or your own choices for base color and label color
  - use that converter to convert the STEP file to 3MF
  - add the 3MF into Bambu Studio; you'll see the colors in the prepare tab
  - slice the plate
  - when you print the plate, Bambu studio will try to pick filaments for each color, but you can also pick whichever filaments you prefer before actually sending it to the printer

This workflow is less tedious than splitting the model to parts or objects and assigning filaments manually.

-----------------

(Sorry about the extra commits on this branch and PR. I had a few independent
changes in separate branches and accidentally combined all of them into
this branch. I took the shortest path get thingws back to where they should
have been.)
You can change colors with a label. See COLOR_NOTES.md for details.

In this implementation, the colors are tracked "on the side"
(that is, outside of the build123d hierarchy. As far as I have
been able to figure out, build123d "forgets" the colors as the
sketches are built up.

The original top-level "label_sketch" is still created, but it's
not used for output file export or for VScode rendering. Instead,
the on-the-side bookkeeping is used. Perhaps someday we'll be able
to track the colors directly in the build123d hierarchy, at which
point the on-the-side bookkeeping can be dropped.
Add images for examples
cut/paste glitch
The new fragment type ColorFragment ({color(red)}) is introduced.  It
changes the color of subsequent fragments until the end of the line or
another ColorFragment is seen. Exported STEP and SVG files, and VScode
renders preserve those colorings (though there is a new --svg-mono
command line option to preserve the old behavior).

A couple of changes as a side effect of implementing the above:

1. (fairly major) Labels are now created as a hierarchy of
Compound objects instead of sketches. Things are labelled at
each level, so hypotherically a tool looking at a STEP, STL, or SVG
could navigate through the layers. (My experiments find little
support fot his in those other tools, though FreeCAD seems to grok
it pretty well.)

2. (minor) ModifierFragment is a subclass of Fragment, meant
for things like the ColorFragment class. These things act on
other fragments instead of being rendered themselves.
The previous x/y/z scaling options were easily implemented. Just
call a single build123d scale operation on the overall assembly.
Unfortunately, build123d considers that a "CAD operation" and so
creates all new objects in the assembly, losing the label and
color attributes in the process.

This revised implementation takes a different approach. It pre-scales
the dimensions of the base (including margin) as well as any command
line specs of width, height, depth, and margin.  The excellent
existing dynamic scaling of the gflabel code takes care of everything
else.

Note: If you use label divisions ({|}) with scaling, you may get
some surprises. Each division is scaled and rendered independently.
That was always the case, but x/y scaling can make it more obvious.
My advice is to use trial and error to get what you want.
@ndevenish
Copy link
Owner

outside tools that can deal with CAD model assemblies

Do you know such tools? I spent a little time trying to work out how to export 3mf with the right tags to have colouring pre-selected, but basically hit all kinds of dead-ends with the format being very loose..

@wjcarpenter
Copy link
Contributor Author

Do you know such tools?

It's challenging, but I found that FreeCAD keeps the colors in a STEP file. I also found that the web site convert3d.org does a good job of converting a STEP file to an OBJ or a 3MF. For both of those converted files, Bambu Studio notices the colors when you open them. (Which it doesn't do for a 3MF file from most other places or from the original STEP file. I don't know the details of that, but I guess the people at convert3d.org do and add whatever special sauce to make it work.)

@wjcarpenter
Copy link
Contributor Author

wjcarpenter commented Jan 25, 2026

FreeCAD example

gflabel tailorbox -w=5 "M3 {|} Bolts Nuts\nWashers\n{color(green)}{hexhead(hex)} {hexhead(torx)} {nut} {washer}"
image

@Paulomart
Copy link

Paulomart commented Jan 28, 2026

It's challenging, but I found that FreeCAD keeps the colors in a STEP file. I also found that the web site convert3d.org does a good job of converting a STEP file to an OBJ or a 3MF. For both of those converted files, Bambu Studio notices the colors when you open them. (Which it doesn't do for a 3MF file from most other places or from the original STEP file. I don't know the details of that, but I guess the people at convert3d.org do and add whatever special sauce to make it work.)

It seems that BambuStudio v2.5.0 introduced Standard 3MF color parsing support [1]. If a tool would generate a valid 3mf file according to the spec, it should be possible to import the colors now.

build123d also supports exporting color information in 3mf files, so maybe using an external converter would not be necessary, if exporting to 3mf would be implemented.

@wjcarpenter
Copy link
Contributor Author

It seems that BambuStudio v2.5.0 introduced Standard 3MF color parsing support

That is pretty great news. I was looking around for a color 3MF that wasn't produced by Bambu Studio, but didn't come across one before my patience ran out. Have you had a chance to try it with a non-BBS color 3MF?

build123d also supports exporting color information in 3mf files

It looks like it's a bit more involved than just calling export_3mf(assembly), but at a glance I don't have a feel for how much more involved. @ndevenish do you have any plans to add 3MF export?

@Paulomart
Copy link

Paulomart commented Jan 28, 2026

Sadly I have not tried any of the new features regarding 3mf. I think the best way forward is to implement 3mf exporting in gflabel and then try to import it. If I get around to implementing it I will pr the changes to your repo.

WJCarpenter and others added 3 commits January 28, 2026 12:26
These key-=value arguments are more intuitive than the previous
pairwise arguments. Example: {scale(x=2, y=0.5)}.
Text fragments are normally rendered as a single build123d Part.
With this option, build123d still creates the single Sketch, but
the resulting Faces are extruded to Parts individually. They
are given Part labels that might make them easier to select in
an external tool. The process of affiliating a character of the
text fragment with a particular Face is not exact because some
characters can render into multiple Faces, and the space character
renders into no Faces. The Faces still get Part labels, but they
may be less helpful or even confusing in some edge cases.

The reason to let build123d create the Sketch of the entire
text fragment is so that it does proper font spacing and other
tricks. A more complete technique for the --text-as-parts option
would render each character to a Sketch individually in order to
count the Faces for that character. Then use that info to label
the Parts. There's still no guarantee that build123d will return
a Sketch with the Faces in character order. (In fact, we have
observed that for some reason the first face corresponds last.
We take that into account, but if that last character produced
multiple Faces, we'd still be wrong in our workaround.)
@Paulomart
Copy link

@wjcarpenter I just got a basic version of the colored 3mf export working. Created a PR here: github.com/wjcarpenter/pull/14/

WJCarpenter and others added 13 commits January 29, 2026 10:09
The type hint for the render() function is changed from Sketch to
Compound. (Compound is the superclass of Sketch.) A fragment can
continue to return the simple sketch, or it can return a Compound
with children. If there are children, each should be a 2D shape of
some kind, and each is extruded to a Part separately.

If the children have color or label attributes, they are respected.

The implementation of --text-as-parts is moved into the TextFragment
render() function and returns a Compound with children, each with
its own label.
Colored 3mf export using lib3mf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants