Reorder custom blocks within palette

Though this subject was discussed before - a.o. in a long-standing feature request - I’m raising it again: not as a feature request but as a request to the community: can we write code, using current Snap! features, to have custom blocks rearranged within a palette? The immediate trigger for me is I’m trying to rearrange a set of blocks for a library.

The order of custom blocks within a palette is apparently determined by the order (in time) in which they were created. My proposed basic approach to rearranging them would be:

  1. Make a list of the blocks to be reordered, in the desired order (block #1 may be skipped);
  2. Generate an unused block name (make sure it’s not used for a hidden block either, a/o for a block confined to another sprite within the project?);
  3. Create a new block with the unused name, and the definition of the original block (i.e. first block on the list), using untitled script pic 232, and untitled script pic 234;
  4. Copy all other properties of the list block to the new block, using the likes of untitled script pic 235, and untitled script pic 236;
  5. Find all blocks and scripts calling the original block; I wonder if scripts and blocks from other sprites within the project need to be included? and the new block itself?
  6. Replace each call to the original block with a call to the new block;
  7. Delete the original block, using untitled script pic 237;
  8. Rename the new block to the old name, using untitled script pic 233;
  9. Repeat steps 2+ for the next block in the list.

Request for help
Did anyone ever try building such tool? If it worked out: may I borrow it? If not: what works? and what are the remaining challenges?
And even if you did not try, do you have any suggestions?

Thx in advance!

That's a lot of hassle...

But in version 10 we already have that:
Screenshot 2024-03-24 035306

But that technique is still good for reordering, just very difficult :dizzy:.
But for me:

  1. Export chosen blocks.
  2. Delete the chosen blocks.
  3. Re-import the exported blocks.

For me that's much easier to do. It's not easy to rearrange blocks using code :dizzy_face:

I love this idea (even if Snap! 10 has basic reordering capabilities already). My biggest trouble with coding it is that I don't know how to edit existing standalone scripts? Changing the definition for a block is no problem but I don't know how to replace a standalone script with a new one. Or replace all the standalone scripts in a sprite at once (ala "set (scripts of another sprite) to (new scripts)"). This is a pretty basic thing to get stuck on so I'm hoping that someone knows if and how it's possible to programmatically edit (or add or remove) standalone scripts in a sprite.

Welcome to the forum, qzne!
AFAIK, no. It's not possible to edit standalone scripts in a sprite using code. It must be done manually.

Dardoro made this:
add move to the top and more functionality

after running the block: