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

Workspace image cropping issue #15317

Open
andydandy74 opened this issue Jun 15, 2024 · 3 comments
Open

Workspace image cropping issue #15317

andydandy74 opened this issue Jun 15, 2024 · 3 comments
Labels

Comments

@andydandy74
Copy link
Contributor

Dynamo Version

DynamoCore 3.0.3.7597

Host

DynamoRevit 3.0.3.4605 (Revit 2025.1)
Issue can be reproduced in earlier versions as well, though.

Operating System

Windows 11

What did you do?

Exported an image of a graph

What did you expect to see?

The image containing the entire graph

What did you see instead?

The exported image is cropped slightly on the right:
cropping issue

What packages or external references (if any) were used?

Not relevant for this issue

Stack Trace


Details

Steps to reproduce:

  • Place a node
  • Place a text note to the right of the node
  • Enter enough text for the automatic linebreak to kick in - this is the key part: if the text note only contains one line the issue doesn't occur
  • Group the node and the text note
  • Export the workspace image
Copy link

Thank you for submitting the issue to us. We are sorry to see you get stuck with your workflow. While waiting for our team member to respond, please feel free to browse our forum at https://forum.dynamobim.com/ for more Dynamo related information.

@avidit avidit added the tracked label Jun 17, 2024
@dynamo-ci-user dynamo-ci-user moved this from Triage to Todo in Dynamo Issues Jun 17, 2024
@johnpierson
Copy link
Member

johnpierson commented Jan 22, 2025

I am able to reproduce the issue, and I wanted to add that it seems to occur with certain nodes. In my case a node with unfulfilled inputs. A simple code block does not let it happen.

Image

and some other tests:

Unfulfilled Input
Image

Node in Default State
Image

Node In Error State
Image

Another Unfulfilled Input
Image

Node with Error and info Bubble Showing:

Image

@johnpierson
Copy link
Member

And I believe this is the method that needs to be looked at:

private RenderTargetBitmap GetRender()
{
RenderTargetBitmap rtb;
try
{
var initialized = false;
var bounds = new Rect();
double minX = 0.0, minY = 0.0;
var dragCanvas = WpfUtilities.ChildOfType<DragCanvas>(this);
var childrenCount = VisualTreeHelper.GetChildrenCount(dragCanvas);
for (int index = 0; index < childrenCount; ++index)
{
ContentPresenter contentPresenter = VisualTreeHelper.GetChild(dragCanvas, index) as ContentPresenter;
if (contentPresenter.Children().Count() < 1) continue;
var firstChild = VisualTreeHelper.GetChild(contentPresenter, 0);
switch (firstChild.GetType().Name)
{
case "NodeView":
case "NoteView":
case "AnnotationView":
break;
// Until we completely removed InfoBubbleView (or fixed its broken
// size calculation), we will not be including it in our size
// calculation here. This means that the info bubble, if any, will
// still go beyond the boundaries of the final PNG file. I would
// prefer not to add this hack here as it introduces multiple issues
// (including NaN for Grid inside the view and the fix would be too
// ugly to type in). Suffice to say that InfoBubbleView is not
// included in the size calculation for screen capture (work-around
// should be obvious).
//
// case "InfoBubbleView":
// child = WpfUtilities.ChildOfType<Grid>(child);
// break;
// We do not take anything other than those above
// into consideration when the canvas size is measured.
default:
continue;
}
// Determine the smallest corner of all given visual elements on the
// graph. This smallest top-left corner value will be useful in making
// the offset later on.
//
var childBounds = VisualTreeHelper.GetDescendantBounds(contentPresenter as Visual);
minX = childBounds.X < minX ? childBounds.X : minX;
minY = childBounds.Y < minY ? childBounds.Y : minY;
childBounds.X = (double)(contentPresenter as Visual).GetValue(Canvas.LeftProperty);
childBounds.Y = (double)(contentPresenter as Visual).GetValue(Canvas.TopProperty);
if (initialized)
{
bounds.Union(childBounds);
}
else
{
initialized = true;
bounds = childBounds;
}
}
// Nothing found in the canvas, bail out.
if (!initialized) return null;
// Add padding to the edge and make them multiples of two (pad 10px on each side).
bounds.Width = 20 + ((((int)Math.Ceiling(bounds.Width)) + 1) & ~0x01);
bounds.Height = 20 + ((((int)Math.Ceiling(bounds.Height)) + 1) & ~0x01);
var currentTransformGroup = WorkspaceElements.RenderTransform as TransformGroup;
WorkspaceElements.RenderTransform = new TranslateTransform(10.0 - bounds.X - minX, 10.0 - bounds.Y - minY);
WorkspaceElements.UpdateLayout();
rtb = new RenderTargetBitmap(((int)bounds.Width),
((int)bounds.Height), 96, 96, PixelFormats.Default);
rtb.Render(WorkspaceElements);
WorkspaceElements.RenderTransform = currentTransformGroup;
}
catch (Exception)
{
throw;
}
return rtb;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Todo
Development

No branches or pull requests

3 participants