Creating BuildingPad : Default Type Not Found

Creating BuildingPad : Default Type Not Found

harilalmn
Advocate Advocate
742 Views
5 Replies
Message 1 of 6

Creating BuildingPad : Default Type Not Found

harilalmn
Advocate
Advocate

Hi All,

I  am  trying to create a building pad. To pass the BuildingPad Type's Id as an argument for the BuildingPad.Create () method, I am trying to get the "first" type in the document like this;

 

 

BuildingPad buildingPad = new FilteredElementCollector(doc)
                	.OfCategory(BuiltInCategory.OST_BuildingPad)
                	.WhereElementIsElementType()
                	.ToElements().First() as BuildingPad;

 

But, this doesn't return a building pad type. I checked if the count() of the collector, and  could see that it was 0 (zero). 

 

I tried creating an instance of the default buildingpad type and deleted the instance and tried running the code and then it showed  1 item in the collector. So I understand, unless an instance is created, the type  is not counted. Why is it so?

 

 

In a new document

0 Likes
Accepted solutions (2)
743 Views
5 Replies
Replies (5)
Message 2 of 6

RPTHOMAS108
Mentor
Mentor
Accepted solution

Probably has been purged out of template you are using somehow (shouldn't usually be possible these days). Historically we've been able to remove things with API that shouldn't be removed i.e. last types and even project browser view.  If you start a blank metric template you can see such Types with RevitLookup.

 

210813a.PNG

 

However BuildingPad elements can only exist once you have a TopographicalSurface in the project:

 

e.g. so similarly  in the UI the Building Pad icon will be unavailable if there is no topo:

210813.PNG

So that could be part of the reason.

Message 3 of 6

FAIR59
Advisor
Advisor
Accepted solution

there is a mismatch in your FilteredElementCollector. The elementtype of a buildingpad is BuildingPadType , so your casting to BuildingPad is faulty.

Actually you don't need a collector at all. Just query revit for  the default BuildingPadTypeId

doc.GetDefaultElementTypeId(ElementTypeGroup.BuildingPadType)

.

0 Likes
Message 4 of 6

harilalmn
Advocate
Advocate

@RPTHOMAS108 

Thanks for the info, Thomas. I had not considered that possibility. Now I notice it. 

But I thought Pad  was a system family like walls or floors. How come they are not 'activated' until one instance is created? Is it a similar algorithm  running in  background to save memory like other component families, for which the Types are to be activated before using...?

0 Likes
Message 5 of 6

harilalmn
Advocate
Advocate
I Tried this too. But this also is working only if atleast one pad instance was created....
0 Likes
Message 6 of 6

RPTHOMAS108
Mentor
Mentor

Some templates such as the 'Construction Template' do not have any BuildingPadType elements within them. Therefore you need to see if you find any and then use BuildingPadType.CreateDefault if you don't.

 

Note that as previously noted you'll need a topo surface under the pad or you'll get InvalidOperationException upon trying to create the BuildingPad instance.

public Result Obj_210814a(Autodesk.Revit.UI.ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements)
{

    UIDocument UIDoc = commandData.Application.ActiveUIDocument;
    if (UIDoc == null)
        return Result.Cancelled;
    Document IntDoc = UIDoc.Document;

    FilteredElementCollector FEC = new FilteredElementCollector(IntDoc);
    ElementCategoryFilter ECF = new ElementCategoryFilter(BuiltInCategory.OST_BuildingPad);
    List<ElementId> Eids = FEC.WherePasses(ECF).WhereElementIsElementType().ToElementIds() as List<ElementId>;

    BuildingPadType BPType = null;
    if (Eids.Count == 0)
    {
        using (Transaction Tx = new Transaction(IntDoc, "Create default pad type"))
        {
            if (Tx.Start() == TransactionStatus.Started)
            {
                BPType = BuildingPadType.CreateDefault(IntDoc);
                Tx.Commit();
            }
        }
    }
    else
    {
        BPType = IntDoc.GetElement(Eids[0]) as BuildingPadType;
    }
     FilteredElementCollector FEC_L = new FilteredElementCollector(IntDoc);
     ElementClassFilter ECF_L = new ElementClassFilter(typeof(Level));
     List<Level> Lvs = FEC_L.WherePasses(ECF_L).ToElements().Cast<Level>().ToList();
     Level Lv = Lvs.Find(L => L.Elevation == Lvs.Min(L0 => L0.Elevation));

    using (Transaction Tx = new Transaction(IntDoc, "Create pad imstance"))
    {

        if (Tx.Start() == TransactionStatus.Started)
        {
            double Val = 3000 / 304.8;
            XYZ C0 = new XYZ(-Val / 2, Val / 2, 0);
            XYZ C1 = new XYZ(-Val / 2, -Val / 2, 0);
            XYZ C2 = new XYZ(Val / 2, -Val / 2, 0);
            XYZ C3 = new XYZ(Val / 2, Val / 2, 0);

            CurveLoop CL = new CurveLoop();
            CL.Append(Line.CreateBound(C0, C1));
            CL.Append(Line.CreateBound(C1, C2));
            CL.Append(Line.CreateBound(C2, C3));
            CL.Append(Line.CreateBound(C3, C0));

            BuildingPad.Create(IntDoc, BPType.Id, Lv.Id, new CurveLoop[] { CL }.ToList());

            Tx.Commit();
        }
    }
    return Result.Succeeded;
}
0 Likes