How to prevent text-layer auto-renaming, when renaming via API?

This happens on Mac, Sketch v2025.2.2.

I’m depending on specific names of my Text Layers, for localization and automation purposes, via in-house plugin code.

But if I edit the text on a Text Layer and make some words bold (for example), the Text Layer gets automatically renamed (to match the beginning of the text on the Layer).

This is wreaking havoc with my document structure - how can I disable this automatic renaming?

EDIT: See clarification below, my issue arises because I have renamed a lot of (previously unrenamed) layers programmatically via plugin script. I now want to find out how to set (by Sketch API) the same option/flag as when renaming manually, to prevent future auto-renaming when editing the plugin-renamed layer!

1 Like

Hey Göran,

You can avoid this by renaming the layer on the layer list and then editing the layer’s text.

Thanks, this fixes the problem “locally”. However, I’m developing my own plugin and have used it to already rename a lot of layers “programatically”.

Apparently, manually changing the Layer name sets some option/flag on the Layer to prevent automatic renaming, but that does not happen when I rename the Layer via API.

For my workflow to become robust, I would need to be able to set this option/flag by plugin script, to make sure future manual edits will not unexpectedly change the Layer names.

Please advice, how I can access this setting by API… :wink:

NOTE: I’m fine with achieving this via .sketchObject etc, if I can just get a hint of where to look!

If you’re looking for integrations and plugins advice, I recommend using the Plugins and integrations category.

I’ve changed this post’s category to that

1 Like

Thanks! I reworded the post’s title to reflect my follow-up question…

1 Like

Thanks Göran! :raising_hands:

Hey there!

I believe the property you’re looking for is called nameIsFixed, which is unfortunately not supported by the JS API, but you may indeed access it via sketchObject like this:

textLayer.name = 'this name should stay as is'
textLayer.sketchObject.setNameIsFixed(true)
textLayer.text = 'modified text'
2 Likes

Thanks a lot! I was able to solve my issue using this function:

function setLayerNameFixed(layer)
{
  msLayer = layer.sketchObject
  if (!msLayer.nameIsFixed())
    msLayer.setNameIsFixed(true)
}
1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.