Skip to content

Commit

Permalink
Adds SampleCsExportSvgWithDialog example for exporting an svg using t…
Browse files Browse the repository at this point in the history
…he print dialog.
  • Loading branch information
travisserio committed Aug 19, 2024
1 parent f52be25 commit 664bdfc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Xml" />
<Reference Include="Xfinium.Pdf.Win">
<HintPath>C:\Program Files\Rhino 7\Plug-ins\Xfinium.Pdf.Win.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -83,6 +84,7 @@
<Compile Include="SampleCsDrawPin.cs" />
<Compile Include="SampleCsDuplicateObjectFromNameTag.cs" />
<Compile Include="SampleCsExportDXF.cs" />
<Compile Include="SampleCsExportSvgWithDialog.cs" />
<Compile Include="SampleCsExtractInflectionPoints.cs" />
<Compile Include="SampleCsExtractMinMaxRadiusPoints.cs" />
<Compile Include="SampleCsExtrudeMeshFace.cs" />
Expand Down
59 changes: 59 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCsExportSvgWithDialog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using Eto.Forms;
using Rhino;
using Rhino.Commands;
using Rhino.UI.Forms;
using Rhino.UI;
using Command = Rhino.Commands.Command;

namespace SampleCsCommands
{
/// <summary>
/// Exports the contents of the 3dm file to an svg via the print dialog.
/// The print dialog is automatically configured for SVG exporting.
/// </summary>
public class SampleCsExportSvgWithDialog : Command
{
public override string EnglishName => "SampleCsExportSvgWithDialog";

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{

//Create an ETO file save dialog
var save_dialog = new Eto.Forms.SaveFileDialog()
{
CheckFileExists = false,
Title = "Export SVG"
};

//Add an SVG filter to the save dialog
save_dialog.Filters.Add(new FileFilter("Export", "*.svg"));
save_dialog.CurrentFilter = save_dialog.Filters[0];

//Show the file save dialog
var result = save_dialog.ShowDialog(RhinoEtoApp.MainWindow);
if (result != DialogResult.Ok)
return Result.Cancel;

//The previous Print dialog settings are stored in the Commands.rhp plug-in. We can get its previous settings directly from the plug-in.
Guid.TryParse("02bf604d-799c-4cc2-830e-8d72f21b14b7", out var commands_id);

//Show the Print Dialog configured for SVG export.
var svg_export_view_capture_settings = PrintDialogUi.EtoExportSvg(doc.RuntimeSerialNumber, PersistentSettings.FromPlugInId(commands_id));

if (svg_export_view_capture_settings == null)
return Result.Cancel;

//Get the SVG Xml settings from the ViewCapture.
var capture_to_svg = Rhino.Display.ViewCapture.CaptureToSvg(svg_export_view_capture_settings);
if (capture_to_svg == null)
return Result.Cancel;

//Save the xml to disk
capture_to_svg.Save(save_dialog.FileName);


return Result.Success;
}
}
}

0 comments on commit 664bdfc

Please sign in to comment.