Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Export Image is cutting few pixels from image corners

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
alexpaduroiu
873 Views, 8 Replies

Export Image is cutting few pixels from image corners

Hello there!

 

I have a small problem regarding Decoument.ExportImage(ImageExportOptions options);

 

I am trying to export a set of drafting views but somehow the generated images cuts the views edges.

 

the Images:

imageNotFull.png

 

And this image has the bottom part not visible at all:

ImageNotFull2.png

 

The cut is very small but very frustrating because I can't make it a whole or even offset the element to fit the images.

 

Image Export Options used:

 

ImageExportOptions imgExportOpts = new ImageExportOptions()
{
ZoomType = ZoomFitType.FitToPage,
PixelSize = 500,
FilePath = rbrImagesDirectory + @"\",
FitDirection = FitDirectionType.Vertical,
HLRandWFViewsFileType = ImageFileType.PNG,
ShadowViewsFileType = ImageFileType.PNG,
ImageResolution = ImageResolution.DPI_72,
ShouldCreateWebSite = false,
};

imgExportOpts.ExportRange = ExportRange.SetOfViews

 

I have tried to modify FitDirectionType.Horizontal and this makes it worse than it is now by cutting the bottom portion even more -> in that case for the first image, the bottom part of the bar is not visible at all.

 

The image doesn't have such a big cut in the edges but it will be nice to have some spaces there or at least to see the parts 🙂

 

Please let me know if there is any way to zoom out the element or move it in order to be arranged better in image.

Thank you!

8 REPLIES 8
Message 2 of 9
jeremytammik
in reply to: alexpaduroiu

Please submit a minimal reproducible case that I can share with the development team for further analysis:

  

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

  

Thank you!

 



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

Message 3 of 9
alexpaduroiu
in reply to: jeremytammik

Sorry for the very very late reply. 😓

 

I was caught with other projects and lots of work.

 

Well I have solved the problem!

 

The problem was with the drafting view I was trying to export. After creating a group of details in the Drafting view, somehow the outline of the view wasn't big enough to include my details. don't know sure why but what i have done to resolve the problem was the following:

 

drafting.CropBoxActive = true;
drafting.CropBoxVisible = true;

private static void ExtendViewCrop(View drafting, Group detail)
        {
            BoundingBoxXYZ crop = (drafting!= null ? drafting.CropBox : null);
            if (crop == null || crop.Max == null || crop.Min == null || crop.Transform == null || detail == null)
                return;
            BoundingBoxXYZ detailBox = detail.get_BoundingBox(drafting);
            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;
            drafting.CropBox = extendedCrop;
        }

 

So basically extending the view crops max and min on their direction with a small value so the detail will fit in my drafting.

 

I am sure that there are lots of other better options doing this, but for now it made the trick. Of course I am opened to more solutions:D

Message 4 of 9

Looks good to me! Thank you for sharing the solution.

   

Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 5 of 9
Iev60047
in reply to: alexpaduroiu

Is there a .cs file someone could share with me of this completed code? I am trying to get the same code to run. Thank you!

 

Well, I am still struggling, but I think I know better questions: what class is the drafting variable? If I defined view instead of drafting would I write:

 

View view = doc.ActiveView;

 

and should I define this before the private static void ExtendVeiwCrop(View view) function?

Message 6 of 9
Iev60047
in reply to: alexpaduroiu

I feel like I am getting closer, but still no luck. I am getting a Modification outside transaction attempt. I tried handling it by wrapping my one adjustment to the model (adjusting the crop box), but that didn't help.

 

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;


namespace AdjustCropView
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application 
            UIApplication uiapp = commandData.Application;

            //Get document objects
            Document doc = uiapp.ActiveUIDocument.Document;

            //Get active view
            View view = doc.ActiveView;

            //Turn on crob box and its visibility
            view.CropBoxActive = true;
            view.CropBoxVisible = true;

            //Create bounding box objects
            BoundingBoxXYZ crop = view.CropBox;
            BoundingBoxXYZ detailBox = view.get_BoundingBox(view);
            BoundingBoxXYZ extendedCrop = new BoundingBoxXYZ();
            extendedCrop.Transform = crop.Transform;

            //Modifying the extended crop box
            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;

            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Transform crop view");

                view.CropBox = extendedCrop;

                tr.Commit();
            }


            return Result.Succeeded;

        }

    }
}
Message 7 of 9

@Iev60047 You are getting an error that you are trying to make a change to a revit model outside of a transaction. All changes made to a model need to happen inside a transaction. 

 

My guess is that you enabling the crop box and showing it is the issue... (It is a change to the model)

 

Try this:

 

 

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;


namespace AdjustCropView
{
    [Transaction(TransactionMode.Manual)]
    [Regeneration(RegenerationOption.Manual)]
    public class Class1 : IExternalCommand
    {

        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //Get application 
            UIApplication uiapp = commandData.Application;

            //Get document objects
            Document doc = uiapp.ActiveUIDocument.Document;


            using (Transaction tr = new Transaction(doc))
            {
                tr.Start("Transform crop view");
				
			
	            //Get active view
				View view = doc.ActiveView;
			
				//Turn on crob box and its visibility
				view.CropBoxActive = true;
				view.CropBoxVisible = true;

				//Create bounding box objects
				BoundingBoxXYZ crop = view.CropBox;
				BoundingBoxXYZ detailBox = view.get_BoundingBox(view);
				BoundingBoxXYZ extendedCrop = new BoundingBoxXYZ();
				extendedCrop.Transform = crop.Transform;

				//Modifying the extended crop box
				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;

                tr.Commit();
            }


            return Result.Succeeded;

        }

    }
}

 

 

 

The definition of insanity is doing the same thing over and over again and expecting different results
Message 8 of 9
Iev60047
in reply to: alexpaduroiu

@EATREVITPOOPCAD Thanks again. I enclosed that in. In the meantime I figured there's no way that my code will work because 

 

BoundingBoxXYZ detailBox = view.get_BoundingBox(view);

 

 

is not going to do anything. I need to get a bounding box (I assume this will assume the same boundary as zoomtofit) of the active elements in the view. This means I need to filter for visible element Id's (I think). 

 

            //Create empty variable to contain element Id's. 
            ElementId elemId = null;

            //Get visible element Id's using filtered collector.
            FilteredElementCollector collector = new FilteredElementCollector(doc, elemId);

 

 

This code is not working and I'm stumped again. Learning a lot though! I feel closer to the solution. Also, as a side note, I know that I want only 2D views, so I think the class BoundingBoxUV may be more appropriate for my application, but I'll be fine if I can get it to work with the class BoundingBoxXYZ.

 

Edit: I also find it odd that I can't look up get_BoundingBox up in the Revit API doc. Am I missing another piece of documentation this filter/constructor exists on?

Message 9 of 9
EATREVITPOOPCAD
in reply to: Iev60047

 

Try this

view.get_BoundingBox(null)

 

And here is the documentation

https://www.revitapidocs.com/2016/def2f9f2-b23a-bcea-43a3-e6de41b014c8.htm

The definition of insanity is doing the same thing over and over again and expecting different results

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community