Changing tag for anonymous layer?

I’ve got an anonymous layer with an identifier like anon:0x1e390940:foo and I’d like to change it to anon:0x1e390940:bar.

My code and the returned error

anon = Sdf.Layer.CreateAnonymous("foo")
# some stuff
path = anon.identifier.rsplit(":", 1)[0]
anon.identifier = path + ":bar"

Error in 'pxrInternal_v0_23__pxrReserved__::SdfLayer::SetIdentifier' at line 2464 in file /opt/USD/pxr/usd/sdf/layer.cpp : 'Cannot change identifier to anon:0x55d54d1419c0:bar': cannot use anonymous layer identifier.'

So, how do I modify a tag for an anonymous since it doesn’t let me assign an anon identifier?

Hi @Kevin ! I am honestly not thrilled that we publicly expose the ability to change any open layer’s identifier (because it’s a gun pointed at your foot to orphan references and sublayers in your scene), and need to dig into the history of why we need to allow it. But it looks like we do prevent you from changing an anonymous layer’s identifier to a different anonymous identifier which, admittedly, is inconsistent with the behavior for asset-based layers.

So unfortunately there is no way currently to do what you want.

Thanks @spiff, I can see why it’s dangerous to change identifier, and honestly I don’t really like that to change tags you need to do it together with the identifier.
Maybe separating the two operations could help avoiding “shooting at your own foot”.

Any insights if changing tags for anons is a thing that may be possible in the near future? Do you suggest me to open an issue on github?

Hmmm… as currently formulated, “tags” are really inseparable from identifiers. Could you explain more about what your use of tags is? I’m wondering if customLayerData gives you all the flexibility you might require in categorizing/organizing layers?

The DCC I’m using (Maya) puts the tag as “layer name” in the Layer Editor.
The default root layer is an anonymous with identifier anon:<memorypath>:anonymousLayer1 which I’d like to change for final UX.

I’m creating the stage through MayaUsd that doesn’t let me specify an identifier for root anon

It kind of sounds like you solely want to hide the tag from an end-user perspective for readability purposes? Wouldn’t you be able to just ‘tweak’ the name for your UIs instead?

Changing the identifiers while Maya code might rely on the names to stay consistent might be a whole other level of dangerous?

Could you elaborate more on why you’d want to change the tags in this instance?

I’ve got two stages, whose composition arcs are almost the same; one is the preview_stage, while the other is the working_stage.

Based on user interaction, the visible stage in the USD Layer Editor will change, but it’s hard for the user which one it is:

If instead of “anonymousLayer1” I had “PREVIEW” it would be better.
But besides my use case, I think it would be good to have the ability to change an anonymous layer’s tag anyway

Thanks for the context, @Kevin . It might be worth starting a discussion about this on the Autodesk UsdMaya forums… I doubt you are the only folks who desire to name their “in memory stages” instead of relying on auto-generated layer-names; and if there isn’t currently a way to do that, it would be a desirable feature? If you are able to name the stage appropriately up-front, that doesn’t seem like a huge lift, and definitely “safer” than renaming the layer.

That said, it is inconsistent in our API’s that you can set the identifier for a non-anonynmous layer, but not for an anonymous one, and if someone wants to submit a PR to relax that, we’d definitely consider it.