@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;
}
}