Description
Hi! I found an issue while rendering a .SchDoc with an applied sheet template.
Some graphical primitives that belong to a SchTemplate record are currently added to the document as normal top-level primitives. As a result, the renderer draws template-owned graphics as real schematic content. In my case this produced an extra Altium title block/frame rendered over the schematic, while the original Altium viewer does not show it there.
The root cause seems to be in SchDocReader: record type 39 is parsed as SchTemplate, but primitives whose OWNERINDEX points to that template record are not associated with the template. They fall through into document.AddPrimitive(primitive).
A minimal fix that worked locally:
- Track template records by their primitive index in
SchDocReader.
- If a primitive has
OWNERINDEX pointing to a known SchTemplate, attach it to that template instead of adding it to the document top level.
- Include template-owned primitives in the model primitive count if round-trip/write fidelity depends on that count.
Pseudo-diff:
var templates = new Dictionary<int, SchTemplate>();
// while reading primitives
if (primitive is SchTemplate template)
templates[primitiveIndex] = template;
// while assigning ownership
else if (ownerIndex >= 0 && templates.TryGetValue(ownerIndex, out var ownerTemplate))
{
ownerTemplate.AddPrimitive(primitive);
}
And SchTemplate can keep these separately:
private readonly List<object> _primitives = new();
public IReadOnlyList<object> Primitives => _primitives;
public void AddPrimitive(object primitive) => _primitives.Add(primitive);
This fixed the incorrect extra title block rendering without disabling the normal sheet frame rendering.
Steps to Reproduce
- Open a
.SchDoc file that has an applied sheet template containing its own title block/frame graphics.
- Parse it with
SchDocReader.
- Render the parsed
SchDocument with the SVG renderer.
- Compare the result with the same document opened in Altium Designer or another reference viewer.
Expected Behavior
SchTemplate should retain primitives owned by the template record, or those primitives should otherwise be excluded from normal document-level rendering.
- Primitives with
OWNERINDEX pointing to a template should not be treated as regular top-level schematic objects.
Observed behavior:
- Template-owned lines/text/frames are rendered as normal sheet primitives.
- This can cause duplicate or misplaced title blocks / sheet frames.
Altium File Type
.SchDoc (Schematic Document)
Package Version
2.0.0
Operating System
Windows
Minimal Reproduction Code
Description
Hi! I found an issue while rendering a
.SchDocwith an applied sheet template.Some graphical primitives that belong to a
SchTemplaterecord are currently added to the document as normal top-level primitives. As a result, the renderer draws template-owned graphics as real schematic content. In my case this produced an extra Altium title block/frame rendered over the schematic, while the original Altium viewer does not show it there.The root cause seems to be in
SchDocReader: record type39is parsed asSchTemplate, but primitives whoseOWNERINDEXpoints to that template record are not associated with the template. They fall through intodocument.AddPrimitive(primitive).A minimal fix that worked locally:
SchDocReader.OWNERINDEXpointing to a knownSchTemplate, attach it to that template instead of adding it to the document top level.Pseudo-diff:
And SchTemplate can keep these separately:
This fixed the incorrect extra title block rendering without disabling the normal sheet frame rendering.
Steps to Reproduce
.SchDocfile that has an applied sheet template containing its own title block/frame graphics.SchDocReader.SchDocumentwith the SVG renderer.Expected Behavior
SchTemplateshould retain primitives owned by the template record, or those primitives should otherwise be excluded from normal document-level rendering.OWNERINDEXpointing to a template should not be treated as regular top-level schematic objects.Observed behavior:
Altium File Type
.SchDoc (Schematic Document)
Package Version
2.0.0
Operating System
Windows
Minimal Reproduction Code