Appearance
Import Job
Poll a long-running asynchronous import. Today core.io.import.dwg (DWG → Snaptrude conversion, minutes) returns an ImportJobHandle instead of blocking; drive it to completion here. Accessed via snaptrude.core.io.job.
Always poll with a timeout. A job cancelled from the app UI (or interrupted by a tab reload) never reaches a terminal state —
getStatuskeeps returning"processing"forever. Give up after a few minutes and surface that to the user.
Types
ImportJobStatus
Lifecycle status: "pending" | "processing" | "complete" | "failed".
Functions
getStatus(job)
Read a job's current status.
Limitation: a job cancelled from the app UI never turns "failed" — it stays "processing" indefinitely. Bound your poll loop with a timeout.
- Parameters:
job:ImportJobHandle— The import job to inspect
- Returns:
ImportJobStatus - Throws:
HandleInvalidErrorif the job handle is unknown.
ts
const job = await snaptrude.core.io.import.dwg(url, 1);
console.log(await snaptrude.core.io.job.getStatus(job)); // "processing"isComplete(job)
Whether the job finished successfully (status "complete"). false while pending/processing and on failure.
- Parameters:
job:ImportJobHandle— The import job to inspect
- Returns:
boolean
ts
const job = await snaptrude.core.io.import.dwg(url, 1);
const deadline = Date.now() + 5 * 60_000; // cap the poll — see getStatus limitation
while (!(await snaptrude.core.io.job.isComplete(job))) {
if (Date.now() > deadline) throw new Error("DWG import timed out");
await new Promise((r) => setTimeout(r, 2000));
}getResult(job)
The imported result once complete — the placed UnderlayHandle. null while still running or if it failed.
DWG results are CAD underlays — CAD scaling is not supported (setScale throws); manage them via core.io.underlay list / getBounds / setOpacity / delete.
- Parameters:
job:ImportJobHandle— The completed import job
- Returns:
UnderlayHandle | null
ts
const cad = await snaptrude.core.io.job.getResult(job);
if (cad) {
const bb = await snaptrude.core.io.underlay.getBounds(cad);
if (bb) console.log(`imported CAD spans ${bb.max.x - bb.min.x} wide`);
}getError(job)
The failure message if the job's status is "failed"; otherwise null.
- Parameters:
job:ImportJobHandle— The import job to inspect
- Returns:
string | null
ts
if ((await snaptrude.core.io.job.getStatus(job)) === "failed") {
console.error(await snaptrude.core.io.job.getError(job));
}Errors
Failed calls reject with a typed PluginError — see Error Handling. Conditions specific to this namespace:
| Code | Thrown by | When | details |
|---|---|---|---|
HANDLE_INVALID | all methods | The job handle is unknown — not minted by import.dwg in this session | — |
A failed (or cancelled) import is data on the success channel, not an error: getStatus returns "failed", getError returns the failure message, and getResult/isComplete return null/false — no method throws for a job in a terminal state.