JOSM Scripting to gridify multiple at once

How to write a scripting code of Scripting, plugin of JOSM, to make Gridify or terracer to equally dividing into specific number of blocks, such as terraced house or parking space, on given numbers, and if variable is support, define number to divide on grid or terraces on each source object and have tgem spilt to prodefined number, in such way, how to have the predefined number on the grid

For Example, I have 100 terraced houses group outlines with 4 nodes rectangle exactly, I want divide on longer axle with a various of 3-15 houses, done at once, how to have JOSM scripting to write such code? Am I have to run each dividing number each time, or I can have a variable to complete at once and each outline have correctly divided?

Thank you

You can use AI tools to generate scripts.
See some examples:
https://wiki.openstreetmap.org/wiki/User:DressyPear4#Scripts_para_JOSM

Copy and past a few lines so it can understand the language pattern, and make simpler requests at first so it can learn.

Not exactly pure scripting: You can use Autohotkey, or Autokey, to run the button pressing on To-do list objects

(function() {
const Node = Java.type(“org.openstreetmap.josm.data.osm.Node”);
const Way = Java.type(“org.openstreetmap.josm.data.osm.Way”);
const LatLon = Java.type(“org.openstreetmap.josm.data.coor.LatLon”);
const EastNorth = Java.type(“org.openstreetmap.josm.data.coor.EastNorth”);
const MainApplication = Java.type(“org.openstreetmap.josm.gui.MainApplication”);
const ProjectionRegistry = Java.type(“org.openstreetmap.josm.data.projection.ProjectionRegistry”);
const Logging = Java.type(“org.openstreetmap.josm.tools.Logging”);

function enOf(node) { return ProjectionRegistry.getProjection().latlon2eastNorth(node.getCoor()); }
function llOf(en) { return ProjectionRegistry.getProjection().eastNorth2latlon(en); }
function sub(a, b) { return new EastNorth(a.east() - b.east(), a.north() - b.north()); }
function add(a, b) { return new EastNorth(a.east() + b.east(), a.north() + b.north()); }
function scale(v, s) { return new EastNorth(v.east() * s, v.north() * s); }
function length(v) { return Math.hypot(v.east(), v.north()); }
function normalize(v) { const L = length(v); return scale(v, 1.0 / L); }

const ds = MainApplication.getLayerManager().getEditDataSet();
if (ds == null) { Logging.info(“No active dataset.”); return; }

ds.getSelectedWays().forEach(function(way) {
const ccTag = way.get(“CC”);
if (ccTag == null) return;
let nUnits = parseInt(ccTag, 10);
if (!Number.isFinite(nUnits) || nUnits <= 0) return;
if (!way.isClosed() || way.getNodes().size() !== 5) return;
const nodes = way.getNodes().toArray();
const p0 = nodes[0], p1 = nodes[1], p3 = nodes[3];
const e0 = enOf(p0), e1 = enOf(p1), e3 = enOf(p3);
const v1 = sub(e1, e0);
const v2 = sub(e3, e0);
const L1 = length(v1), L2 = length(v2);
const longV = (L1 >= L2) ? v1 : v2;
const shortV = (L1 >= L2) ? v2 : v1;
const Llong = Math.max(L1, L2), Lshort = Math.min(L1, L2);
const uLong = normalize(longV), uShort = normalize(shortV);
const step = Llong / nUnits;
// Build grid of nodes
const bottomNodes = , topNodes = ;
for (let i = 0; i <= nUnits; i++) {
const base = add(e0, scale(uLong, i * step));
const bottomEN = base;
const topEN = add(base, scale(uShort, Lshort));
const nBottom = new Node(llOf(bottomEN));
const nTop = new Node(llOf(topEN));
ds.addPrimitive(nBottom);
ds.addPrimitive(nTop);
bottomNodes.push(nBottom);
topNodes.push(nTop);
}
// Build ways using shared nodes
for (let i = 0; i < nUnits; i++) {
const newWay = new Way();
newWay.addNode(bottomNodes[i]);
newWay.addNode(bottomNodes[i+1]);
newWay.addNode(topNodes[i+1]);
newWay.addNode(topNodes[i]);
newWay.addNode(bottomNodes[i]); // close
newWay.put(“amenity”, “parking_space”);
ds.addPrimitive(newWay);
}
Logging.info("Created " + nUnits + " parking_space blocks with shared nodes for way " + way.getId());
});
})();

This is I had get generated using Copilot, to handle the “spitting a row unit of blocks from a 4 nodes closed outline“, e.g. spilt terraced house or individual parking space (single and straight row), which number of unit pre-defined on tag so variable number of unit can be handled at once

Running with Javascript with Graaljs, need JDK 21 to run