extract_methods_to_xml
Convert inline METHOD blocks in TwinCAT ST code to structured XML elements for improved organization and IEC 61131-3 compliance.
Instructions
Promote inline METHOD blocks from main ST to XML elements.
Args: file_path: Path to .TcPOU file create_backup: Create .bak backup when content changes
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes | ||
| create_backup | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- The core implementation of the extract_methods_to_xml tool which promotes inline METHOD blocks to <Method> XML nodes.
def extract_methods_to_xml(file_path: str, create_backup: bool = True) -> str: """Promote inline METHOD blocks from main ST to <Method> XML elements. Args: file_path: Path to .TcPOU file create_backup: Create .bak backup when content changes """ _t0 = time.monotonic() try: path, error = _validate_file_path(file_path, start_time=_t0) if error: return error file = TwinCATFile.from_path(path) if file.suffix != ".TcPOU": return _tool_error( "extract_methods_to_xml only supports .TcPOU files", file_path=file_path, start_time=_t0, ) before_hash = _sha256_text(file.content) changed, methods_extracted = _promote_inline_methods_to_xml(file) backup_path = None if changed: backup_path = file.save(create_backup=create_backup) after_hash = _sha256_text(file.content) return _with_meta( { "success": True, "file_path": str(file.filepath), "content_changed": changed, "methods_extracted": methods_extracted, "backup_created": create_backup and changed, "backup_path": str(backup_path) if backup_path else None, - twincat_validator/server.py:158-158 (registration)Registration of the extract_methods_to_xml tool within the server.
extract_methods_to_xml = _get_tool_fn("extract_methods_to_xml")