Skip to content

Instantly share code, notes, and snippets.

@timolaine
Created November 5, 2025 12:56
Show Gist options
  • Select an option

  • Save timolaine/01d9619b89a2f9aed5a99d94f523759e to your computer and use it in GitHub Desktop.

Select an option

Save timolaine/01d9619b89a2f9aed5a99d94f523759e to your computer and use it in GitHub Desktop.
Add consecutive ID to selection in #jArchi
/*
* Add consecutive ID to selection
* (c) 2025 Timo Laine www.timoroso.com
*/
console.log("Add consecutive ID to selection");
var propName = window.prompt("To which property do you want to add a consecutive ID for selected elements or relations? (leave empty to cancel)?", "");
if (propName) {
var initialValue = window.prompt("Which value do you want to set for the initial value (leave empty to cancel)?", "0");
if (initialValue) {
var idlength = $(selection).size().toString().length;
var propValue = Number(initialValue);
$(selection).each(function(sel) {
var propString = propValue.toString();
while (propString.length < idlength) {
propString = "0" + propString;
}
sel.prop(propName, propString);
propValue = propValue + 1;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment