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

Revit .NET Creations API: Create Columns – Rectangular Shape (cont.)

$
0
0

We created a variety of Revit elements such as walls, windows, doors, openings, floors, roofs, and levels with different shapes such as rectangular and circular if possible programmatically using Revit .NET API and C# before.

Previously, we tried to create an architectural rectangular column but found Revit went into an unstable status after that. In this post, let’s look into the issue and fix it.

public static FamilyInstance InsertColumn(Document doc, FamilySymbol symbol, XYZ location, Level topLevel, double topOffset, Level baseLevel, double baseOffset)
{
    FamilyInstance famInst = doc.Create.NewFamilyInstance(location, symbol, baseLevel, StructuralType.Column);

    famInst.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(topLevel.Id);
    famInst.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(topOffset);
    //famInst.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(baseLevel.Id);
    famInst.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(baseOffset);

    return famInst;
}

public static void TestCreateColumn(Document doc, XYZ location)
{
    FamilySymbol symbol = ColumnCreation.GetFirstSymbol(ColumnCreation.FindColumnFamilies(doc).FirstOrDefault());
    IOrderedEnumerable<Level> levels = FindAndSortLevels(doc);
    Level toplevel = levels.Last();
    Level baseLevel = levels.ElementAt(levels.Count() - 2);
    InsertColumn(doc, symbol, location, toplevel, 0.0, baseLevel, 0.0);
}

Here is the sample caller code.

ColumnCreation. TestCreateColumn(CachedDoc, new XYZ(50, 0, 0));

The resultant architectural rectangular column both looks good and behaves well this time in Revit.
 RecColumnGood

However, things are far than clear. Readers may have noticed that a different signature of the Document.Create.NewFamilyInstance(...) method, which accepts a Level argument, is used here.  Why not use the same simpler signature and set the base level parameter too as shown by the commented code?

public static FamilyInstance InsertColumn_crash(Document doc, FamilySymbol symbol, XYZ location, ElementId topLevel, double topOffset, ElementId baseLevel, double baseOffset)
{
    FamilyInstance famInst = doc.Create.NewFamilyInstance(location, symbol, StructuralType.Column);

    famInst.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_PARAM).Set(topLevel);
    famInst.get_Parameter(BuiltInParameter.FAMILY_TOP_LEVEL_OFFSET_PARAM).Set(topOffset);
    famInst.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_PARAM).Set(baseLevel);
    famInst.get_Parameter(BuiltInParameter.FAMILY_BASE_LEVEL_OFFSET_PARAM).Set(baseOffset);

    return famInst;
}

We actually tried that but it caused Revit to disappear without any messages!

So, the same ItemFactoryBase.NewFamilyInstance(XYZ, FamilySymbol, StructuralType) treats different elements differently. For what it knows well enough such as Doors and Windows, it behaves well; for Columns, it still can create them without extra burden such as setting level parameters but will make Revit unstable and finally crash; for the same Colmuns, if level parameters being set thereafter, it makes Revit disappear right away. The signature having the Level argument of the ItemFactoryBase.NewFamilyInstance method has to be used to create columns as demonstrated!

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