SimpleVG › Tutorial › Chapter 11

Chapter 11: The Live SVG Code Drawer

Goal Read the SVG that SimpleVG writes as you draw, edit it directly and watch the canvas follow, and use Find Selected and Clean & Format to work with larger drawings.

This is an advanced chapter. You never need the code to use SimpleVG, but being able to read and change it is a real strength: it lets you make exact edits, fix things the Inspector cannot reach, and see precisely what a SCADA system will be given.

Part 1: Open the drawer

Draw a rectangle and an ellipse, as in the earlier chapters. Along the very bottom of the window is a bar titled Live SVG XML Source Code (2-Way Editing).

The collapsed code drawer bar along the bottom of the window with Find Selected, Clean and Format XML, Copy to Clipboard and Expand buttons

Click Expand to open it. The same button now reads Collapse.

The code drawer expanded under the canvas, showing the SVG source for a rectangle and an ellipse

Part 2: Reading the code

The drawer shows the drawing as an SVG document. For our two shapes it looks like this:

<svg xmlns="http://www.w3.org/2000/svg" width="500" height="500" viewBox="0 0 500 500">
  <rect x="60" y="80" width="140" height="80" fill="#3182CE" stroke="#2D3748" stroke-width="2"></rect>
  <ellipse cx="320" cy="120" rx="40" ry="40" fill="#3182CE" stroke="#2D3748" stroke-width="2"></ellipse>
</svg>

Only your artwork is shown. The grid, rulers, selection handles and any reference image from Chapter 9 are part of the editor, not of the drawing.

Part 3: Edit the code

The drawer works in both directions. Draw on the canvas and the code updates. Type in the code and the canvas updates, about half a second after you stop typing.

Try it. Click in the code, find fill="#3182CE" on the rectangle and change it to fill="#E53935". The rectangle turns red.

The rectangle on the canvas now red after its fill value was changed in the code drawer

You can add whole shapes too. Just before the closing </svg>, type:

<circle cx="250" cy="300" r="40" fill="#4CAF50" stroke="#2D3748" stroke-width="2"></circle>

A green circle appears below the other two.

A new green circle on the canvas, added by typing its code, with the code visible in the drawer
Note Applying a code edit clears the current selection, so after typing you click a shape again to select it.

When the code is not valid

While you type, the code is often temporarily broken: a missing quote, a half-written tag. SimpleVG simply waits. The canvas keeps showing the last version that was valid, and updates again as soon as your code is well-formed. Nothing is lost by pausing mid-edit.

Careful If you leave the code broken and carry on drawing on the canvas, the code is rewritten from the canvas and your broken edit is replaced. Fix the code first.

Part 4: Find Selected

In a big drawing it is hard to know which lines of code belong to which shape. Select a shape on the canvas, then click Find Selected (or press Ctrl+Shift+F). The drawer opens if it was closed, highlights the code for that shape and scrolls it into the middle of the view.

It looks for the element’s id, data-tag or class first, and its type otherwise, so giving shapes ids (Chapter 10) makes them much easier to find.

Part 5: Clean & Format XML

The code arrives as a single long line. Click Clean & Format XML and SimpleVG tidies it, with one element per line and neat indentation.

The code drawer after Clean and Format XML, with the svg element and each shape on its own indented line

The formatting is done by SimpleVG’s own server, so the app must be running for this button to work. It changes only the layout of the text, not the drawing.

Part 6: Copy to Clipboard

Copy to Clipboard copies the whole code in one click. It is handy for pasting into another editor, a document or a bug report, or into a SCADA project that takes SVG as text.

A safe place to learn SVG Because the canvas shows every change straight away, the drawer is a friendly way to learn how SVG works. Change a number, see what moves. If it goes wrong, undo with Ctrl+Z.

Recap

That completes the SimpleVG tutorial. You can now draw, place and restyle symbols, arrange and trace, tag shapes, and work with the SVG itself. The built-in help (F1) has the full reference for everything you have seen.

← Chapter 10: SCADA Tagging Tutorial contents →