知野好男|CAD・BIM Works

DXFをJSON形式に整理して、生成AIに相談する

DXF図面データをJSON形式に整理し、生成AIへの相談や変更比較に活用するための技術メモです。

DXFをJSON形式に整理して、生成AIに相談する

DXF図面データをJSON形式に整理し生成AIへ相談する方法
こんにちは。京都府京田辺市で作曲活動を行いながら、CADオペレーターとして働いている知野好男です。

今回は、DXFに含まれる情報をJSON形式に整理し、生成AIへの相談に活用する方法について記録します。

DXFの情報を、生成AIが扱いやすいJSON形式に整理することで、変更前と変更後の比較や、図面内の仕様確認について相談しやすくなります。

図面や仕様について悩んでいるものの、生成AIにどのような情報を渡せばよいのか分からない場合の参考になればと思います。

DXFはそのままでは内容を把握しにくい

DXFはテキスト形式のファイルですが、CAD内部の構造を表すための記述が多く含まれています。

そのため、人間がテキストエディターで内容を読んだり、DXFをそのまま生成AIに渡して確認してもらったりするには、やや扱いにくい形式です。

そこで、線分、円、文字、寸法、レイヤーなど、確認に必要な情報を抽出し、JSON形式に整理します。

{
  "entity_type": "LINE",
  "layer": "FRAME",
  "start": [0, 0],
  "end": [1200, 0]
}

JSON化の目的は、元の図面を完全に再現することではありません。

図面内の情報を検索、比較、説明しやすい形に整理し、生成AIへの相談材料として利用することが目的です。

必要な情報に絞って出力することで、元のDXFをそのまま扱うよりも、変更箇所や仕様上の疑問点について相談しやすくなります。

変更前と変更後の比較に利用する

変更前と変更後のDXFをそれぞれJSON形式に変換すれば、生成AIに次のような確認を依頼できます。

  • 追加または削除された文字や寸法
  • レイヤーごとの要素数の変化
  • 線分、円、文字などの変更
  • 古い注記や型番が残っていないか
  • 特定の要素の位置や寸法が変わっていないか
  • 変更内容に不自然な点がないか

目視による図面比較だけでなく、変更内容を文章や一覧として整理するための補助として利用できます。

ただし、座標値のわずかな違いや、変換時の丸め処理などによって、実質的には同じ要素が変更箇所として検出されることもあります。

生成AIの回答をそのまま採用するのではなく、確認すべき箇所を見つけるための手掛かりとして使うことが重要です。

ローカルで動くHTMLを生成AIに作ってもらう

DXFをJSON形式に変換するための簡単なツールは、生成AIに作成を依頼することもできます。

たとえば、次のように依頼します。

DXFファイルをブラウザ上で読み込み、線分、円、文字、寸法、レイヤー情報をJSONとして書き出す、ローカルで動作するHTMLを作成してください。

HTMLとJavaScriptだけで処理する構成であれば、ブラウザ上でDXFを読み込み、パソコン内でJSONへ変換できます。

外部のサーバーへ図面をアップロードせずに処理できるため、業務上の図面や機密性のあるデータを扱う場合には重要な考え方です。

ただし、生成AIが作成したコードが本当に外部通信を行わないかは、可能な範囲で確認する必要があります。

外部のJavaScriptライブラリをCDNから読み込む構成になっている場合は、完全なローカル動作とはいえません。必要に応じて、使用するライブラリもパソコン内に保存する構成へ変更します。

また、会社の図面を扱う場合は、社内規則や情報管理ルールに従う必要があります。

JSON化によって失われる情報がある

変換方法によっては、DXFに含まれるすべての情報をJSONへ保存できるとは限りません。

特に注意が必要なのは、次のような情報です。

  • ブロック定義とブロック参照の関係
  • 属性付きブロック
  • 寸法スタイル
  • 線種や線幅
  • ハッチング
  • UCSや座標系
  • 外部参照
  • 3D情報
  • CADソフト独自の拡張データ
  • 単位や尺度
  • 文字コードや特殊文字

たとえば、ブロックを単純な線分や文字へ展開して出力した場合、図形の見た目は確認できても、どの要素が同じブロックに属していたのかという構造情報が失われる可能性があります。

文字や寸法の確認が目的であれば、それでも十分な場合があります。

一方で、JSONから元のDXFを完全に復元したい場合や、ブロック構造、寸法スタイル、外部参照まで確認したい場合には、より詳細な変換処理が必要です。

DXFからJSONへの変換は、図面データの完全な保存形式ではなく、生成AIへの相談や情報整理のための中間資料として考えるのが適切です。

最終的な判断は自分で行う

DXFの情報をJSON形式に整理することで、PDFの図面画像だけを生成AIに見せる場合よりも、文字、座標、レイヤー、要素の種類などを構造化された情報として伝えやすくなります。

その結果、変更箇所の整理や、仕様上の疑問点を洗い出す作業に役立つ可能性があります。

ただし、生成AIは図面の設計意図、社内ルール、製造上の事情、現場での納まりまで正確に理解しているわけではありません。

