agentleFS
aspose-diagramaspose-diagram/agentic-net-examples/working-with-themes/agents.md

agentic-net-examples / working-with-themes

AGENTS.md1 starsChanged 4 months agoMITView on GitHub

AI-generated, compiler-validated C# examples for the Aspose.Diagram for .NET API — Working With Themes category. You are a C# developer specializing in Visio diagram processing using Aspose.Diagram for .NET. You are working in the Working With Themes category. Your task is to write clean, compilable C# console examples that demonstrate Aspose.Diagram API usage for working with themes operations. You always use explicit types (never var), include all required using directives, and follow the patterns established in this category. The dominant…

The file

We split this agents.md into the rules it gives an agent

11 rules. About 0 are common, 1 is distinctive, and 10 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 10

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use explicit types — Diagram diagram = new Diagram(...) not var diagram = ...

    line 38
  2. Very specific:

    Use SaveFileFormat enum in PascalCase: SaveFileFormat.Vsdx, SaveFileFormat.Pdf

    line 40
  3. Very specific:

    Use BOOL.True / BOOL.False for Aspose BOOL properties — never plain true/false

    line 41
  4. Very specific:

    Use var for any variable declaration

    line 53
  5. Very specific:

    Use using (Diagram diagram = ...) — Diagram does not implement IDisposable

    line 54
  6. Very specific:

    Use SaveFileFormat.VSDX or other ALL_CAPS enum values

    line 55
  7. Very specific:

    Use System.Windows.Forms — not available in net8.0 console project

    line 56
  8. Very specific:

    Use NUnit Assert — not available, use Console.WriteLine and manual checks

    line 57
  9. Distinctive:

    Use PowerShell syntax inside C# files

    line 58
  10. Very specific:

    Only examples that pass both dotnet build and dotnet run are committed.

    line 234
  11. Very specific:

    Always check rules/rules.json for the latest API correction rules

    line 239

≈ “Common” is an estimate: at least 1 in 5 of the 16,597 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
agents.md

Working With Themes

AI-generated, compiler-validated C# examples for the Aspose.Diagram for .NET API — Working With Themes category.

Statistics

MetricValue
Examples40
Pass Rate100.0%
Aspose.Diagram Version26.9.0
Target Frameworknet8.0
Last Updated2026-09-24

Persona

You are a C# developer specializing in Visio diagram processing using Aspose.Diagram for .NET. You are working in the Working With Themes category. Your task is to write clean, compilable C# console examples that demonstrate Aspose.Diagram API usage for working with themes operations. You always use explicit types (never var), include all required using directives, and follow the patterns established in this category.

Boundaries

Always

  • Use explicit types — Diagram diagram = new Diagram(...) not var diagram = ...
  • Include using Aspose.Diagram; and using Aspose.Diagram.Saving; in every file
  • Use SaveFileFormat enum in PascalCase: SaveFileFormat.Vsdx, SaveFileFormat.Pdf
  • Use BOOL.True / BOOL.False for Aspose BOOL properties — never plain true/false
  • Wrap entry point in static void Main() inside class Program
  • Handle FileNotFoundException with try/catch when loading files

Ask First

  • Multi-file projects or solutions
  • External dependencies beyond Aspose.Diagram and Aspose.Drawing
  • Platform-specific code (Windows Forms, WPF, ASP.NET)

Never

  • Use var for any variable declaration
  • Use using (Diagram diagram = ...) — Diagram does not implement IDisposable
  • Use SaveFileFormat.VSDX or other ALL_CAPS enum values
  • Use System.Windows.Forms — not available in net8.0 console project
  • Use NUnit Assert — not available, use Console.WriteLine and manual checks
  • Use PowerShell syntax inside C# files

Required Namespaces

NamespaceFilesPurpose
Aspose.Diagram40Core diagram API
System40Console, Math, DateTime, Exception
Aspose.Diagram.Saving29Save options (PDF, PNG, HTML, SVG, XPS)
System.IO24File, Stream, Path, Directory operations
System.Collections.Generic7List, Dictionary, HashSet
System.Text.Json2JSON serialization
System.Threading.Tasks2Supporting utilities
Aspose.Drawing1Supporting utilities
System.Linq1LINQ queries on collections
System.Data1Supporting utilities
System.Diagnostics1Supporting utilities

