cmdCreateViewTag

start

//把當前視圖名稱與比例標註在最低的軸網下面
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
public class cmdCreateViewTag : IExternalCommand
{
    /// <summary>
    
/// 得到最下面的軸網
    
/// </summary>
    
/// <param name="doc"></param>
    
/// <returns></returns>
    public Grid GetLowestGrid(Document doc)
    {
        FilteredElementCollector collector = new FilteredElementCollector(doc);
        collector.OfClass(typeof(Grid)).OfCategory(BuiltInCategory.OST_Grids);//
        Grid grid = null;
        foreach (Element el in collector)
        {
            if (grid == null)
            {
                grid = el as Grid;
            }
            else
            {
                Grid gridTmp = el as Grid;
                if (gridTmp.Curve.get_EndPoint(0).Y < grid.Curve.get_EndPoint(0).Y)
                {
                    grid = gridTmp;
                }
            }
        }
        return grid;
    }
    /// <summary>
    
/// 得到當前視圖名稱
    
/// </summary>
    
/// <param name="doc"></param>
    
/// <returns></returns>
    public string GetViewName(Document doc)
    {
        return doc.ActiveView.Name;
    }
    /// <summary>
    
/// 得到視圖比例
    
/// </summary>
    
/// <param name="doc"></param>
    
/// <returns></returns>
    public string GetViewScale(Document doc)
    {
        return "1 : " + doc.ActiveView.get_Parameter(BuiltInParameter.VIEW_SCALE).AsInteger().ToString();
    }
    public Result Execute(ExternalCommandData cmdData, ref string msg, ElementSet elements)
    {
        Document doc = cmdData.Application.ActiveUIDocument.Document;

        Transaction ts = new Transaction(doc, "http://revit.5d6d.com");
        ts.Start();
        //得到最低的軸網,得到原點
        Grid grid = GetLowestGrid(doc);
        if (grid == null)
        {
            ts.RollBack();
            return Result.Cancelled;
        }
        XYZ xyzOrigin = grid.Curve.get_EndPoint(0) + new XYZ(0, -10);
        //得到視圖名稱,得到視圖比例
        string strText = "視圖名稱:" + GetViewName(doc) + "\n視圖比例:" + GetViewScale(doc);
        //
        XYZ baseVec = new XYZ(000);
        XYZ upVec = new XYZ(000);
        double dWidth = 0.16;
        TextAlignFlags textAlign = TextAlignFlags.TEF_ALIGN_LEFT | TextAlignFlags.TEF_ALIGN_TOP;
        TextNote textNote = doc.Create.NewTextNote(doc.ActiveView, xyzOrigin, baseVec, upVec, dWidth, textAlign, strText);

        ts.Commit();

        return Result.Succeeded;
    }
}


end
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章