#RTCNA2016 Wish 2 Granted! (part one)

Timothy had this API wish:

View Ranges in Section to show graphically like a space in section (with Interior checked on) . Allow me to drag the box up/down to level if desired otherwise keep “Level Above”.

Here is part one – creating lines in an elevation view to show the view range of a plan view.

public void showViewRange()
{
    string planName = "Level 1 View Range Test";
    
    Document doc = this.ActiveUIDocument.Document;
    
    ViewPlan viewPlan = new FilteredElementCollector(doc)
        .OfClass(typeof(ViewPlan))
        .Cast<ViewPlan>()
        .FirstOrDefault(q => q.Name == planName);
    if (viewPlan == null)
        return;
    
    PlanViewRange range = viewPlan.GetViewRange();
    Level bottomLevel = doc.GetElement(range.GetLevelId(PlanViewPlane.BottomClipPlane)) as Level;
    Level topLevel = doc.GetElement(range.GetLevelId(PlanViewPlane.TopClipPlane)) as Level;
    
    Category bottomClipLineStyle = doc.Settings.Categories.Cast<Category>().FirstOrDefault(q => q.Id.IntegerValue == (int)BuiltInCategory.OST_Lines)
        .SubCategories.Cast<Category>().FirstOrDefault(q => q.Name == "Bottom Clip Plane");

    Category topClipLineStyle = doc.Settings.Categories.Cast<Category>().FirstOrDefault(q => q.Id.IntegerValue == (int)BuiltInCategory.OST_Lines)
        .SubCategories.Cast<Category>().FirstOrDefault(q => q.Name == "Top Clip Plane");
    
    using (Transaction t = new Transaction(doc, "Make View Range Line"))
    {
        t.Start();
        if (bottomLevel != null)
        {
            double bottomOffset = range.GetOffset(PlanViewPlane.BottomClipPlane);
            double z = bottomLevel.Elevation + bottomOffset;
            DetailCurve bottomLine = doc.Create.NewDetailCurve(doc.ActiveView, Line.CreateBound(new XYZ(0,0,z), new XYZ(30,0,z)));
            if (bottomClipLineStyle != null)
            {
                bottomLine.LineStyle = bottomClipLineStyle.GetGraphicsStyle(GraphicsStyleType.Projection);
            }
        }
        
        if (topLevel != null)
        {
            double topOffset = range.GetOffset(PlanViewPlane.TopClipPlane);
            double z = topLevel.Elevation + topOffset;
            DetailCurve topLine = doc.Create.NewDetailCurve(doc.ActiveView, Line.CreateBound(new XYZ(0,0,z), new XYZ(30,0,z)));
            if (topClipLineStyle != null)
            {
                topLine.LineStyle = topClipLineStyle.GetGraphicsStyle(GraphicsStyleType.Projection);
            }
        }
        t.Commit();
    }
    
}

One thought on “#RTCNA2016 Wish 2 Granted! (part one)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s