Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FishPrint of svg #395

Open
ChenChihYuan opened this issue Feb 19, 2025 · 3 comments
Open

FishPrint of svg #395

ChenChihYuan opened this issue Feb 19, 2025 · 3 comments
Labels
question Further information is requested

Comments

@ChenChihYuan
Copy link

Motivation

Vectorized format has better detail preservation capability than rasterized Bitmap.

When viewing the pictures either in Dashboard or TT-Design Explorer, I find it's better if Tunny can also support svg format.

Description

I dived into code, and found out the FishPrint is casted from Bitmap.

However, I think there's need for FishPrint accepting Svg as well, since there's this https://developer.rhino3d.com/api/rhinocommon/rhino.display.viewcapture/capturetosvg function.
Vectorized format has better detail preservation capability than rasterized Bitmap.

I hope this can be a feature supported in the future.

Alternatives (optional)

No response

Additional context (optional)

No response

@hrntsm
Copy link
Owner

hrntsm commented Feb 19, 2025

Hi @ChenChihYuan
Artifact also supports direct input of paths.
Is there a problem with creating your own svg and putting the path to it into Artifact?

@ChenChihYuan
Copy link
Author

Thanks @hrntsm , I am looking into it.

I do have some problems to create my own svg scripting component.
I know if I have this kind of code and the output attach as FishPrint, the component will be triggered(? each solution.

private void RunScript(ref object bitmap_0, ref object bitmap_1)
  {
      
      
      bitmap_0 = CaptureViewport()[0];
      bitmap_1 = CaptureViewport()[1];
  }



  List<Bitmap> CaptureViewport()
  {
      // RhinoView view = RhinoDoc.ActiveDoc.Views.ActiveView;
      
      List<Guid> viewNames = new List<Guid>();
      List<Bitmap> bitmaps = new List<Bitmap>();

      foreach (Rhino.Display.RhinoView view in RhinoDoc.ActiveDoc.Views)
      {
          // viewNames.Add(view.ActiveViewport.Id);
          Bitmap bitmap = view.CaptureToBitmap();
          bitmaps.Add(bitmap);
          
      }
      return bitmaps;
  
  }

Image

However,
I am trying to output svg and save it as following

private void RunScript(string folderPath, ref object a, ref object b)
    {
        // string fileName = "ViewportCapture.svg"; // Change filename as needed
        string fileName = $"ViewportCapture_{DateTime.Now:yyyyMMdd_HHmmss}.svg";
        a = CaptureViewportAsSvg(folderPath, fileName);
        b = Path.Combine(folderPath, fileName);
    }

    public static void CaptureViewportAsSvg(string folderPath, string fileName)
    {
        RhinoView view = RhinoDoc.ActiveDoc.Views.ActiveView;
        if (view == null)
        {
            RhinoApp.WriteLine("No active viewport found.");
            return null;
        }

        int width = 1920; // Set width
        int height = 1080; // Set height
        double dpi = 300;  // High resolution

        ViewCaptureSettings vcs = new ViewCaptureSettings(view, new System.Drawing.Size(width, height), dpi);
        vcs.DrawBackground = true; // Change to false for a transparent background
        vcs.ApplyDisplayModeThicknessScales =true; //Apply viewport display thickness settings
        vcs.WireThicknessScale = 0.3; // Adjust line thickness

        // Capture SVG as XmlDocument
        XmlDocument svg = Rhino.Display.ViewCapture.CaptureToSvg(vcs);
        if (svg == null)
        {
            RhinoApp.WriteLine("Failed to capture viewport as SVG.");
            return null;
        }

        // Ensure the folder exists
        if (!Directory.Exists(folderPath))
            Directory.CreateDirectory(folderPath);

        string filePath = Path.Combine(folderPath, fileName);

        // Save SVG file
        svg.Save(filePath);
        RhinoApp.WriteLine($"SVG saved: {filePath}");
    }

Image

I attach as such, so that artifact accepting the filePath, but it won't trigger svg script component I made above to fire each solution runs.
I couldn't find the svg files under .tunny_env/tmp but when it is a bitmap, there's no problem

Image

@hrntsm
Copy link
Owner

hrntsm commented Feb 21, 2025

@ChenChihYuan
I checked the behavior of specifying the path to the svg. Confirmed that if the file path could be specified, it would appear in Artifacts on the Dashboard.

After the svg is properly generated, check that the correct file path is specified.

Image

@hrntsm hrntsm added the question Further information is requested label Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants