Skip to content

adding console write file name function#3965

Merged
swharden merged 5 commits intoScottPlot:mainfrom
aespitia:feature/aespitia/savedimageinfo
Jun 25, 2024
Merged

adding console write file name function#3965
swharden merged 5 commits intoScottPlot:mainfrom
aespitia:feature/aespitia/savedimageinfo

Conversation

@aespitia
Copy link
Contributor

adding requested functionality for writing the file path to the console, briefly looked at the clipboard request too, but it may be a little more involved for different systems, or have to introduce another library to abstract the clipboard, so, i didn't want to introduce a new dependency.

#3943

using ScottPlot;

Plot plt = new();
plt.Add.Signal(Generate.Sin());
plt.Add.Signal(Generate.Cos());

plt.SavePng("test.png", 600, 300).ConsoleWriteFilename();

@swharden
Copy link
Member

Thanks @aespitia! I think I'll rename ConsoleWriteFilename to ConsoleWritePath because the full path (not just the filename) will be shown. Also I think I can solve the clipboard issue by adding extension methods to the various control projects. I'll give that a quick go and merge shortly!

@swharden
Copy link
Member

Note: to get copy-to-clipboard to work in a console app you need to modify the .csproj file to target Windows, use Windows Forms libraries, and add the STAThread attribute to the main method like:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0-windows</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <IsPackable>false</IsPackable>
        <UseWindowsForms>true</UseWindowsForms>
    </PropertyGroup>
...
using ScottPlot.WinForms;

public static class Program
{
    [STAThread]
    public static void Main()
    {
        Plot plt = new();
        plt.Add.Signal(Generate.Sin());
        plt.Add.Signal(Generate.Cos());

        plt.SavePng("test.png", 600, 300).CopyToClipboard();
    }
}

@swharden swharden enabled auto-merge (squash) June 25, 2024 00:24
@swharden swharden merged commit d7313bd into ScottPlot:main Jun 25, 2024
@aespitia aespitia deleted the feature/aespitia/savedimageinfo branch June 25, 2024 13:26
KroMignon added a commit to KroMignon/ScottPlot that referenced this pull request Jun 26, 2024
* upstream/main:
  Fix interaction of axis panels when scale factor is more than 1 (ScottPlot#3994)
  Added ResetMinAndMaxValues() to DataLoggerSource.cs (ScottPlot#3993)
  CoordinateLine: add constructor overloads (ScottPlot#3987)
  Colormap.GetColors() (ScottPlot#3983)
  Added a constructor overload that accepts List<Coordinates> (ScottPlot#3982)
  Signal: improve support for IReadOnlyList<T> (ScottPlot#3978)
  Axes: improve sharpness of axis lines, tick marks, and grid lines (ScottPlot#3976)
  adding console write file name function (ScottPlot#3965)
  Color.ToColor()
  Sandbox: extend minimal API
  Sandbox: Create .NET API project
  SVG XML Updates (ScottPlot#3957)
  Repeat render if changes are made in invoked events (ScottPlot#3952)
  CI: autoformat
  Experimental DataLogger2 using a `CircularBuffer<T>` (ScottPlot#3946)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants