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_tempto 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
.pcadfile is UTF-8. - •Python: Use
pythonorpython3depending 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
.scruses the absolute path to your.lspfile. - •ANSI Encoding: The
.scris 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 globalparams/deriveblocks. - •Fix: Move local
dimsdefinitions to thederiveblock 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.pyglobals.
Command Not Found: PCAD_Render
- •Check if the
.lspfile was loaded successfully. - •Look at the AutoCAD command line for syntax errors during loading.
Reference Paths
| Item | Path |
|---|---|
| Transpiler | f:\Uchannel\.agent\skills\image-to-pcad\scripts\pcad_to_autolisp.py |
| AutoCAD EXE | C:\Program Files\Autodesk\AutoCAD 2021\acad.exe |
| Default Output | P-CAD-code\AutoGenerated.lsp |