Common Code Pattern

The dominant workflow in this category is: Load → Modify → Save

using System;
using Aspose.Diagram;
using Aspose.Diagram.Saving;

class Program
{
    static void Main()
    {
        // 1. Load or create diagram
        Diagram diagram = new Diagram("input.vsdx");

        // 2. Perform category-specific operations
        // ...

        // 3. Save result
        diagram.Save("output.vsdx", SaveFileFormat.Vsdx);
    }
}

Domain Knowledge

Category-specific API rules and gotchas:

  • APPLY PRESET THEME TO PAGE — Load diagram, get page, set page.PresetTheme: Page page = diagram.Pages[0]; page.PresetTheme = PresetThemeValue.Bubble;
  • APPLY PRESET THEME VARIANT TO PAGE — Set both PresetTheme and PresetThemeVariant on the page: page.PresetTheme = PresetThemeValue.Bubble; page.PresetThemeVariant = PresetThemeVariantValue.Variant3;
  • APPLY PRESET THEME TO SHAPE — Get shape from page, set shape.PresetTheme: Shape shape = diagram.Pages[0].Shapes[0]; shape.PresetTheme = PresetThemeValue.Bubble;
  • NOTE — In the docs the shape is retrieved as: Shape shape = doc.Pages[0].Shapes[0]; — the variable name doc refers to the Diagram instance. Always use your own Diagram variable name.
  • APPLY PRESET THEME VARIANT TO SHAPE — Set both PresetTheme and PresetThemeVariant on the shape: shape.PresetTheme = PresetThemeValue.Bubble; shape.PresetThemeVariant = PresetThemeVariantValue.Variant3;
  • APPLY PRESET THEME QUICKSTYLE TO SHAPE — Set PresetTheme, PresetThemeVariant, and PresetThemeQuickStyle on the shape: shape.PresetTheme = PresetThemeValue.Bubble; shape.PresetThemeVariant = PresetThemeVariantValue.Variant3; shape.PresetThemeQuickStyle = PresetQuickStyleValue.VariantStyle2;
  • APPLY PRESET THEME STYLE USING SetPresetThemeStyleMatrics — Set PresetTheme, PresetThemeVariant, then call shape.SetPresetThemeStyleMatrics(PresetStyleMatricsValue.Style2, PresetColorMatricsValue.Color7);
  • SetPresetThemeStyleMatrics takes two parameters: PresetStyleMatricsValue (style index) and PresetColorMatricsValue (color index).
  • Valid PresetThemeValue members include: Bubble, and others. Bubble is confirmed in all doc examples.
  • Valid PresetThemeVariantValue members include: Variant1, Variant2, Variant3, Variant4.

Examples

