最初のスクリプト
このチュートリアルでは、LinkCAD の対話型コンソールで最初の Python スクリプトを実行する手順を説明します。
コンソールを開く
View → Python Console (Ctrl+Shift+P) に移動します。ウィンドウ下部に Python プロンプトが表示されます。
Hello World
次を入力して ↵ を押します。
print("Hello from LinkCAD!")コンソールに出力が表示されます。
図面を探索する
ファイルを読み込んだ状態で、その構造を調べることができます。
from linkcad import db
# Get the current drawingdwg = db.Drawing.current()
# List all cellsfor cell in dwg.cells(): print(f"Cell: {cell.name}")
# List all layersfor layer in dwg.layers(): print(f"Layer: {layer.name}")形状を数える
from linkcad import db
dwg = db.Drawing.current()main = dwg.main_cell()
count = 0for shape in main.shapes(): count += 1print(f"Total shapes in main cell: {count}")スクリプトエディターを使う
長いスクリプトでは、組み込みエディターを使用します。
- View → Python Script Editor (Ctrl+Shift+E) を開きます
- エディターでスクリプトを書きます
- F5 を押してスクリプト全体を実行します
- または行を選択し、Ctrl+↵ を押して選択部分だけを実行します
次のステップ
- ツールプラグインの作成——GUI ダイアログ付きの再利用可能なツールを作成します
- 形式プラグインの作成——カスタムファイル形式を追加します