Skip to content
Back to search

china-patent-figure-skill

Generate patent figures from a 3D CAD assembly (STEP) by writing one figure-plan.json that scripts render deterministically into assembly and exploded DXF sheets with leaders and reference numerals, and clean or convert existing patent line drawings (DWG, DXF, Matplotlib, PDF, raster) into continuous-line DXF plus an AutoCAD-audited DWG with reference numerals removed and functional labels preserved.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/pisenailab--china-patent-figure-skill/badge.svg)](/listings/pisenailab--china-patent-figure-skill)

HTML

<a href="/listings/pisenailab--china-patent-figure-skill"><img src="/api/listings/pisenailab--china-patent-figure-skill/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 452 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ---
  2. name: china-patent-figure-skill
  3. description: Generate patent figures from a 3D CAD assembly (STEP) by writing one figure-plan.json that scripts render deterministically into assembly and exploded DXF sheets with leaders and reference numerals, and clean or convert existing patent line drawings (DWG, DXF, Matplotlib, PDF, raster) into continuous-line DXF plus an AutoCAD-audited DWG with reference numerals removed and functional labels preserved.
  4. ---
  5. # 中国专利附图 Skill
  6. **中国专利附图 Skill** turns a 3D assembly (STEP) into CNIPA-style patent figures (说明书附图) with reference numerals and leaders, and nothing more (no claim drafting, no search). The Python package directory stays `patent_figure_kit`; the CLI is `pfk`. The Web workbench, CLI, REST and MCP all report this display name.
  7. Two routes. Pick one by input type and do not mix them.
  8. | Input | Route | Where the geometry comes from |
  9. | --- | --- | --- |
  10. | 3D CAD assembly — `.stp` / `.step` | **Route A**, below | computed by `scripts/patent_figure/*` from a plan you write |
  11. | Existing DXF | Route B | the source file, cleaned in place on a copy |
  12. | Existing DWG | Route B (convert to DXF first) | the source file |
  13. | Matplotlib or other vector | Route B | the source artists / paths |
  14. | PDF, PNG, JPG | Route B | extracted vector paths, or a traced reconstruction |
  15. `scripts/cad_hlr_to_dxf.py` remains the **legacy single-view** STEP route: one view, no per-part
  16. leaders, no numerals, no multi-figure split. Do not use it to produce a filing figure. Everything
  17. below in Route A supersedes it.
  18. ---
  19. ## Route A — 3D CAD assembly to patent figures
  20. **Your only output artefact is `figure-plan.json`.** No coordinate, text height, layout constant or
  21. numeral is ever written by you: the scripts compute all of them. The full specification is
  22. [docs/impl-contract.md](docs/impl-contract.md). Read the contract before deviating from
  23. anything on this page — and then do not deviate, report instead (see *Prohibitions*).
  24. ### Verifying an install
  25. A new machine or runtime should prove the toolchain works before doing real work:
  26. ```bash
  27. python3 acceptance/run_acceptance.py
  28. ```
  29. Nineteen nodes, several minutes, exit 0 only if every one passes. Two of them earn
  30. their keep: one deliberately breaks a good drawing to prove the QA gate can fail at all,
  31. and one compares this machine's rendering against a digest recorded in the repository —
  32. which is what makes "any runtime renders the same figure" a checked claim rather than a
  33. promise. See [acceptance/README.md](acceptance/README.md); the behavioural half, which no
  34. script can judge, is in [acceptance/行为验收.md](acceptance/行为验收.md).
  35. ### Two authors, one plan
  36. A plan can be written by a model (below) or clicked together by a person in **Plan Studio**
  37. (`python3 scripts/plan_studio.py ASM.stp` — local browser UI: pick parts in 3D, group them
  38. into figures, name them, render behind the same QA gate). Both authors produce the same
  39. `figure-plan.json` and go through identical CLIs, so a hand-made plan reproduces like any
  40. other: in a verified environment the same plan yields the same normalised entity digest
  41. (coordinates to 6 decimals, geometry and text entities, file header and handles excluded —
  42. acceptance N10/N10b). When a human wants to adjust figure grouping, point them at
  43. Plan Studio instead of editing JSON by hand — and never have a model drive the Studio.
  44. ### The loop
  45. ```
  46. doctor → analyze → write plan → validate → render (QA gate inside) → convert
  47. ↑ │
  48. └──── on failure: edit the plan only ────┘
  49. ```
  50. Run the commands exactly as written. Every CLI prints its contract under `--help`, writes
  51. machine-readable output with `--json`, and exits `0` pass / `1` failure / `2` usage error.
  52. **A0 — environment probe (first run in a session, always).**
  53. ```bash
  54. python3 scripts/doctor.py --json
  55. ```
  56. Exit `1` means a required capability is missing. Report what is missing and stop. Never work around
  57. a missing dependency by hand.
  58. **A1 — analyze the assembly.** This is the only place part names and geometry enter the workflow.
  59. ```bash
  60. python3 scripts/analyze_assembly.py ASM.stp -o assembly.json --include 'SYN-*' --exclude '*SCREW*'
  61. ```
  62. `--include` / `--exclude` are repeatable and **case-sensitive** (`fnmatchcase`), as is every glob in
  63. the system. Read `assembly.json` before writing the plan: `parts[]`, `stack_order`,
  64. `coaxial_groups`, `size_tiers`, `split_suggestions`, `warnings`. `split_suggestions` may legitimately
  65. be `[]` — then the grouping is yours to choose. Add `--instances assembly.instances.json` to also
  66. write the per-instance sidecar (every instance's assembly path); A1b needs it to see sub-assemblies
  67. and a part name that occurs in several of them.
  68. **A1b — candidate figures (optional, F2-lite).** When you do not know how to group the parts,
  69. ask for candidates — every one is **actually rendered and run through the QA gate** before it gets
  70. a status:
  71. ```bash
  72. python3 scripts/suggest_figure_plan.py --assembly assembly.json --instances assembly.instances.json \
  73. --step ASM.stp [--plan plan.json] -o .suggest/ --json candidates.json
  74. ```
  75. Candidates: the whole assembly (a fallback that is *allowed* to fail — its reason teaches the
  76. split), the whole assembly exploded along the principal axis, every `split_suggestions` figure, one
  77. exploded figure per sub-assembly and per coaxial group. Each candidate lists `members` as **real
  78. part names** (`{"part": …}`), `status` `pass`/`fail` with a plain-language `reason` and
  79. `suggestion`, and `ambiguous_members` when a name occurs in several sub-assemblies (a plan selects by
  80. name, so it picks every instance: 「按名称选中 N 处」). Standard parts (contract §14.2 regex:
  81. SCREW/BOLT/NUT/WASHER/PIN/BEARING/螺钉/螺栓/螺母/垫圈/销/轴承, whole-word for Latin, lead/ball screws
  82. excepted) are trial-rendered with `label: "none"`. The tool never edits a plan: copy the members
  83. of a `pass` candidate into a figure of YOUR plan (A2). Exit `1` + `empty_reason` means no candidate
  84. passed — choose the grouping yourself. The trial versions live in `.suggest/candidates/` and are
  85. never anything's current version.
  86. **A2 — write `figure-plan.json`.** See the next section. This is the only file you author.
  87. **A3 — validate the plan.** Never skip it; it is cheaper than a failed render.
  88. ```bash
  89. python3 scripts/validate_figure_plan.py plan.json --assembly assembly.json --json issues.json
  90. ```
  91. **A4 — render.** The QA gate runs inside, and publishing is **atomic and all-or-nothing**:
  92. the whole set is rendered into a fresh immutable version directory
  93. `out.versions/results/<id>/`, and only when **every** figure passes QA with no dropped HLR
  94. edges is the version committed (one atomic write of `out.versions/current.json`). `out/` is the
  95. **view** of the current version — a symlink on macOS/Linux, a copy on Windows — so it always
  96. holds one complete, gate-passed set; a sheet that did not clear the gate never appears there
  97. (the "过闸才落盘" guarantee, impl-contract §8 / §13.5.3).
  98. ```bash
  99. python3 scripts/render_patent_figure.py plan.json --assembly assembly.json -o out/ \
  100. --cache .cache/ --preview
  101. ```
  102. On success `out/` holds, for every figure, `<figure id>.dxf`, `<figure id>.png` (with
  103. `--preview`), `<figure id>.layout.json`, `<figure id>.qa.json`, plus `reference-numerals.json`
  104. (the global numeral table plus the ready-to-paste 「附图标记说明:1—底座;2—…」 sentence).
  105. If **any** figure fails QA or drops an HLR edge, the run exits `1`, prints the failing checks
  106. with their hints, and **nothing is published**: `out/` keeps the previous complete version (or
  107. does not exist yet), and the failed figures sit under
  108. `out.versions/results/<id>/diag/` for inspection — the path is printed, and `--json report.json`
  109. records it as `diag_dir` (with `version`, `published`, `current_version`). `--only fig2`
  110. re-renders a single figure while iterating (the other figures of the current version are carried
  111. into the new set). `-o` must be a dedicated output directory: a pre-existing ordinary folder is
  112. moved aside to `out.pre-versions-<stamp>/` (never deleted), and a folder that holds the plan,
  113. assembly or STEP is refused. `--in-place` is internal to the workbench's publish service and only accepts an unsealed
  114. version directory as `-o` (anything else is a usage error); never use it for delivery. Two runs
  115. writing the same `-o` at once are safe: revisions and the commit are serialised by a
  116. cross-process lock, so the newer revision always ends up current. `--json` and `--cache` must
  117. point OUTSIDE `-o` and `out.versions/` (checked before rendering, symlink aliases included —
  118. otherwise a report could overwrite a published version); such a path is a usage error (exit 2).
  119. `--thresholds overrides.json` tightens or loosens the QA gate (a JSON object of
  120. `qa.DEFAULT_THRESHOLDS` keys → values); omit it for the contract-frozen thresholds. Use it for
  121. a stricter review pass, e.g. `{"text_height_mm_min": 4.0}`.
  122. **A5 — re-check one DXF (optional, same checks as the gate in A4).**
  123. ```bash
  124. python3 scripts/qa_patent_figure.py out/fig1.dxf --kind exploded --json qa.json
  125. ```
  126. **A6 — convert to DWG** with the frozen converters (identical to Route B; see *Create the DWG*).
  127. ```bash
  128. python3 scripts/autocad_core_dxf_to_dwg.py out/fig1.dxf out/fig1.dwg
  129. ```
  130. **A7 — 规范标注(图号 + 件号名称表)**, on copies only. Chinese filing drafts number figures
  131. 「图1、图2…」and, in the common style used for disclosures (交底书),
  132. carry a 「序号|名 称」table in a free corner of each sheet. The renderer's sheet stays the
  133. canonical output; this CLI derives two copies from it and never touches the source DXF:
  134. ```bash
  135. python3 scripts/annotate_figure_sheet.py out/fig1.dxf --numerals out/reference-numerals.json \
  136. --figure-number 1 -o out/fig1_annotated.dxf --preview # 交底版:图号 + 件号表
  137. python3 scripts/annotate_figure_sheet.py out/fig1.dxf --numerals out/reference-numerals.json \
  138. --figure-number 1 -o out/fig1_filing.dxf --no-table --preview # 递交版:仅图号
  139. # Office profile (profiles/<office>.json): --office uspto writes "FIG. 1" and, with --sheet-total N,
  140. # the "1/N" sheet number (37 CFR 1.84(t)/(u)); default cnipa writes 「图1」. Set "office" in the plan
  141. # so the workbench does the same at render time.
  142. ```
  143. Table rows are read from the NUM layer of that sheet and named from `reference-numerals.json` —
  144. the CLI issues no numeral and invents no name. The descriptive caption moves into the report as
  145. the 附图说明 sentence (「图1为……;」). The figure number is the figure's position in
  146. `plan.figures` (1-based); do not pass anything else.
  147. **A8 — 附图导出包 (filing package, F1).** The deliverable a person files is a **PDF or Word**
  148. document, not loose DXFs. One command renders the plan through the publish service (raw → QA gate →
  149. 交底版 / 递交版 → sealed version) and builds the package through the export service:
  150. ```bash
  151. python3 scripts/export_figure_package.py plan.json --assembly assembly.json -o 附图包/ \
  152. [--variant filing|disclosure|both] [--formats pdf,docx,dxf,dwg] [--dpi 300] \
  153. [--preset standard|conservative] [--office cnipa|uspto] [--zip 附图包.zip] [--json export.json]
  154. ```
  155. Per numbered variant you get `说明书附图_递交版.pdf/.docx` (figure numbers only — this is what is
  156. filed) and `说明书附图_交底版.pdf/.docx` (with the 序号|名称 table — internal disclosure): A4, margins
  157. top 25 / left 25 / bottom 15 / right 15 mm, drawing area `standard` 170×257 or `conservative`
  158. 165×245 mm, one figure per page in 图1…图n order, raster at `--dpi` (default 300), **never
  159. enlarged**. Every written document is then checked **page by page from the file itself**
  160. (`scripts/patent_figure/deliverable_check.py`): page size, margins, scaled minimum text height
  161. ≥ 3.5 mm and ≥ 24 px at the effective dpi, the 「图N」 caption actually inked on page N, page count =
  162. figure count, files complete (Word is verified **structurally** — one section, the exact page and
  163. margins, one centred inline picture per paragraph, explicit single spacing, page breaks only where
  164. expected — and the report says so: actual Word pagination is not measured). A document that fails
  165. — or whose check could not run — is moved to `_未通过核验/` and its items are
  166. `fail` with the reason — never reported ok (e.g. `--dpi 72` fails every page: 3.5 mm ≈ 9.9 px).
  167. DXF/DWG are source files for re-editing; DWG is `skip` with a reason when no converter is installed.
  168. The package also holds `附图说明.txt`, `核对清单.txt` (what a person must still check by hand —
  169. there is no automatic comparison against the specification in M1) and `核验报告.json`. Exit `0`
  170. only if every requested item passed. Re-check a document yourself with
  171. `python3 scripts/deliverable_check.py 说明书附图_递交版.pdf --sources 递交版_仅图号/fig1_filing.dxf …`.
  172. Exact image parameters follow the current 《电子申请文件格式要求说明》; the PDF check needs the optional
  173. package `pypdf` (`doctor.py` reports it). Every output path of these CLIs (`-o`, `--workdir`,
  174. `--json`, `--zip`, `--cache`, analyze's `--instances`) is checked before writing: it may not be an
  175. input file, may not land in any version store's reserved area (symlink and letter-case aliases
  176. included), and a work directory must be new, empty or one the same tool created — otherwise exit `2`.
  177. ### Method flowcharts (方法流程图)
  178. Same split of authorship: you write **only** `flowchart.json` (schema `patent-flowchart/1`:
  179. `title`, optional `step_style` `S101`|`S1`, `nodes[{id,kind,text}]`, `edges[{from,to,label}]`,
  180. `kind` ∈ start / end / process / decision / io). Step numbers, box sizes, coordinates, routing and
  181. the figure number are computed; a node text containing a step number is rejected
  182. (`E_STEP_NUMBER_IN_TEXT`), and every decision needs exactly two labelled out-edges (是 / 否).
  183. ```bash
  184. python3 scripts/render_flowchart.py flow.json --check # 只校验
  185. python3 scripts/render_flowchart.py flow.json -o out/flow1.dxf --figure-number 6 --preview --json res.json
  186. ```
  187. Number flowcharts after the structural figures. `res.json` carries the S-number ↔ step table for
  188. the description.
  189. ### Workbench (human UI, multi-project, DeepSeek, REST, MCP)
  190. `python3 scripts/workbench.py` starts a local web workbench (default `http://127.0.0.1:8790/?token=…`):
  191. home page with an example carousel and project list; one Plan Studio per project with click and
  192. **box selection** (left→right window, right→left crossing, Shift add, Alt subtract), AI drafting
  193. of part names, render with the QA gate, automatic 交底版/递交版, method flowcharts, candidate
  194. figures (`POST /v1/projects/{id}/plan/suggest`, accept via `/plan/candidates/accept`), and the
  195. filing package of A8 (`POST /v1/projects/{id}/export`; `GET /v1/capabilities` says up front
  196. whether DWG/Word are available). External callers use REST `/v1/*` (docs at `/docs`, contract in
  197. `docs/openapi.yaml`) or MCP `POST /mcp` with `Authorization: Bearer <token>` (tools include
  198. `suggest_figures`, `accept_figure_candidates`, `get_export`). `?token=` still works for one
  199. compatibility period and answers with a `Deprecation` header. The large-model channel (DeepSeek API,
  200. or a local CodeBuddy CLI as fallback) only drafts **semantics** — part names and flowchart steps —
  201. and everything it returns goes through the same validators; human-entered names are never
  202. overwritten. As with Plan Studio, **a model must never drive the workbench UI**; it talks to the
  203. REST/MCP tools. Project data lives in `~/.patent-workbench` and secrets in
  204. `~/.config/patent-workbench/config.json` (0600) — neither belongs in a repository.
  205. ### The only file you write: `figure-plan.json`
  206. A complete minimal plan, valid against
  207. [schemas/figure-plan.schema.json](schemas/figure-plan.schema.json) and runnable against the
  208. synthetic fixture:
  209. ```json
  210. {
  211. "schema": "patent-figure-plan/1",
  212. "source": {
  213. "step": "tests/fixtures/synthetic.stp",
  214. "include": ["SYN-*"],
  215. "exclude": []
  216. },
  217. "terms": [
  218. {"selector": "SYN-A01", "term": "底座"},
  219. {"selector": "SYN-B02", "term": "回转座"},
  220. {"selector": "SYN-C03", "term": "支撑轴"},
  221. {"selector": "SYN-D04", "term": "密封圈"},
  222. {"selector": "SYN-E05", "term": "调整垫片", "label": "once"},
  223. {"selector": "SYN-F06", "term": "球头", "label": "all"},
  224. {"selector": "SYN-G07", "term": "上盖"},
  225. {"selector": "SYN-H08*", "term": "紧固螺钉", "label": "none"}
  226. ],
  227. "figures": [
  228. {"id": "fig1", "caption": "整体结构示意图", "kind": "assembly", "members": ["*"]},
  229. {"id": "fig2", "caption": "回转组件分解示意图", "kind": "exploded",
  230. "members": ["SYN-A01", "SYN-B02", "SYN-C03", "SYN-G07"],
  231. "layout": {"explode_axis": "z"}}
  232. ],
  233. "layout": {
  234. "view": "iso",
  235. "explode_axis": "auto",
  236. "axis_angle": "auto",
  237. "density": "normal",
  238. "max_labels_per_figure": 20,
  239. "engineering_table": false
  240. }
  241. }
  242. ```
  243. Rules the validator enforces — read them as the contract, not as advice:
  244. - **`terms` carries Chinese technical nouns only, never numerals and never a part code.** The order
  245. of `terms` *is* the numeral issue order: `terms[0]` becomes numeral 1. The script issues the
  246. numbers; a numeral appearing anywhere in the plan is a defect, not a shortcut.
  247. - `terms[].selector` and `figures[].members` are case-sensitive globs on the part name and must each
  248. match at least one part in `assembly.json` (`E_SELECTOR_NO_MATCH` / `E_MEMBER_NO_MATCH`).
  249. - `terms[].label` is `once` (default — exactly one instance carries the numeral), `all` (every
  250. instance), or `none` (standard parts: no leader at all). This is the escape valve for repeated
  251. hardware; use it before you consider splitting a figure.
  252. - `figures[].kind` is `assembly` or `exploded`. `figures[].id` is also the output file stem.
  253. - **`layout.axis_angle` stays `"auto"`.** The renderer solves the sheet angle per figure in closed
  254. form; the optimal angle depends on that figure's length-to-width ratio, so it is not a constant.
  255. Pin a number only when a reviewer asks for a specific look — and never by copying back a value the
  256. renderer just printed at you. Same for `explode_axis`: `"auto"` unless the assembly axis is known.
  257. - `layout` accepts only these keys and only these enums (`additionalProperties: false` everywhere);
  258. a figure may override any key in its own `layout` block.
  259. - Terms that look like internal part codes are rejected (`E_TERM_LOOKS_LIKE_PART_CODE`). Internal
  260. part numbers must never reach a filing figure — that is a confidentiality rule, not a style rule.
  261. ### Prohibitions (hard constraints)
  262. These exist because the v1 failure was a 170-line model-authored render script whose invented layout
  263. constants produced 97% overlapping numerals, 13.5% page occupancy and a table leaking internal part
  264. codes. They are not negotiable.
  265. 1. **Do not write any throwaway generation script** (`gen_*.py`, a `python3 -c` one-liner that draws,
  266. a notebook cell). If a figure needs geometry the CLIs do not produce, that is a capability gap.
  267. 2. **Do not import package internals.** No `sys.path.insert` and no
  268. `from patent_figure... import ...` from your side. The scripts are reachable **only** through
  269. their CLIs.
  270. 3. **Do not put layout constants in the plan** — no coordinates, gaps, text heights, margins, colours,
  271. scales, angles beyond the enumerated `layout` keys.
  272. 4. **Do not hand-fill reference numerals**, in the plan or in the DXF, or renumber the output.
  273. 5. **Do not edit the scripts, the schemas, or the thresholds** to make a figure pass.
  274. 6. **A filing figure carries geometry, leaders, numerals and the caption — nothing else.** No parts
  275. table, no part names, no internal codes, no dimensions, no title block (contract §8). The
  276. `NO./NAME/QTY/REMARK` table exists only behind `layout.engineering_table: true`, is off by
  277. default, and its output is written as `<id>_engineering.dxf`, which is a review copy and never a
  278. filing copy. *(The "Part table" row in
  279. [references/cad-source-to-drawing.md](references/cad-source-to-drawing.md) §6 is a mechanical
  280. assembly-drawing convention; contract §8 overrides it for patent figures.)*
  281. 7. **When the CLI cannot express the requirement, stop and report the gap.** Say what is missing and
  282. which command would need to carry it. A human decides whether to extend the CLI.
  283. ### When validate or QA fails
  284. The only permitted repair is **editing `figure-plan.json` and re-running the loop from A3.** Every
  285. error and every failed check carries a `hint` naming the plan edit that fixes it — apply that edit,
  286. not an invention of your own. Typical repairs:
  287. | Failure | Plan edit |
  288. | --- | --- |
  289. | `E_TOO_MANY_LABELS`, or labels that cannot be placed | set `label: "none"` on standard parts, or split the figure per `assembly.json:split_suggestions` |
  290. | page fill too low, rotation would help | restore `layout.axis_angle` to `"auto"` so the renderer re-solves it (this branch only fires when the plan pinned an angle), or `density: "compact"` |
  291. | page fill too low, rotation would not help | change `layout.view`, or split the figure |
  292. | text height below the floor / part outline too small | `label: "none"` on standard parts, split the figure, or `density: "compact"` — note the message may say the **part count**, not the label count, is what overflowed |
  293. | a degenerate part, or a part with no visible curves | add it to `source.exclude` |
  294. | forbidden text on the sheet | fix the offending `terms[].term` |
  295. **Three consecutive failed repairs on the same figure: stop.** Report the failing checks, the edits
  296. already tried, and the capability gap. Do not widen the scope of the fix, and do not fall back to
  297. drawing anything by hand.
  298. ### Route A delivery checklist
  299. 1. `doctor.py` exits 0, or the missing capability is stated in the handoff.
  300. 2. `validate_figure_plan.py` exits 0 on the final plan.
  301. 3. `render_patent_figure.py` exits 0 — every figure passed the QA gate.
  302. 4. The plan contains no numerals, no coordinates and no layout constants beyond the enumerated keys.
  303. 5. No sheet carries a parts table, an internal part code or a dimension; `_engineering.dxf` files,
  304. if any, are labelled as review copies in the handoff.
  305. 6. `out/reference-numerals.json` accompanies the figures, and the 附图标记说明 sentence is quoted in
  306. the handoff for the specification text.
  307. 7. Preview PNGs were rendered from the DXF and inspected.
  308. 8. When the deliverable is a filing or disclosure set, `annotate_figure_sheet.py` produced the
  309. 「图N」copies (with or without the 件号名称表, as asked) and the 附图说明 sentences are quoted.
  310. 9. When a filing package was asked for, `export_figure_package.py` exited 0 (every PDF/Word page
  311. passed the file-level check) — or the failing items and their reasons are quoted from
  312. `核对清单.txt`; the hand-check list in `核对清单.txt` is passed on to the person.
  313. ---
  314. ## Route B — clean or convert an existing drawing
  315. Produce a clean, editable CAD deliverable while preserving the source files. The expected result is
  316. continuous-line geometry, no patent reference numerals requested for removal, retained functional
  317. labels, and an AutoCAD-audited DWG plus an editable DXF.
  318. - Existing DXF: inspect the text candidates, clean a copy with `scripts/clean_patent_dxf.py`, then validate it with `scripts/validate_clean_dxf.py`.
  319. - Existing DWG: open or convert a copy to DXF with AutoCAD first. Do not treat a compressed DWG as a text-editable file or rewrite it with `ezdxf`.
  320. - Matplotlib or other vector source: preserve the source geometry and export its artists or paths to DXF. Read [references/workflow.md](references/workflow.md) for the artist-to-CAD mapping.
  321. - PDF, PNG, or JPG only: confirm whether the figure is vector or raster. Extract vector paths when present; otherwise trace or reconstruct the geometry. Do not claim that raster-to-vector output is dimensionally exact unless dimensions or controlled CAD are available.
  322. ### Separate reference numerals from functional text
  323. First inventory every text object containing numbers. Treat standalone multi-digit labels such as `100`, `310`, or `3411` as candidates, not automatic proof that they are patent references. Preserve functional identifiers and engineering content such as `A1`, `A2`, `24V`, pin names, dimensions, tolerances, and terminal labels unless the user explicitly says to remove them.
  324. Use an explicit accepted list whenever the drawing contains dimensions or mixed technical notation:
  325. ```bash
  326. python3 scripts/clean_patent_dxf.py input.dxf output.dxf \
  327. --reference-number 100 \
  328. --reference-number 310 \
  329. --reference-number 3411 \
  330. --strip-selected-inline-references \
  331. --remove-figure-labels \
  332. --report cleanup-report.json
  333. ```
  334. For a drawing known to use every standalone multi-digit text object as an attached reference label, `--remove-standalone-candidates` is available. Run `--dry-run` first and review the report. Do not use broad numeric deletion on dimensioned drawings.
  335. ### Make linework continuous
  336. Set graphical entities to `CONTINUOUS` and set their layers to `CONTINUOUS`; checking only the visible plot is insufficient. Preserve geometry, arrows, junctions, and functional symbols. Convert former dashed boxes, centerlines, and chain lines to solid geometry only when the user asks for all-solid figures.
  337. Generate a preview image after cleaning and compare it with the source. The preview must show that no outline, arrowhead, junction, or retained label was lost.
  338. ### Create the DWG
  339. Prefer Autodesk's own core engine over third-party DWG converters when AutoCAD is installed. The bundled converter writes to an ASCII temporary path so Chinese output paths do not get corrupted by the command-script prompt:
  340. ```bash
  341. python3 scripts/autocad_core_dxf_to_dwg.py cleaned.dxf cleaned.dwg
  342. ```
  343. The converter runs `AUDIT`, saves as AutoCAD 2018 DWG, re-audits, and reports entity and non-continuous counts. Pass `--autocad-core` if AutoCAD is installed in a nonstandard location.
  344. When AutoCAD is not installed, fall back to LibreDWG:
  345. ```bash
  346. python3 scripts/libredwg_dxf_to_dwg.py cleaned.dxf -o dwg/ --deep-audit --report dwg-report.json
  347. ```
  348. It writes R2000 and uses `dwgread` in place of the AUDIT round trip: a file that re-parses cleanly
  349. with a non-zero entity count and intact text passes. Say in the handoff which engine produced the DWG.
  350. LibreDWG does not scale to very large combined sheets; convert per figure and deliver an oversized
  351. combined sheet as DXF rather than reporting a DWG that never completed.
  352. If retained Chinese text is substituted or garbled, keep the editable-text DXF and create a second DWG in which the text is converted to vector outlines before conversion. Label that tradeoff clearly: outlined text is portable but no longer editable as text.
  353. ### Route B delivery checklist
  354. ```bash
  355. python3 scripts/validate_clean_dxf.py cleaned.dxf
  356. python3 scripts/autocad_core_dxf_to_dwg.py cleaned.dxf cleaned.dwg
  357. ```
  358. Deliver only after these checks pass:
  359. 1. Source files remain unchanged and outputs are in a new folder or new filenames.
  360. 2. The DXF contains no rejected reference labels and no non-continuous entity or layer linetypes.
  361. 3. The DWG opens in AutoCAD, the final `AUDIT` reports zero errors, and the entity count is nonzero.
  362. 4. A visual preview matches the intended source geometry.
  363. 5. The handoff states which labels were preserved and whether DWG text is editable text or vector outlines.
  364. Read [references/workflow.md](references/workflow.md) when rebuilding from Matplotlib/raster sources, combining multiple figures, or handling Chinese-font portability.
README.md · README · 193 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. **中文** | [English](README.en.md)
  2. <p align="center">
  3. <img src="docs/assets/banner.png" width="100%" alt="中国专利附图 Skill:从 3D 装配体直接出符合国家知识产权局形式要求的说明书附图">
  4. </p>
  5. <p align="center">
  6. <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-2e7d4f.svg" alt="MIT"></a>
  7. <a href="#三分钟上手"><img src="https://img.shields.io/badge/Python-3.9--3.12-1c4d8f.svg" alt="Python 3.9–3.12"></a>
  8. <a href="SKILL.md"><img src="https://img.shields.io/badge/Agent-Skill%20·%20MCP%20·%20CLI-b43a2b.svg" alt="Skill · MCP · CLI"></a>
  9. <a href="references/patent-figure-spec.md"><img src="https://img.shields.io/badge/版式-CNIPA-1e1c17.svg" alt="CNIPA"></a>
  10. </p>
  11. <p align="center"><b>把 3D 装配体,变成可以直接放进专利申请的说明书附图。</b><br>
  12. 导入 STEP,自动消隐、分图、发放附图标记、画引线、按国家知识产权局形式要求排版,导出 PDF · Word · DXF。</p>
  13. ## 五个特点
  14. 1. **从 3D 模型直接出线条图。** 读入 STEP 装配体,用几何内核做解析式消隐,线条来自真实几何,不是截图描边,也不是生成式模型"画"出来的。
  15. 2. **附图标记和引线全自动。** 标号按规则发放,引线不交叉、不压字、落点准确;螺钉、轴承等标准件默认不标号,可以随时改。
  16. 3. **按中国专利形式要求排版。** A4 图纸,页边 上 25 / 左 25 / 下 15 / 右 15 mm,「图 N」居中在图下方,字高不低于 3.5 mm,图内只留标号。
  17. 4. **13 项质量闸门把关。** 标号重叠、引线交叉、字高、版面铺满度等逐项检查;不通过的图不会被导出,每一项都用白话告诉你原因和改法。
  18. 5. **装进你的 AI Agent,也能自己点着用。** 以 Skill、MCP、命令行三种方式接入 Claude Code、Codex、Trae、CodeBuddy 等;不写代码的人用浏览器工作台。全程在本机运行,未公开的图纸不出你的电脑。
  19. <p align="center">
  20. <img src="docs/assets/hero.gif" width="92%" alt="真实录屏:空工作台,载入示例行星齿轮减速器,候选分图,出图并通过 13 项质量闸门,导出附图包">
  21. <br><sub>真实录屏:全新数据目录、首次运行、未快进。示例模型由仓库脚本生成,与任何真实产品无关。</sub>
  22. </p>
  23. ## 它做什么,你做什么
  24. 画附图里最费时间的,是重复劳动:换视角、消隐线、排版、数标号、拉引线、对字高。最值钱的,是判断:保护范围怎么体现、哪个视角最能说明发明点、审查意见怎么答。
  25. **中国专利附图 Skill 只接手前者,把后者留给你。**
  26. | 交给它 | 留给你 |
  27. | --- | --- |
  28. | 从 3D 模型算出消隐线条 | 选哪些零件进哪张图 |
  29. | 按结构给出候选分图,并逐张试出图 | 确认分图是否体现发明点 |
  30. | 发放附图标记、排引线、避让文字 | 给零件定名称,和说明书、权利要求对上 |
  31. | 按形式要求排版、检查、导出 | 最终审核,并对申请文件负责 |
  32. AI 在这里只做"填空":它写的唯一文件是一份分图计划 `figure-plan.json`,里面没有坐标、没有字高、没有标号。所有线条和位置都由脚本计算,同一份计划在已验证环境下每次出图结果一致,可以复查、可以追溯。
  33. ## 三分钟上手
  34. 先装好 [Python 3.12](https://www.python.org/downloads/)(3.9–3.12 均可;Windows 安装时勾选「Add python.exe to PATH」),再下载本仓库:
  35. ```bash
  36. git clone https://github.com/PisenAILab/china-patent-figure-skill.git
  37. ```
  38. 然后选一条路:
  39. **① 不想碰命令行:双击安装**
  40. | 系统 | 操作 |
  41. | --- | --- |
  42. | Windows | 右键 `安装并启动.ps1`,选「使用 PowerShell 运行」 |
  43. | macOS | 双击 `安装并启动.command`;首次被拦时右键选「打开」 |
  44. | Linux | 终端运行 `./install.sh` |
  45. 脚本会建独立环境、装依赖、自检,然后打开浏览器工作台。点「一键载入示例」,就能看到完整流程。
  46. **② 在 AI Agent 里用:作为 Skill 安装**
  47. ```bash
  48. git clone https://github.com/PisenAILab/china-patent-figure-skill.git ~/.claude/skills/china-patent-figure-skill
  49. cd ~/.claude/skills/china-patent-figure-skill
  50. python3 -m pip install -r requirements-pinned.txt -r requirements-web.txt
  51. ```
  52. 之后对 Agent 说「用这个 STEP 出专利附图」即可,入口是 [`SKILL.md`](SKILL.md)。Codex 读 [`AGENTS.md`](AGENTS.md);其他客户端走 MCP,各家写法见 [`docs/mcp-clients.md`](docs/mcp-clients.md)。
  53. **③ 开发者:命令行**
  54. ```bash
  55. cd china-patent-figure-skill
  56. python3 -m venv .venv && source .venv/bin/activate # Windows:.venv\Scripts\activate
  57. python3 -m pip install -r requirements-pinned.txt -r requirements-web.txt
  58. python3 scripts/pfk_cli.py doctor # 最后一行应为:结论:可以启动工作台。
  59. python3 scripts/pfk_cli.py start # 打开浏览器工作台
  60. ```
  61. <details>
  62. <summary>不开界面,一条龙出一套附图包(冒烟测试)</summary>
  63. ```bash
  64. mkdir -p "$HOME/pfk-demo"
  65. python3 scripts/make_demo_assemblies.py -o "$HOME/pfk-demo"
  66. cp examples/planetary-gearbox/figure-plan.json "$HOME/pfk-demo/"
  67. python3 scripts/analyze_assembly.py "$HOME/pfk-demo/demo-planetary-gearbox.stp" -o "$HOME/pfk-demo/assembly.json" --include 'PGB-*'
  68. python3 scripts/export_figure_package.py "$HOME/pfk-demo/figure-plan.json" --assembly "$HOME/pfk-demo/assembly.json" -o "$HOME/pfk-demo/附图包"
  69. ```
  70. 预期:6 行 `[通过]`,最后显示「全部通过」,退出码 0;`附图包/` 里有 `说明书附图_递交版.pdf`。
  71. </details>
  72. <!-- For AI agents: non-interactive install + smoke test from a source checkout. No credentials, no AI channel, nothing leaves the machine.
  73. git clone https://github.com/PisenAILab/china-patent-figure-skill.git && cd china-patent-figure-skill
  74. python3 -m venv .venv && . .venv/bin/activate
  75. python3 -m pip install -U pip && python3 -m pip install -r requirements-pinned.txt -r requirements-web.txt
  76. python3 scripts/pfk_cli.py doctor # expect last line: 结论:可以启动工作台。 (exit 0)
  77. then run the smoke test above. Expected: six "[通过]" lines and "(全部通过)", exit 0.
  78. Python must be 3.9–3.12. Full acceptance (several minutes): python3 acceptance/run_acceptance.py — do not pipe it, the exit code matters. -->
  79. ## 你会拿到什么
  80. 点「导出附图包」,得到一个压缩包:
  81. - **递交版 PDF**:只有图号与附图标记,按形式要求排版,用于提交。
  82. - **交底版 Word**:多一张"标号—零件名称"对照表,方便和发明人、代理师核对。
  83. - **DXF 源文件**:可以继续在 CAD 里编辑;装了 AutoCAD 或 LibreDWG 还能转 DWG。
  84. - **《附图说明》文本**:可直接粘进说明书的「附图说明」一节。
  85. - **《核对清单》**:逐张列出闸门结果和需要人工确认的事项。
  86. <table>
  87. <tr>
  88. <td align="center" width="33%"><img src="docs/assets/package/pdf-filing-p1.png" alt="递交版 PDF 第一页"><br><sub>递交版 PDF</sub></td>
  89. <td align="center" width="33%"><img src="docs/assets/package/docx-disclosure-p1.png" alt="交底版 Word 预览"><br><sub>交底版 Word(预览图,实际分页以 Word 打开为准)</sub></td>
  90. <td align="center" width="33%"><img src="docs/assets/package/dxf-source.png" alt="DXF 源文件"><br><sub>DXF 源文件</sub></td>
  91. </tr>
  92. </table>
  93. > [!IMPORTANT]
  94. > 版式按国家知识产权局形式要求排版,规则出处逐条列在 [`references/patent-figure-spec.md`](references/patent-figure-spec.md)。精确图片参数以当期《电子申请文件格式要求说明》为准;最终以受理为准,本工具不构成法律意见。
  95. ## 在工作台里怎么用
  96. <table>
  97. <tr>
  98. <td align="center" width="25%"><img src="docs/assets/readme/step1-import.jpg" alt="导入 STEP"><br><sub><b>① 导入</b><br>拖入 STEP,自动解析装配层级</sub></td>
  99. <td align="center" width="25%"><img src="docs/assets/readme/step2-candidates.jpg" alt="候选分图"><br><sub><b>② 选图</b><br>按结构给出候选分图,过闸的盖绿章</sub></td>
  100. <td align="center" width="25%"><img src="docs/assets/readme/step3-qa.jpg" alt="出图与质检"><br><sub><b>③ 出图</b><br>13 项闸门逐项给结论</sub></td>
  101. <td align="center" width="25%"><img src="docs/assets/readme/step4-export.jpg" alt="导出附图包"><br><sub><b>④ 导出</b><br>PDF · Word · DXF 一次拿到</sub></td>
  102. </tr>
  103. </table>
  104. 不通过时不会给你一张"看起来差不多"的图,而是告诉你卡在哪、怎么改:
  105. <p align="center"><img src="docs/assets/readme/feat-gate-failed.jpg" width="80%" alt="质量闸门判定不通过时的白话原因与修改建议"></p>
  106. <details>
  107. <summary>13 项质量闸门分别查什么</summary>
  108. | 检查项 | 通过条件 |
  109. | --- | --- |
  110. | 图形占比 | 图形占图区足够大,不留大片空白 |
  111. | 版面铺满度 | 排版充分利用版心 |
  112. | 标号字高 | 不低于 3.5 mm |
  113. | 零件与字号比例 | 标号不比所指零件还大 |
  114. | 标号重叠 | 0 处 |
  115. | 引线压字 | 0 处 |
  116. | 引线交叉 | 0 处 |
  117. | 引线落点 | 引线端点落在所指零件上 |
  118. | 零件压叠 | 爆炸图里零件互不遮挡 |
  119. | 标号数量 | 每张图不超过 20 个,超了建议拆图 |
  120. | 多余文字 | 图内只留标号 |
  121. | 线型 | 只用连续实线 |
  122. | 禁用文字 | 图内没有注释性文字 |
  123. </details>
  124. ## 数据与隐私
  125. - **出图全部在本机完成。** 解析、消隐、标号、质检、导出都不联网;工作台默认只监听 `127.0.0.1`。
  126. - **AI 是可选项。** 只用于给零件起名、识别结构分组。检测到 `DEEPSEEK_API_KEY` 或本机 CodeBuddy 时会默认开启,并会外发零件名、尺寸、装配路径等派生信息,不外发 STEP 文件和几何数据。
  127. - **处理保密模型前请先关闭 AI**:启动前设置 `PFK_AI_PROVIDER=none`,首页显示「AI 未接入」即为关闭。
  128. ## 已知限制
  129. - 目前只出线条图,不做剖视图和局部放大图。
  130. - 带封闭外壳的模型,候选分图可能被闸门全部拦下,需要在 3D 里手动框选零件分组。
  131. - 只读 STEP;其他格式请先在 CAD 里导出为 STEP。
  132. - macOS 已实机验证;Windows 与 Linux 安装脚本尚未在真机上完整验证,欢迎反馈。
  133. - 交底版 Word 只做结构核验,实际分页以 Word 打开为准。
  134. ## 文档
  135. | 文档 | 内容 |
  136. | --- | --- |
  137. | [`SKILL.md`](SKILL.md) | 给 AI Agent 的完整工作流 |
  138. | [`references/patent-figure-spec.md`](references/patent-figure-spec.md) | 中国专利附图形式要求与出处 |
  139. | [`docs/impl-contract.md`](docs/impl-contract.md) | 模块接口、确定性规则与排版算法 |
  140. | [`docs/deploy/`](docs/deploy/) | 本地、服务器与在线演示站部署 |
  141. | [`acceptance/README.md`](acceptance/README.md) | 19 项验收节点:怎么证明这台机器出图正确 |
  142. ## 参与与许可
  143. 欢迎提 Issue 和 PR。提交前请运行 `python3 acceptance/run_acceptance.py`,确认全部通过,细则见 [`CONTRIBUTING.md`](CONTRIBUTING.md)。
  144. MIT 许可证 · 品胜 AI Lab 开源项目

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.