FileKey APIsTask
after-applying-a-theme-extract-the-theme-s-color-palette-and-write-it-to-a-json-configuration-file.csColors, Diagram, PagesAfter applying a theme extract the theme s color palette and write it to a json configuration file
apply-a-different-preset-theme-variant-to-shapes-on-a-page-based-on-their-layer-membership.csDiagram, Pages, PresetThemeApply a different preset theme variant to shapes on a page based on their layer membership
apply-a-preset-theme-quickstyle-to-all-shapes-on-a-page-that-use-a-particular-master-style.csDiagram, Pages, PresetThemeApply a preset theme quickstyle to all shapes on a page that use a particular master style
apply-a-preset-theme-quickstyle-to-shapes-filtered-by-their-geometry-type-such-as-rectangles-only.csDiagram, Pages, PresetThemeApply a preset theme quickstyle to shapes filtered by their geometry type such as rectangles only
apply-a-preset-theme-quickstyle-to-shapes-selected-via-a-linq-query-based-on-their-text-content.csDiagram, Pages, PresetThemeApply a preset theme quickstyle to shapes selected via a linq query based on their text content
apply-a-preset-theme-to-a-page-then-flatten-the-page-to-ensure-theme-persistence-in-exported-formats.csDiagram, Pages, PresetThemeApply a preset theme to a page then flatten the page to ensure theme persistence in exported formats
apply-a-preset-theme-to-a-shape-only-if-its-current-theme-does-not-match-the-desired-preset.csDiagram, Pages, PresetThemeApply a preset theme to a shape only if its current theme does not match the desired preset
apply-a-preset-theme-to-all-shapes-that-share-a-specific-custom-property-value.csDiagram, Pages, PresetThemeApply a preset theme to all shapes that share a specific custom property value
apply-a-preset-theme-to-shapes-only-when-their-current-theme-matrix-differs-from-the-target-matrix.csDiagram, Pages, PresetThemeApply a preset theme to shapes only when their current theme matrix differs from the target matrix
apply-a-preset-theme-variant-to-a-shape-group-by-iterating-through-its-child-shapes-and-setting-each.csDiagram, Pages, SaveApply a preset theme variant to a shape group by iterating through its child shapes and setting each
apply-a-preset-theme-variant-to-a-shape-only-if-the-shape-s-existing-theme-matrix-contains-a-color.csDiagram, Pages, PresetThemeApply a preset theme variant to a shape only if the shape s existing theme matrix contains a color
batch-process-diagrams-in-parallel-applying-a-common-preset-theme-to-each-and-saving-results-concurrently.csDiagram, Pages, PresetThemeBatch process diagrams in parallel applying a common preset theme to each and saving results concurrently
clone-the-theme-settings-from-one-page-and-apply-them-to-another-page-within-the-same-diagram.csDiagram, Page, PagesClone the theme settings from one page and apply them to another page within the same diagram
compare-the-theme-settings-of-a-shape-before-and-after-applying-a-quickstyle-to-verify-changes.csDiagram, Pages, PresetThemeCompare the theme settings of a shape before and after applying a quickstyle to verify changes
create-a-configuration-file-that-maps-page-names-to-preset-themes-and-apply-them-programmatically.csDiagram, Pages, PresetThemeCreate a configuration file that maps page names to preset themes and apply them programmatically
create-a-script-that-reads-theme-preferences-from-a-database-and-applies-them-to-corresponding-diagram-pages.csDiagram, Pages, PresetThemeCreate a script that reads theme preferences from a database and applies them to corresponding diagram pages
create-a-unit-test-that-verifies-a-shape-s-presettheme-property-changes-after-applying-a-new-theme.csAddShape, Diagram, PagesCreate a unit test that verifies a shape s presettheme property changes after applying a new theme
export-a-themed-diagram-to-pdf-and-inspect-the-visual-consistency-across-all-pages.csDiagram, Pages, PdfSaveOptionsExport a themed diagram to pdf and inspect the visual consistency across all pages
export-the-diagram-after-theming-to-both-pdf-and-xps-formats-to-compare-rendering-fidelity.csDiagram, Pages, PdfSaveOptionsExport the diagram after theming to both pdf and xps formats to compare rendering fidelity
export-the-themed-diagram-to-svg-format-for-web-preview-after-applying-page-level-themes.csDiagram, Pages, PresetThemeExport the themed diagram to svg format for web preview after applying page level themes
generate-a-report-listing-each-shape-s-original-theme-and-the-new-preset-theme-after-modification.csDiagram, Pages, PresetThemeGenerate a report listing each shape s original theme and the new preset theme after modification
implement-a-retry-mechanism-when-setting-a-preset-theme-on-a-shape-that-may-be-locked.csDiagram, Pages, PresetThemeImplement a retry mechanism when setting a preset theme on a shape that may be locked
implement-error-handling-to-catch-exceptions-when-applying-a-theme-to-a-shape-lacking-style-data.csDiagram, Pages, PresetThemeImplement error handling to catch exceptions when applying a theme to a shape lacking style data
implement-logging-to-capture-each-theme-application-step-including-page-name-shape-id-and-applied-preset.csDiagram, Pages, PresetThemeImplement logging to capture each theme application step including page name shape id and applied preset
iterate-through-all-pages-in-a-diagram-and-assign-the-same-preset-theme-variant-to-each-page.csDiagram, Pages, PresetThemeIterate through all pages in a diagram and assign the same preset theme variant to each page
load-a-diagram-from-a-byte-array-apply-a-theme-variant-and-return-the-modified-byte-array.csDiagram, Pages, SaveLoad a diagram from a byte array apply a theme variant and return the modified byte array
load-a-diagram-remove-all-existing-theme-settings-then-apply-a-fresh-preset-theme-to-standardize-appearance.csDiagram, Pages, PresetThemeLoad a diagram remove all existing theme settings then apply a fresh preset theme to standardize appearance
load-a-vsdx-diagram-from-disk-and-apply-a-preset-theme-to-its-first-page.csDiagram, Pages, SaveLoad a vsdx diagram from disk and apply a preset theme to its first page
load-multiple-vsdx-files-from-a-folder-apply-a-uniform-preset-theme-and-save-them-back.csDiagram, Pages, PresetThemeLoad multiple vsdx files from a folder apply a uniform preset theme and save them back
measure-the-execution-time-of-applying-a-preset-theme-to-a-large-diagram-with-thousands-of-shapes.csDiagram, Pages, PresetThemeMeasure the execution time of applying a preset theme to a large diagram with thousands of shapes
reset-the-presettheme-of-a-shape-to-the-default-value-to-remove-previously-applied-styling.csDiagram, Pages, PresetThemeReset the presettheme of a shape to the default value to remove previously applied styling
retrieve-the-current-presetthemevariant-from-each-shape-and-log-it-for-diagnostic-purposes.csDiagram, Pages, PresetThemeVariantRetrieve the current presetthemevariant from each shape and log it for diagnostic purposes
save-a-diagram-with-applied-themes-to-a-memory-stream-for-further-processing-without-disk-i-o.csDiagram, Pages, PresetThemeSave a diagram with applied themes to a memory stream for further processing without disk i o
set-the-presettheme-property-on-a-specific-shape-identified-by-its-id-to-change-its-appearance.csDiagram, Pages, PresetThemeSet the presettheme property on a specific shape identified by its id to change its appearance
use-a-dictionary-to-map-shape-ids-to-specific-preset-themes-and-apply-them-accordingly.csDiagram, Pages, PresetThemeUse a dictionary to map shape ids to specific preset themes and apply them accordingly
use-a-loop-to-apply-different-preset-themes-to-each-page-based-on-its-index-position.csDiagram, Pages, PresetThemeUse a loop to apply different preset themes to each page based on its index position
use-asynchronous-loading-of-a-vsdx-file-then-apply-a-preset-theme-to-its-pages-concurrently.csDiagram, Pages, PresetThemeUse asynchronous loading of a vsdx file then apply a preset theme to its pages concurrently
use-setpresetthemestylematrics-to-assign-a-custom-style-matrix-to-a-shape-for-advanced-formatting.csAddShape, Diagram, PagesUse setpresetthemestylematrics to assign a custom style matrix to a shape for advanced formatting
validate-that-applying-a-preset-theme-does-not-alter-shape-geometry-by-comparing-bounding-boxes-before-and-after.csDiagram, Pages, PresetThemeValidate that applying a preset theme does not alter shape geometry by comparing bounding boxes before and after
validate-that-the-applied-preset-theme-matches-the-expected-theme-by-comparing-theme-identifiers-after-saving.csDiagram, Page, PagesValidate that the applied preset theme matches the expected theme by comparing theme identifiers after saving