変換時に情報が失われることもあり、生成AIが誤った解釈や見落としをする可能性もあります。

生成AIから得た回答は、確認箇所を見つけるための補助情報として扱い、必ず元のDXF、PDF、仕様書、関連図面などと照合してください。

図面や仕様についての最終的な判断は、作図者や設計担当者自身が行う必要があります。

English

Organizing DXF Data as JSON for Consultation with Generative AI

Hello. My name is Yoshio Chino. I work as a composer and CAD operator in Kyotanabe, Kyoto, Japan.

In this article, I will describe a method of organizing information contained in DXF files into JSON format so that it can be used when consulting generative AI.

Converting relevant DXF information into a structured JSON format can make it easier to ask generative AI about differences between drawings, changes made during revisions, and possible inconsistencies in specifications.

This method may be useful when you have questions about a drawing but are unsure what information you should provide to an AI system.

DXF Files Can Be Difficult to Interpret Directly

A DXF file is a text-based file, but it contains many descriptions intended to represent the internal structure of CAD data.

As a result, it can be difficult for a person to read a DXF file in a text editor. It may also be difficult for generative AI to examine the original DXF data without first reorganizing it.

One possible approach is to extract the information needed for review, such as lines, circles, text, dimensions, and layers, and organize it in JSON format.

{
  "entity_type": "LINE",
  "layer": "FRAME",
  "start": [0, 0],
  "end": [1200, 0]
}

The purpose of converting DXF data into JSON is not necessarily to reproduce the original drawing perfectly.

The main purpose is to organize information from the drawing into a form that is easier to search, compare, and explain. The resulting JSON can then be used as supporting material when consulting generative AI.

By limiting the output to the information required for a particular review, it may become easier to ask questions about revisions, annotations, dimensions, and possible specification conflicts.

Comparing Drawings Before and After a Revision

If both the original and revised DXF files are converted into JSON, generative AI can assist with checking items such as:

  • Added or deleted text and dimensions
  • Changes in the number of entities on each layer
  • Changes to lines, circles, text, and other objects
  • Old notes or model numbers that may still remain in the drawing
  • Changes in the positions or dimensions of specific elements
  • Differences that may require further investigation

This can provide another way to review a drawing in addition to visually comparing the two versions.

However, small differences in coordinates or rounding during conversion may cause objects that are effectively identical to be reported as changes.

For this reason, AI-generated results should be treated as clues for locating areas that require review, rather than as final conclusions.

Asking Generative AI to Create a Locally Running HTML Tool

A simple tool for converting DXF data into JSON can also be created with the assistance of generative AI.

For example, you could use the following prompt:

Create a locally running HTML file that loads a DXF file in a web browser and exports information about lines, circles, text, dimensions, and layers in JSON format.

If the tool is built using only HTML and JavaScript, it may be possible to load a DXF file in a browser and convert it into JSON on the local computer.

This is an important consideration when working with confidential drawings because the original file does not need to be uploaded to an external server.

However, you should verify, as far as reasonably possible, that the generated code does not communicate with external services.

If the HTML file loads JavaScript libraries from a content delivery network, or CDN, the tool is not operating completely offline. When necessary, those libraries should also be stored locally.

When using company drawings, you must also follow your organization’s information-security policies and internal rules.

Some Information May Be Lost During Conversion

Depending on how the conversion tool is designed, not all information contained in a DXF file will necessarily be preserved in the JSON output.

Particular care may be required for the following types of information:

  • Relationships between block definitions and block references
  • Blocks containing attributes
  • Dimension styles
  • Linetypes and lineweights
  • Hatches
  • User coordinate systems and other coordinate information
  • External references
  • 3D data
  • CAD application-specific extended data
  • Units and drawing scales
  • Character encodings and special characters

For example, if a block is expanded into individual lines and text objects during conversion, its visual appearance may still be available, but the structural information indicating that those elements originally belonged to the same block may be lost.

This may be sufficient when the purpose is only to review text or dimensions.

However, a more detailed conversion process will be required if the goal is to reconstruct the original DXF file or examine block structures, dimension styles, and external references.

It is therefore more appropriate to regard the JSON file as an intermediate document for consultation and information organization, rather than as a complete archival replacement for the original DXF file.

Make the Final Decision Yourself

Organizing DXF information as JSON makes it easier to provide generative AI with structured information such as text, coordinates, layers, and entity types.

Compared with showing the AI only a PDF image of the drawing, this may help it identify revision points and possible inconsistencies more systematically.

However, generative AI does not necessarily understand the design intent, internal company rules, manufacturing requirements, or installation conditions behind a drawing.

Information may also be lost during conversion, and the AI may produce incorrect interpretations or overlook important details.

Any advice provided by generative AI should therefore be treated as supporting information for identifying areas that require further review.

Always compare the results with the original DXF file, PDF drawings, specifications, and other related documents.

The final decision regarding a drawing or specification must be made by the CAD operator, designer, engineer, or other responsible professional.
Navigation