Message 1 of 10
Rotating a Plan View
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi
I'm having a problem (or a misunderstanding) with rotating views using the
ElementTransformUtils.RotateElement method. The simplified sample code below will work but only if i add 2 to the Id value of the newly created view. So if newViewPlan.Id is the view I'm rotating, what element is newViewPlan.Id + 2 referring to? I stumbled on this "solution" after comparing the element Id's of the new view during code execution and after.
[RegenerationAttribute(RegenerationOption.Manual)]
[Transaction(TransactionMode.Manual)]
public class rotateElem2 : IExternalCommand
{
UIApplication uiapp;
UIDocument uidoc;
Autodesk.Revit.ApplicationServices.Application app;
Document doc;
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
uiapp = commandData.Application;
uidoc = uiapp.ActiveUIDocument;
app = uiapp.Application;
doc = uidoc.Document;
using (Transaction trans = new Transaction(doc, "Rotate View"))
{
trans.Start();
// create new plan view of the first level found
ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType))
.Cast<ViewFamilyType>()
.FirstOrDefault<ViewFamilyType>(x => ViewFamily.FloorPlan == x.ViewFamily);
Level firstLevel = new FilteredElementCollector(doc).OfClass(typeof(Level))
.Cast<Level>().FirstOrDefault<Level>();
ViewPlan newViewPlan = ViewPlan.Create(doc, vft.Id, firstLevel.Id);
// create rotation axis
Line lineAsAxis = app.Create.NewLineBound(new XYZ(0, 0, 0), new XYZ(0, 0, 1));
// rotate 45 deg (in radians)
double rad = 45 / 57.2957795;
// this line doesn't work or at least executes but doesn't do anything
// ElementTransformUtils.RotateElement(doc, newViewPlan.Id, lineAsAxis, rad);
// If you add 2 to the Id of newViewPlan then the new view gets rotated ???
int id = newViewPlan.Id.IntegerValue + 2;
ElementTransformUtils.RotateElement(doc, new ElementId(id), lineAsAxis, rad);
trans.Commit();
}
return Result.Succeeded;
}
}