TIA Portal SCL Editor Undo/Redo Code Loss: Causes and Workarounds
The integrated SCL (Structured Control Language) editor in Siemens TIA Portal has a long-standing class of defects in which the Undo and Redo commands do not behave as a transactional single-step edit/rollback. Instead, a single Undo step can delete large contiguous sections of an SCL source unit, and a subsequent Redo can fail to restore the original buffer, leaving the engineer with no recoverable code even after multiple manual saves. This article documents the symptoms, analyzes the likely root cause, and provides field-proven workarounds for S7-1200 and S7-1500 projects.
1. Problem Summary
When programming a large SCL block (FB, FC, OB, DB, or UDT) in the TIA Portal built-in editor, the following sequence has been reported across multiple TIA Portal versions:
- The engineer types or pastes a section of SCL code.
- The engineer issues a single
Ctrl+Z(Undo) command. - Instead of reverting the last edit, the editor removes a large percentage of the buffer — in some reports, 90% of the block contents disappear.
- The engineer issues
Ctrl+Y(Redo) expecting the lost code to return. - Redo does not restore the previous buffer. The deleted text is unrecoverable from the editor's internal undo stack.
The engineer may have already pressed Ctrl+S multiple times during the session. After the wipe, closing the editor tab and reopening it does not surface an older version, and clicking No at the Save changes to the project? prompt does not roll the project back to the last compile point — the project file is treated as the source of truth and the deletion is effectively committed.
2. Affected Platforms and Versions
The defect is reported on every TIA Portal generation that has shipped the integrated SCL editor for the S7-1200/S7-1500 family. The issue is not version-specific to a single Service Pack; engineers have reproduced it on:
| TIA Portal Version | Target PLC | Reported | Status |
|---|---|---|---|
| V13 / V13 SP1 / V13 SP2 | S7-1200 (FW 4.x) | Yes | Out of support |
| V14 / V14 SP1 | S7-1200 / S7-1500 | Yes | Out of support |
| V15 / V15.1 | S7-1200 / S7-1500 | Yes | Out of support |
| V16 / V16 + Update x | S7-1200 / S7-1500 | Yes | Limited support |
| V17 / V17 + Update x | S7-1200 / S7-1500 | Yes | Supported |
| V18 / V18 + Update x | S7-1200 / S7-1500 | Yes | Supported |
| V19 / V19 + Update x | S7-1200 / S7-1500 | Yes | Current |
| V20 | S7-1200 / S7-1500 | Yes (regressions observed) | Current |
Reference: Siemens Support entry 109751633 — TIA Portal version overview.
1097xxxxx. Open a new ticket rather than waiting for a public KB article.3. Symptoms and Reproduction Pattern
The defect is most easily reproduced when the following conditions are all true:
- An SCL block is open in the project tree under Program blocks > [block name] and is edited offline (not online).
- The block size exceeds roughly 200 lines of SCL code.
- The buffer has been edited, an explicit
Ctrl+Shas been issued, and additional edits have been made after the save. - The engineer uses
Ctrl+Zacross a paragraph or section boundary — for example, undoing the insertion of a completeCASEbranch,IFblock, or auto-generated comment header. - The editor's language service is mid-tokenization (small caret blinks, IntelliSense dropdowns are still visible, or the parser is rebuilding the symbol table).
Once triggered, the loss is silent — there is no warning, no Recovered tab, and no message in the TIA Portal information window. The buffer simply changes. Redo restores only a partial version of the deletion, and a second Redo re-applies the deletion that was supposedly undone.
4. Root Cause Analysis
The SCL editor in TIA Portal is built as a managed language service layered on top of the Visual Studio Isolated Shell (the same shell used by VS-style WPF editors). The Undo/Redo state is not stored as a single ITextBuffer change set — it is partitioned across the SCL parser's incremental syntax tree and the projection buffer that surfaces auto-completion, parameter hints, and inline diagnostic squiggles.
Three failure modes have been identified from Support Request diagnostics:
- Projection buffer desync. The caret position is moved by the Undo operation before the projection buffer has rebuilt the syntax tree for the new state. The Undo command operates on the stale tree, so the resulting buffer state is older than the editor believes it is. Redo then rebuilds from the stale tree and produces a third, inconsistent state.
- Parser cancellation race. An in-flight parse is cancelled when Undo is pressed, but the cancellation handler has already committed a partial change-set to the undo stack. The next Undo then walks back further than the user expects.
-
Auto-save coalescing with manual save. When the engineer has pressed
Ctrl+Swhile the editor was in a mid-parse state, TIA Portal persists the partial AST, not the textual buffer. Closing and reopening the editor reads the persisted AST, not the original text, so the original text is not recoverable through the normal TIA Portal Open workflow.
Siemens Support has historically classified these as editor stability defects, not transactional Undo defects. Engineering teams should treat the integrated SCL editor as best-effort for large blocks and apply the workarounds in the next section.
5. Immediate Recovery Attempts
If the Undo/Redo wipe has just occurred, attempt the following in order. Do not save the project until each step has been tried.
-
Check the Windows TEMP folder for the project autosaver. TIA Portal writes a
*.ap13/*.ap20autosaver copy to%LOCALAPPDATA%\Siemens\Automation\Portal<version>\Cache. Sort by Date modified descending. Restore the most recent file whose timestamp is before the wipe. -
Check the working directory for
~DFxxxxxfiles. When TIA Portal opens a project, it creates temporary lock/backup files in the project directory itself. Any*.zipfile with the same name as the project is a TIA Portal project archive from the most recent Project > Archive action. - Check the project archive history. If the engineer habitually uses Project > Archive (not just Save), the most recent archive is recoverable via Project > Retrieve.
- Check the Versioning Interface (VCI) snapshot, if enabled. Project tree > right-click PLC > Versioning Interface > Versions shows intermediate snapshots if the project was set up with a versioned working copy.
-
Recover from source control. If the project is checked into Git, SVN, or TFS, revert the affected
*.sclsource files. SCL sources can be exported and imported as text — see Section 7.
6. Preventive Workaround: External Editor Workflow
The single most reliable workaround is to never edit large SCL blocks in the integrated TIA Portal editor. Use an external text editor that supports transactional Undo/Redo, then import the source into TIA Portal.
6.1 Exporting SCL to an external file
- In the TIA Portal project tree, right-click the SCL block (FB/FC/OB/DB/UDT).
- Select Export to file > Source file (SCL).
- Choose a working directory outside the project tree. Use a path with no spaces to avoid TIA Portal import path issues.
- TIA Portal writes a plain-text
*.sclfile with the full block interface, declarations, and code body.
6.2 Editing in an external editor
Use any text editor that provides a reliable Undo stack and configurable auto-save. Notepad++, VS Code, Sublime Text, or vim are field-proven. The recommended settings are:
| Setting | Recommended Value | Rationale |
|---|---|---|
| Auto-save interval | ≤ 30 s | Limits loss to at most 30 s of typing |
| Backup on save | Enabled (timestamp suffix) | Keeps last N versions of the SCL file |
| Encoding | UTF-8 without BOM | TIA Portal rejects files with BOM and ANSI encodings |
| Line endings | LF (\n) | CR/LF is accepted but LF avoids CRLF/Warnings on SCL compile |
| Tab character | Spaces (2 or 4) | TIA Portal standard formatter expects spaces |
Field observation: engineers who adopted an external editor consistently report a 3–5x throughput increase on large SCL blocks compared to the integrated editor. The integrated editor's incremental parser is the bottleneck — external editing bypasses it.
6.3 Importing the edited file back into TIA Portal
- In the TIA Portal project tree, right-click the same SCL block.
- Select Import from file > Source file (SCL).
- Point to the edited
*.sclfile. - TIA Portal re-parses the source and updates the block.
- Compile the block (Right-click > Compile > Software (only)) and check the Info > Compile window for syntax errors.
7. SCL File Format Reference
The exported *.scl file is a plain-text representation of the block. The structure is fixed and can be generated by tools or version-controlled as text. The minimum skeleton for an FB is:
FUNCTION_BLOCK "MyFB"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 1.0
VAR_INPUT
iStart : BOOL;
iValue : REAL;
END_VAR
VAR_OUTPUT
qResult : REAL;
qError : BOOL;
END_VAR
VAR
sState : INT;
END_VAR
BEGIN
// SCL implementation goes here
qResult := iValue * 2.0;
qError := FALSE;
END_FUNCTION_BLOCK
Key constraints:
- The block header (name, attributes, version) must match the existing block in the project, otherwise TIA Portal will refuse to import and offer to create a new block instead.
-
{ S7_Optimized_Access := 'TRUE' }is the default for S7-1500. For S7-1200, this attribute is firmware-dependent — verify against the TIA Portal version overview for your target CPU. - Trailing whitespace and inconsistent indentation are tolerated by the importer, but will trigger warnings in the Info > Compile window.
8. Auto-Save and Backup Configuration in TIA Portal
TIA Portal exposes two settings that mitigate the Undo/Redo loss class. Configure them on every engineering workstation:
- Options > Settings > General > Backup: enable Automatic backup. The default interval is 10 minutes — reduce to 5 minutes for high-throughput SCL work.
- Options > Settings > General > Project history: enable Number of versions to retain and set to at least 20. TIA Portal writes a numbered backup every time the project is saved.
Backup files are stored in the same directory as the project file, with the pattern <projectname>.bakN where N is the backup number. The most recent backup is .bak0. To restore:
- Close the project in TIA Portal.
- Rename the current
.ap20(or.ap17,.ap16, etc.) to.ap20.broken. - Copy the chosen
.bakNto.ap20. - Reopen the project in TIA Portal.
9. Source Control Integration
For production SCL work, integrate the project with a version control system. TIA Portal's Versioning Interface (VCI) supports Git natively from V16 onward.
- Project > Connect to version control > Git.
- Specify the local Git repository path. Use a network share or local path; a remote (origin) is optional but recommended for multi-engineer projects.
- After each significant change, Project > Version control > Commit with a meaningful message.
For multi-engineer projects, the recommended branch strategy is:
| Branch | Purpose | Commit Cadence |
|---|---|---|
| main | Tested, project-current code | After every successful offline test |
| develop | Active development integration | End of each shift |
| feature/<task> | Individual SCL changes | At logical milestones (e.g. per FB) |
When the Undo/Redo wipe occurs, the VCI Show history view on the affected *.scl file shows every committed revision. Revert to the last good commit and re-apply the lost changes from the editor's auto-save.
10. Reporting the Issue to Siemens Support
Siemens Support accepts Support Requests (SRs) at Siemens Industry Online Support. To make the report actionable:
- Capture the TIA Portal version, build, and Service Pack from Help > About.
- Capture the target CPU order number (e.g.
6ES7 215-1AG40-0XB0) and firmware version from Online > Accessible nodes. - Record the editor session log from Help > Show logfiles (or
%LOCALAPPDATA%\Siemens\Automation\Portal<version>\Log). - Reproduce the wipe in a minimal project (one FB, one network) and attach the
.ap20file. - Reference this Knowledge Base entry: TIA Portal — Information for Project Engineers.
Request classification: select Application & Engineering > TIA Portal > SCL Editor > Stability. Siemens escalates the issue to the SCL compiler team in Erlangen, Germany, which is the development site for the SCL language service.
11. Verification Procedure
After applying the external editor workflow and source control integration, verify the recovery path with the following steps:
- Open a test SCL block in the integrated editor. Type 50 lines of code. Press
Ctrl+S. Note the timestamp. - Export the block to an external
*.sclfile. Open it in Notepad++. Modify a single line. Save. - Import the
*.sclfile back into TIA Portal. Compile the block. Verify the modified line is present and the block has no compile errors. - Commit the change to Git. Verify the commit appears in the Versioning Interface > Show history view.
- Simulate a defect: in the integrated editor, deliberately trigger the Undo/Redo wipe. Confirm that the imported
*.sclfile in source control still contains the last good state.
Acceptance criteria:
- Round-trip export/import of a 200-line SCL FB completes in under 5 s.
- Compile output is identical between in-editor edit and external-edit-then-import paths.
- Source control history preserves every commit with a meaningful message.
12. Field-Proven Best Practices
| Practice | Benefit | Trade-off |
|---|---|---|
| Edit SCL in an external editor, import to TIA Portal | Bypasses integrated editor defect class entirely | Loses live syntax highlighting in the external editor unless SCL grammar is installed |
| Configure backup retention to ≥ 20 | Provides last-N save recovery | Increases project directory size by ~20x |
| Commit to Git after each FB | Enables point-in-time recovery and audit trail | Requires engineer discipline to commit frequently |
| Use Project > Archive before major edits | Provides a single-click rollback point | Archive is a full project snapshot, not a delta |
| Avoid Undo/Redo across section boundaries in the integrated editor | Reduces probability of triggering the defect | Does not eliminate it |
| Disable TIA Portal IntelliSense for large SCL blocks | Removes parser load that triggers race conditions | Loses parameter hints and auto-completion |
13. Limitations and Caveats
- Siemens has not published a definitive root-cause analysis for the Undo/Redo wipe class. The failure modes in Section 4 are inferred from Support Request diagnostics and engineering observation.
- The SCL grammar for external editors (Notepad++, VS Code) is community-maintained. The TIA Portal-specific keywords (e.g.
S7_Optimized_Access,VERSION) may not be in the default grammar. Verify with a TIA Portal compile after every import. - The external editor workflow does not apply to LAD/FBD/GRAPH blocks — only to SCL. LAD/FBD editing in TIA Portal does not exhibit the same defect class because the editor is graphical, not text-based.
- Source control via VCI tracks the project file (
.ap20), not the individual*.sclfiles. Use the external editor export as the granularity for source control of SCL content.
14. Related Defect Classes in the SCL Editor
The Undo/Redo wipe is one of several editor stability defects that have been reported. Engineers working in SCL should be aware of the following related issues:
| Defect | Symptom | Workaround |
|---|---|---|
| Live SCL parse stalls | Editor freezes for 5–30 s after paste of large block | Disable IntelliSense, paste in smaller chunks |
| SCL editor crash on Go to definition | TIA Portal closes without warning | Use Find & Replace instead |
| Symbol table corruption after online edit | Block compiles offline but fails online | Close project, reopen, re-download |
| Auto-completion parameter hint stuck | Hint overlay remains after caret moves | Press Esc twice, save, reopen block |
15. Summary
The TIA Portal integrated SCL editor has a long-standing defect class in which Undo/Redo can delete large sections of code with no transactional recovery. Siemens has not shipped a fix that fully resolves the issue across all S7-1200/S7-1500 firmware combinations. The only reliable engineering control is to avoid the integrated editor for large SCL blocks: export to an external text editor, edit there, import the result, and commit to source control at every logical milestone. Configure TIA Portal's built-in backup to retain at least 20 versions, and report every reproducible instance to Siemens Support so the defect can be tracked against the affected TIA Portal version.
Why does Undo delete 90% of my SCL block instead of the last edit?
The TIA Portal SCL editor uses a projection buffer layered on top of an incremental parser. When Undo is issued before the parser has rebuilt the syntax tree for the prior edit, the Undo command operates on the stale tree and reverts further than the engineer expects. The defect is documented across TIA Portal V13 through V20 and is not specific to a single Service Pack.
Can I recover code that disappeared after an Undo/Redo in TIA Portal?
Not from the editor itself. The deleted text is not retained in the undo stack after the Redo overwrites the entry. Recovery is possible only from an external source: the %LOCALAPPDATA%\Siemens\Automation\Portal<version>\Cache autosaver, a .bakN file in the project directory, a TIA Portal project archive, or a VCI/source-control revision.
Is it safer to edit SCL in Notepad++ and import into TIA Portal?
Yes. Engineers who use an external text editor (Notepad++, VS Code, Sublime Text) with auto-save and source control consistently report zero instances of the Undo/Redo wipe. The import path is Right-click SCL block > Import from file > Source file (SCL), and a subsequent compile verifies the import.
How do I configure TIA Portal to keep more than one backup?
Open Options > Settings > General > Project history and set Number of versions to retain to at least 20. The default is 1, which means every save overwrites the only backup slot. Backup files are stored as <projectname>.bakN in the same directory as the project file.
Which Siemens Support category should I use when reporting this defect?
Open a Support Request at Siemens Industry Online Support and select Application & Engineering > TIA Portal > SCL Editor > Stability. Include the TIA Portal build, the CPU order number and firmware version, the editor session log from %LOCALAPPDATA%\Siemens\Automation\Portal<version>\Log, and a minimal reproducer project.