control_after_generate - chrisgoringe/Comfy-Custom-Node-How-To GitHub Wiki
How do I get a widget to have control_after_generate
Seeds in the KSampler nodes are INT with an additional feature - the control_after_generate setting. This is automatically added to any INT with the name seed or noise_seed. If you want to apply it to another widget (for instance, variation_seed...), here's the code I used in the variation noise nodes:
import { app } from "../../../scripts/app.js";
import { addValueControlWidget } from "../../../scripts/widgets.js";
app.registerExtension({
name: "my.unique.extension.name",
async nodeCreated(node) {
const variationSeedWidgetIndex = node.widgets?.findIndex((w) => w.name === 'variation_seed');
if (variationSeedWidgetIndex > -1) {
const variationSeedWidget = node.widgets[variationSeedWidgetIndex];
const variationSeedValueControl = addValueControlWidget(node, variationSeedWidget, "fixed");
node.widgets.splice(variationSeedWidgetIndex+1,0,node.widgets.pop());
}
}
});
nodeCreated is called for every node type; search the node widgets for ones called variation_seed, use the addValueControlWidget method to add the control to the end of the widget list, and then use splice to move it to directly after the variation_seed.
Why after?
It's control after generate because of the way ConfyUI works: when you queue a prompt the whole thing (graph and widget values) gets bundled up and sent to the backend. Code generally gets run on the nodes in response (progress bars, images etc), by which time changing the widgets doesn't have any effect on the execution.
So mostly the javascript can only change things in preparation for the next run.