AgentSkillsCN

pcad-to-autocad

将P-CAD代码转译为AutoLISP,并在AutoCAD中进行渲染的指南。

SKILL.md
--- frontmatter
name: pcad-to-autocad
description: Guide for transpiling P-CAD code to AutoLISP and rendering it in AutoCAD.

P-CAD to AutoCAD Rendering Guide

This skill guides the process of converting P-CAD DSL code into AutoLISP scripts and automating AutoCAD to render the final drawing.

Prerequisites

  • Transpiler: f:\Uchannel\.agent\skills\image-to-pcad\scripts\pcad_to_autolisp.py
  • AutoCAD: Installed on the system (typically C:\Program Files\Autodesk\AutoCAD 2021\acad.exe).
  • Workspace: Operations should ideally happen in a workspace-local folder or h:\automation_temp to avoid permission/path issues.

Step 1: Transpilation

Convert the .pcad file to .lsp using the Python transpiler.

powershell
python f:\Uchannel\.agent\skills\image-to-pcad\scripts\pcad_to_autolisp.py <source.pcad> <output.lsp>

Common issues:

  • Encoding: Ensure the .pcad file is UTF-8.
  • Python: Use python or python3 depending on the environment.

Step 2: AutoCAD Automation

AutoCAD can be automated using Script files (.scr).

1. Create a Loader Script (Auto-Generated)

The transpiler automatically generates a <source>.scr file alongside your .lsp output.

Key Features:

  • Automatic Path Handling: The .scr uses the absolute path to your .lsp file.
  • ANSI Encoding: The .scr is encoded in Windows ANSI (GBK/Latin-1) to ensure AutoCAD compatibility, even with Chinese characters in paths.

2. Launch AutoCAD with the Script

Simply drag and drop the auto-generated .scr file into AutoCAD, or use the following command:

powershell
& "C:\Program Files\Autodesk\AutoCAD 2021\acad.exe" /b "C:\path\to\AutoGenerated.scr"

Troubleshooting

numberp: nil Error in AutoCAD

This usually happens if a variable used in a barshape segment is not defined in params or derive.

  • Check: Ensure all variables in segments = [...] are either literals or defined in the global params/derive blocks.
  • Fix: Move local dims definitions to the derive block if they are needed for geometry.

Missing Fonts or Styles

If text looks wrong or "Standard" style is missing properties:

  • The transpiler automatically attempts to set TEXT_FONT (default: fsdb_e.shx,cadhzf.shx).
  • Ensure these fonts are in the AutoCAD font path, or modify pcad_to_autolisp.py globals.

Command Not Found: PCAD_Render

  • Check if the .lsp file was loaded successfully.
  • Look at the AutoCAD command line for syntax errors during loading.

Reference Paths

ItemPath
Transpilerf:\Uchannel\.agent\skills\image-to-pcad\scripts\pcad_to_autolisp.py
AutoCAD EXEC:\Program Files\Autodesk\AutoCAD 2021\acad.exe
Default OutputP-CAD-code\AutoGenerated.lsp