Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Complete beginner here in writing code for Revit. I am trying to run the following bit of code.
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;
}
In general when I see something like this, do I try and copy and paste the code to a macro within Revit (i.e. using SharpDevelop)? Or should I attempt to create a project in VisualStudio (i.e. building a .cs file and adding a .addin file). This seems like something so obvious it's not stated anywhere. I followed the tutorial here.
I tried building the following code in a project:
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 ExportImage
{
public class Class1
{
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;
}
}
}
But only ended up with plenty of errors when I tried to build. When someone else runs the above (first) snippet of code, how exactly do they get it to run? Thanks so much. I am continuing to work through tutorials.
Solved! Go to Solution.