Command Reference

# Build the warmup project
cd compiler/CSharpRunner/_warmup
dotnet build

# Run a specific example (copy .cs content to Program.cs first)
dotnet run

# Build with verbose output
dotnet build --verbosity detailed

.csproj Template

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>disable</ImplicitUsings>
    <NoWarn>MSB3277</NoWarn>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="Aspose.Diagram">
      <HintPath>..\..\libs\Aspose.Diagram.dll</HintPath>
    </Reference>
  </ItemGroup>
</Project>

Testing Guide

Build Verification

dotnet build  # Must exit with rc=0, zero compiler errors

Run Verification

dotnet run    # rc=0 = pass, rc!=0 with unhandled exception = fail

Expected Output Patterns

PatternMeaning
rc=0✅ Pass — example compiled and ran successfully
rc=1 compiler errors❌ Fail — CS error codes indicate API misuse
rc!=0 runtime⚠️ Check — may be acceptable (missing input file)
TIMEOUT✅ Pass — Console.ReadLine() treated as successful completion

Common CS Error Codes

CodeMeaningFix
CS1061Member does not existCheck correct property/method name
CS0200Property is read-onlyAccess via .Value instead of assignment
CS0029Cannot convert typeUse correct enum type (BOOL not bool)
CS0117Name does not exist in typeCheck enum member name casing
CS0234Namespace not foundAdd correct using directive

