คุณสามารถเขียนคำสั่งเป็น JavaScript แล้วเอามาใส่ในแอพ Draw Things AI ได้ เช่น เขียนคำสั่งให้เจนรูป, คำสั่ง Upscale มันสะดวกตรงที่เราไม่ต้องมาทำเองทีละรูป
เช่น ใช้คำสั่ง SD Ultimate Upscaler ในกระบวนการเป็นการทำภาพขนาด 512×768 ทั้งหมด 24 รูป ทำเองทีละรูปแน่นอนว่ามันน่าเบื่อมาก
แต่การใช้คำสั่ง Script จะช่วยทำทุกอย่างให้เสร็จได้ในคลิกเดียว
วิธีเพิ่มคำสั่ง Scripts ในแอพ Draw Things AI
![Draw-Things-AI-Script-01 | maahalai.com วิธีเพิ่มคำสั่ง Scripts ในแอพ Draw Things AI](https://maahalai.com/wp-content/uploads/2023/09/Draw-Things-AI-Script-01-1024x653.jpg)
1. คลิก Presets เลือก Manage Scripts
![Draw-Things-AI-Script-02 | maahalai.com วิธีเพิ่มคำสั่ง Scripts ในแอพ Draw Things AI](https://maahalai.com/wp-content/uploads/2023/09/Draw-Things-AI-Script-02-1024x778.jpg)
2. คลิก Add ตั้งชื่อ Scripts
และคลิก Add
![Draw-Things-AI-Script-03 | maahalai.com วิธีเพิ่มคำสั่ง Scripts ในแอพ Draw Things AI](https://maahalai.com/wp-content/uploads/2023/09/Draw-Things-AI-Script-03-1024x778.jpg)
3. วาง Script และคลิก Save
ตัวอย่าง Script
//@api-1.0
//
//@api-1.0
// wildcards
// author wetcircuit
// modified by iHy for serial wildcards
// v0.3.a.1
// fallback prompt to be used if no wildcards are found in the UI prompt
const fallbackPrompt = “Portrait of woman wearing {bra|bikini|shirt|nightdress|turtleneck}”;
// set the number of renders — should be determined by wildcards in prompt.
const batchCount = 1; // fallback of sorts
const configuration = pipeline.configuration;
const uiPrompt = pipeline.prompts.prompt;
let promptString; // Declare promptString
// look for wildcards in the UI prompt
if (uiPrompt.includes(‘{‘) && uiPrompt.includes(‘|’) && uiPrompt.includes(‘}’)) {
console.log(“wildcard found.”);
promptString = uiPrompt;
} else {
console.log(“no wildcard detected in the UI prompt. Using fallback prompt in the script.”);
promptString = fallbackPrompt;
}
const countXt = countWildcard1(promptString);
console.log(__dtPrettyPrint(countXt));
// run pipeline
console.log(__dtPrettyPrint(countXt));
for (let i = 0; i < countXt; i++) {
let editedString = replaceWildcardsX(promptString, i);
console.log(__dtPrettyPrint(i));
console.log(__dtPrettyPrint(editedString));
// configuration.seed = -1; there is an interface for that?
let batchCountLog = `render ${i} of ${countXt}`;
console.log(__dtPrettyPrint(batchCountLog));
// Uncomment these lines to run the pipeline
pipeline.run({
configuration: configuration,
prompt: editedString
});
}
// function
function countWildcard1(inputString) {
const wildcardRegex = /{([^}]+)}/g;
let wildCount = 0;
while (match = wildcardRegex.exec(inputString)) {
const options = match[1].split('|');
wildCount += options.length;
}
return wildCount;
}
function replaceWildcardsX(inputString, iX) {
const wildcardRegex = /{([^}]+)}/g;
function replaceWithIndexedOption(match) {
const options = match.slice(1, -1).split('|');
const index = iX; // No need to adjust index
if (index >= 0 && index < options.length) {
console.log(__dtPrettyPrint(index));
return options[index];
} else {
console.log(__dtPrettyPrint(match));
// Return the original match if the index is out of bounds
return match;
}
}
let editedString = inputString;
while (wildcardRegex.test(editedString)) {
editedString = editedString.replace(wildcardRegex, replaceWithIndexedOption);
}
return editedString;
}
![Draw-Things-AI-Script-04 | maahalai.com วิธีเพิ่มคำสั่ง Scripts ในแอพ Draw Things AI](https://maahalai.com/wp-content/uploads/2023/09/Draw-Things-AI-Script-04-1024x653.jpg)
4. วิธีใช้ Scripts ก็คลิกปุ่มเดิมคือ Presets และเลือกสคริปต์ที่ต้องการใช้
![Draw-Things-AI-Script-05 | maahalai.com วิธีเพิ่มคำสั่ง Scripts ในแอพ Draw Things AI](https://maahalai.com/wp-content/uploads/2023/09/Draw-Things-AI-Script-05-1024x665.jpg)
5. รอจนสคริปต์รันเสร็จ
แต่ก่อนใช้งานต้องศึกษาสคริปต์ตัวนั้นๆก่อน ถ้าสร้างเองก็เขียนเองได้เลย สำหรับสคริปต์ที่เอามามาแจก ผมดัดแปลงมาอีกที (ส่วนตัวเขียนสคริปต์เองไม่เป็น)
สคริปต์ที่ผมแจกนี้คือ AI จะเจนรูปทั้งหมด 5 รูป เป็นรูปผู้หญิงใส่ชุดต่างๆ
ซึ่งสคริปต์ตัวนี้จะกำหนดไว้แค่ Prompt ไม่ได้กำหนด Negative Prompt, ขนาดภาพ และตัวโมเดลที่ใช้
ประโยชน์ของสคริปต์จริงๆมันมีเยอะกว่านี้มากนะ ถ้าคุณเป็นโปรแกรมเมอร์คุณสามารถเขียนคำสั่งได้ทุกอย่าง ให้แอพ Draw Things ทำงานอะไรก็ได้