Quantcast
Channel: RevitNetAddinWizard & NavisworksNetAddinWizard
Viewing all articles
Browse latest Browse all 872

Revit Family .NET API: Create Cone in Family Document

$
0
0

Revit .NET has provided the family API for several versions. We did not really address it in the past. In this series of posts, we are going to explore the Revit family .NET API and provide nice sample code and good analysis as usual.

Let’s create a Cone solid into a family document. Here we go.

public static ElementId CreateCone(RvtDocument famDoc, XYZ bottomCenter, double radius, double height)
{
    ElementId ret;

    CurveArray bottomProfile = new CurveArray();
    Plane plane = new Plane(XYZ.BasisZ, bottomCenter);
    Arc arc1 = famDoc.Application.Create.NewArc(plane, radius, 0.0, Math.PI);
    Arc arc2 = famDoc.Application.Create.NewArc(plane, radius, Math.PI, Math.PI * 2);
    bottomProfile.Append(arc1);
    bottomProfile.Append(arc2);

    SketchPlane sketchPlane = famDoc.FamilyCreate.NewSketchPlane(plane);

    CurveArray topProfile = new CurveArray();
    plane = new Plane(XYZ.BasisZ, new XYZ(bottomCenter.X, bottomCenter.Y, bottomCenter.Z + height));
    arc1 = famDoc.Application.Create.NewArc(plane, 1e-3, 0.0, Math.PI);
    arc2 = famDoc.Application.Create.NewArc(plane, 1e-3, Math.PI, Math.PI * 2);
    topProfile.Append(arc1);
    topProfile.Append(arc2);

    Blend solid = famDoc.FamilyCreate.NewBlend(
        true,
        topProfile,
        bottomProfile,
        sketchPlane
        );

    ret = solid.Id;

    return ret;
}

public static void TestCreateCone(UIApplication uiapp)
{
    RvtDocument famDoc = GetOpenOrCreateFamilyTestDoc(uiapp);
    using (Transaction tr = new Transaction(famDoc, "CreateCone"))
    {
        tr.Start();

        CreateCone(famDoc, new XYZ(25, 0, 0), 5, 10);

        tr.Commit();
    }
}

Here is how the newly created Cone looks like in the Revit family document.
Solid_Cone

Revit Addin Wizard (RevitAddinWizard) provides various wizards, coders and widgets to help program Revit addins. It can be downloaded from the Download link at the bottom of the blog index page.


Viewing all articles
Browse latest Browse all 872

Trending Articles