revit二次开发小技巧

//获取当前视图的标高 ,操做时只能在平面视图,否则会报错,由于在三维视图没法获取标高。ui

Level level = document.ActiveView.GenLevel;spa

//经过某构件获取标高(如放置门时获取墙体标高)code

Level level = document.GetElement(wall.LevelId) as Level;orm

//能够经过Document获取UIdocument.blog

UIDocument uidoc = new UIDocument(document);ip

//过滤全部轴网ci

List<Grid> allgrids = new FilteredElementCollector(doc).OfClass(typeof(Grid)).Cast<Grid>().ToList();element

//楼板与管道过滤选择string

public class FloorPipeFileter : ISelectionFilter
        {
            public bool AllowElement(Element elem)
            {
                if (elem.Category.Name == "楼板" || elem.Category.Name == "管道")
                {
                    return true;
                }
                return false;
            }

            public bool AllowReference(Reference reference, XYZ position)
            {
                return false;
            }
        }

//IList<T>转 List<T>();it

能够先利用IList<T> iList=new List<T>();而后用iList去承接承接生成的集合。

//try catch用法

public class Document_Selection : IExternalCommand
{
    public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
        ref string message, ElementSet elements)
    {
        try
        {
            
        }
        catch (Exception e)
        {
            //message = e.Message;
            //MessageBox.Show(ex.Message);
            return Autodesk.Revit.UI.Result.Failed;
        }

        return Autodesk.Revit.UI.Result.Succeeded;
    }    
}

 

//获取一个面的法向向量

XYZ normal = planarFace.ComputeNormal(new UV(planarFace.Origin.X, planarFace.Origin.Y));

Curve.CreateOffset Method

依据一个曲线偏移后生成另外一个曲线。

用其余 方法获得Curve1后,偏移后的

Curve2=Curve1.CreateOffset (double类型偏移距离,XYZ normal);

XYZ normal能够用下面的表示:

new XYZ(0,0,1)表示右或外方偏移,new XYZ(0,0,-1) 表示向左或内偏移,以下图所示:

未完,待完善。。。