旋转BoundingBoxXYZ来修改三维视图的截面盒

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.UI.Selection;


namespace MyDimention
{
    [Autodesk.Revit.Attributes.Regeneration(RegenerationOption.Manual)]
    [Autodesk.Revit.Attributes.Transaction(TransactionMode.Manual)]
    public class Class1 : IExternalCommand
    {
        // public bool IsGrid(Element el)
        // {
        //     Grid g = el as Grid;
        //     if(g!=null)
        //     {
        //         return true;
        //     }
        //     return false;
        // }
       
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIDocument uidoc = commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;
            Selection selection = uidoc.Selection;

           //Reference reff = selection.PickObject(ObjectType.Element, "请选择一个轴线!");
            //Element ell = doc.GetElement(reff);
        
            #region  BoudingBox
            View3D view3D = doc.GetElement(new ElementId(96277)) as View3D;
            BoundingBoxXYZ bbXYZ = view3D.GetSectionBox();
            if(bbXYZ==null)
            {
                TaskDialog.Show("title", "the section box for view3d isn't enabled!");
            }
            //create transform
            using (Transaction ts=new Transaction(doc))
            {
                ts.Start("bbox");
                XYZ origin = XYZ.Zero;
                XYZ axis = new XYZ(0, 0, 1);
                Transform rotate = Transform.CreateRotationAtPoint(axis, Math.PI/4, origin);
                //apply transformation to 3D view
                bbXYZ.Transform = bbXYZ.Transform.Multiply(rotate);
                view3D.SetSectionBox(bbXYZ);
                ts.Commit();
            }
           


            #endregion

            return Result.Succeeded;

        }
        //创建几何选项
        public static Options GetGeometryOption()
        {
            Options option = new Options();
            option.ComputeReferences = true;
            option.DetailLevel = ViewDetailLevel.Fine;
            return option;
        }
       
    }
    /*
    public class DoorFilter : ISelectionFilter
    {
        public bool AllowElement(Element elem)
        {
            if (elem.Category.Id.IntegerValue == (int)(BuiltInCategory.OST_Doors))
            {
                return true;
            }
            else return false;

        }

        public bool AllowReference(Reference reference, XYZ position)
        {
            throw new NotImplementedException();
        }
    }
    */
}

参考书籍:Autodesk Revit二次开发基础教程

你可能感兴趣的:(Revit二次开发)