Export Image cutting off edge pixels

Export Image cutting off edge pixels

Anonymous
Not applicable
1,839 Views
9 Replies
Message 1 of 10

Export Image cutting off edge pixels

Anonymous
Not applicable

I'm trying to export family type images from a family, but I'm getting the edge pixels cut off in my exported images. See the attached images.

 

This is what I currently have for my export image options

    img = ImageExportOptions()
    img.ZoomType = ZoomFitType.FitToPage
    img.PixelSize = size
    img.ImageResolution = ImageResolution.DPI_150
    img.FitDirection = FitDirectionType.Vertical
    img.ExportRange = ExportRange.SetOfViews
    img.SetViewsAndSheets(viewIds)
    img.HLRandWFViewsFileType = ImageFileType.PNG
    img.FilePath = filepath
    img.ShadowViewsFileType = ImageFileType.PNG

 

Any ideas for how to fix this?

0 Likes
1,840 Views
9 Replies
Replies (9)
Message 2 of 10

jeremytammik
Autodesk
Autodesk

This very question has already been discussed and resolved right here in the past:

 

https://forums.autodesk.com/t5/revit-api-forum/export-image-is-cutting-few-pixels-from-image-corners...

 

Please always search for existing answers before submitting a new thread.

 

Thank you!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 10

nikolay.gerasimov3SGFN
Participant
Participant

No, it has not. Please read the questions carefully before kicking off people. The problem is still there - pure ImageExport crops the elements on the borders. It is not always possible to adjust the crop region of the view (e.g. when one exports from a family), so when to expect a correction?

Message 4 of 10

jeremy_tammik
Alumni
Alumni

Thank you for the clarification and correction. Sorry, it was not my intention to kick anyone off, or kick anyone at all in any way. I am just trying to help as much as possible with very limited time and manpower. OK, well, DanBoghean supplied an almost complete reproducible case that I could pass on to the development team for analysis locally at their end. It would help if the code was included in an RVT macro together with the image to export, so they can just execute the macro in the debugger to reproduce the behaviour you describe:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Can you provide that? Thank you!

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 5 of 10

nikolay.gerasimov3SGFN
Participant
Participant

Please see the attachments

Message 6 of 10

Iev60047
Advocate
Advocate

I am struggling with the same problem, has there been any headway on this?

0 Likes
Message 7 of 10

jeremy_tammik
Alumni
Alumni

Did you see this alternative solution?

  

https://forums.autodesk.com/t5/revit-api-forum/export-image-is-cutting-few-pixels-from-image-corners...

  

I am not sure whether the two threads are actually discussing the same problem. IN any case the solution suggested there may be of use to you too.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 8 of 10

Iev60047
Advocate
Advocate

@jeremy_tammik Yes, I did! I have been trying to figure the code based on these two questions and some of the responding dialog, without any luck. I am trying to export an image within Revit families (e.g. air terminals) and even manually my image is getting cropped, so I am coming here to try and figure out a solution. The other question deals with detail groups. I don't have any detail groups. I modified the code, but I just feel like I am missing something big, should the modified code I am working on be part of a method like public Result Cropthebox(...)? I'm attaching the part I modified and then also the entire code I am working with: 

 

        View view = doc.ActiveView;

        view.CropBoxActive = true;
        view.CropBoxVisible = true;
        {
            BoundingBoxXYZ crop = (view != null ? view.CropBox : null);
            if (crop == null || crop.Max == null || crop.Min == null || crop.Transform == null)
                return;
            BoundingBoxXYZ detailBox = view.get_BoundingBox(view);
            BoundingBoxXYZ extendedCrop = new BoundingBoxXYZ();
            extendedCrop.Transform = crop.Transform;

            if (detailBox == null || detailBox.Max == null || detailBox.Min == null)
                return;

            extendedCrop.Max = detailBox.Max + (extendedCrop.Transform.BasisX + extendedCrop.Transform.BasisY / 2) * 0.03;
            extendedCrop.Min = detailBox.Min + (-extendedCrop.Transform.BasisX + -extendedCrop.Transform.BasisY / 2) * 0.03;
            view.CropBox = extendedCrop;
        }

 

And then 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.ApplicationServices;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using Autodesk.Revit.DB.Architecture;

//We will not be committing any changes to the model, so read only for the transaction mode.
[Transaction(TransactionMode.ReadOnly)]
public class Main : IExternalCommand
{
    public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
    {
        //Get application and document objects
        UIApplication uiapp = commandData.Application;
        Document doc = uiapp.ActiveUIDocument.Document;

        View view = doc.ActiveView;

        view.CropBoxActive = true;
        view.CropBoxVisible = true;
        {
            BoundingBoxXYZ crop = (view != null ? view.CropBox : null);
            if (crop == null || crop.Max == null || crop.Min == null || crop.Transform == null)
                return;
            BoundingBoxXYZ detailBox = view.get_BoundingBox(view);
            BoundingBoxXYZ extendedCrop = new BoundingBoxXYZ();
            extendedCrop.Transform = crop.Transform;

            if (detailBox == null || detailBox.Max == null || detailBox.Min == null)
                return;

            extendedCrop.Max = detailBox.Max + (extendedCrop.Transform.BasisX + extendedCrop.Transform.BasisY / 2) * 0.03;
            extendedCrop.Min = detailBox.Min + (-extendedCrop.Transform.BasisX + -extendedCrop.Transform.BasisY / 2) * 0.03;
            view.CropBox = extendedCrop;
        }

        //Setting up image export options to fit right around family object.
        ImageExportOptions imgExportOpts = new ImageExportOptions();
        {
            imgExportOpts.ZoomType = ZoomFitType.FitToPage;
            imgExportOpts.PixelSize = 256;
            imgExportOpts.FilePath = "C:/Users/iev60047/Documents/Test" + "/" + doc.Title + ".TIFF";
            imgExportOpts.FitDirection = FitDirectionType.Horizontal;
            imgExportOpts.HLRandWFViewsFileType = ImageFileType.TIFF;
            imgExportOpts.ShadowViewsFileType = ImageFileType.TIFF;
            imgExportOpts.ImageResolution = ImageResolution.DPI_150;
            imgExportOpts.ShouldCreateWebSite = false;
        };

        doc.ExportImage(imgExportOpts);

        //Returns success if programs runs well
        return Result.Succeeded;
    }




}

 

0 Likes
Message 9 of 10

jeremy_tammik
Alumni
Alumni

You say that even manually my image is getting cropped. That is good news. In that case, this is not an API issue, but a real end-user problem that affects all users. In that case, I would suggest reporting it to the product support group and requesting a fix to the end user product functionality, not the API. Resolving the issue in the end-user product interface will automatically resolve the API functionality as well. I suppose the Revit Architecture forum is the appropriate place to report the UI problem.

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 10 of 10

Iev60047
Advocate
Advocate
Great! @jeremy_tammik I'll make sure to forward this problem along to the product support group.
0 Likes