This has been an all day effort, but unfortunately I am still stuck. I am trying to export an image without cropping the outer-most pixels. I thought by adjusting the crop region I could do this. But the archi-lab _view variable does not accept what I thought to be the adjusted view region. So I am back at step one. I am looking into writing something in the .api, but no luck so far.
This post includes this code, which based on a lot of research seems to be the only way to overcome this problem. I can include links to other posts on other forums on my journey so far.
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;
}
Capture_Image.dyn (89.0 KB)
If anyone has any idea about how to solve, I would love to hear about it.
My …dll attempt at code is here:
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;
//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);
//Get visible family element
//View elemView = GetBoundingBox(view);
//Turn on crop box and its visibility
using (Transaction tr = new Transaction(doc))
{
tr.Start("Transform crop view");
view.CropBoxActive = true;
view.CropBoxVisible = true;
//Create bounding box objects
BoundingBoxXYZ crop = view.CropBox;
BoundingBoxXYZ detailBox = view.get_BoundingBox(null);
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;
//Transforming the current active view crop box
view.CropBox = extendedCrop;
tr.Commit();
}
return Result.Succeeded;
}
}
}
Okay, so after a few too many hours at this. I figured this out, and in the process found some pretty odd behavior. The Views.SetCropBox node seems to be working as expected, however, when I tried to create a new bounding box using the BoundingBox.ByCorners node, the Views.SetCropBox node would not accept this input. So I had to recreate the bounding box by using the BoundingBox.ToPolySurface node and then create a new bounding box from that.
I am pretty happy with this result. Can I elevate this problem with the BoundingBox.ByCorners node to anyone? Seems like it is probably an easy bug to fix.