原文
Make a Torus command: pick the center, drag the ring's radius with a preview, then set the tube radius.
import { BRep, Curve, Plane } from "aircad";
export const manifest = {
name: "Torus",
kind: "command",
capabilities: ["document:read", "document:write"],
inputs: {
center: { type: "point", prompt: "Pick the center" },
radius: { type: "length", prompt: "Major radius" },
tube: { type: "length", prompt: "Tube radius" },
},
api: 1,
};
export default async function main(cad) {
const center = await cad.input.point("center");
// Draw the ring while the pointer moves.
const ring = cad.display.show();
const radius = await cad.input.length("radius", {
from: center,
onChange: (r) => ring.set(Curve.circle(Plane.at(center), r)),
});
const tube = await cad.input.length("tube");
return cad.doc.add(BRep.torus(Plane.at(center), radius, tube));
}Saved Torus as a draft in the Scripts panel: asks for center, radius, tube