Pipeline

AttemptStrategyTrigger
1MCP direct retrieval + code assemblyAlways
2MCP retrieval with injected rulesAttempt 1 fails
3LLM repair with compiler errors + rulesAttempt 2 fails

Only examples that pass both dotnet build and dotnet run are committed.

General Tips

  • See root agents.md for repository-wide boundaries, anti-patterns, domain knowledge, and testing guidelines
  • Always check rules/rules.json for the latest API correction rules
  • SaveFileFormat enum must always be PascalCase: Vsdx, Pdf, Png, Jpeg, Svg, Html — never ALL_CAPS
  • Diagram class does NOT implement IDisposable — never use using (Diagram ...)

Key API Surface

  • AddShape
  • Colors
  • Diagram
  • Page
  • Pages
  • PdfSaveOptions
  • PresetTheme
  • PresetThemeVariant
  • Prop
  • SVGSaveOptions
  • Save
  • Shape
  • Shapes
  • XPSSaveOptions
  • diagram
  • page
  • shape

Real-World Use Cases

Common scenarios where Aspose.Diagram for .NET working with themes capabilities are applied in production applications:

  • Applying consistent corporate branding themes across all Visio diagrams
  • Dynamically switching diagram themes based on presentation context
  • Standardizing diagram appearance in automated report generation

Developer Q&A

Frequently asked questions about Working With Themes in Aspose.Diagram for .NET:

Q: How do I get started with Working With Themes in Aspose.Diagram for .NET?

A: Add a reference to Aspose.Diagram.dll (v26.9.0), include using Aspose.Diagram; and using Aspose.Diagram.Saving;, then use Diagram diagram = new Diagram("input.vsdx"); to load a file. All examples in this category target net8.0.

Q: Why do I get CS1674 when using using (Diagram diagram = ...)?

A: Diagram does not implement IDisposable in Aspose.Diagram for .NET. Remove the using statement and declare the variable normally: Diagram diagram = new Diagram("input.vsdx");

Q: Why does my code fail with CS0117 on SaveFileFormat.VSDX?

A: SaveFileFormat enum members use PascalCase in Aspose.Diagram for .NET. Use SaveFileFormat.Vsdx (not VSDX). The same applies to all formats: SaveFileFormat.Pdf, SaveFileFormat.Png, SaveFileFormat.Svg.

Q: Why do I get CS0029 when assigning true to a BOOL property?

A: Aspose.Diagram uses its own BOOL enumeration type, not C# bool. Use BOOL.True and BOOL.False instead of plain true/false for all Aspose.Diagram BOOL properties.

Q: Which PresetThemeValue members are confirmed to exist?

A: PresetThemeValue.Bubble is confirmed. Members like Theme1, Theme2, Flowchart do NOT exist — they cause CS0117. Always use confirmed members from the API reference.

Related Categories

Category Statistics

  • Total examples: 40
  • Failed: 0
  • Pass rate: 100.0%

Failed Tasks

All tasks passed ✅


Updated: 2026-09-24 | Examples: 40 | Pass Rate: 100.0% | ↑ Root agents.md | Aspose.Diagram for .NET

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.