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

Revit .NET Creations API: Insert an Opening into Wall - Pt. 1

$
0
0

In Revit .NET API 2013, though the NewWall method has been moved to the Wall class itself, the Opening generation method has not. It is still in the Document.Create instance. Anyway, we figured where it is and were able to create some Openings.

In this article, let’s create an Opening and insert it into a wall. Here is the code.

Line line = CachedDoc.Application.Create.NewLineBound(new XYZ(50, 0, 0), new XYZ(65, 0, 0));
Wall wall = Wall.Create(CachedDoc, line, FindAndSortLevels(CachedDoc).Last().Id, false); //Level 2 or higher
Opening opening = CachedDoc.Create.NewOpening(wall, new XYZ(55, 0, 15), new XYZ(60, 0, 25));

...
public static IOrderedEnumerable<Level> FindAndSortLevels(RvtDocument doc)
{
    return new FilteredElementCollector(doc)
                    .WherePasses(new ElementClassFilter(typeof(Level), false))
                    .Cast<Level>()
                    .OrderBy(e => e.Elevation);
}
...

By the way, the last level obtained by the FindAndSortLevels() method in our test cases is the ‘Level 2’ which has an elevation of 10’ from the ground. That explains why we have to calculation out the Z coordinates (15’ and 25’ respectively) of the two corners of the opening as we thought they would use absolute positions again just as in door and window creation methods.

However, it’s totally out of our expectations.  Here is what the opening and the wall look like in Revit.
OpeningInWall
 
As can be seen, the Document.Create.NewOpening method behaves totally different from the Document.NewFamilyInstance method that we demonstrated many times before to create doors and windows and also insert them into a wall.  The Document.Create.NewOpening method however, thinks the X coordinates in the two corners as absolute but the Z coordinates as relative which are the Base Offset and the Top Offset from the bottom of the wall, it seems. In terms of what it thinks about the Y coordinates of the two corners is unclear. Please feel free to give it one more try in case interested in.

If people get confused when using the Document.NewFamilyInstance method to create doors and windows, the Document.Create.NewOpening method is more confusing. The Document.Create.NewOpening method treats the same guys (X, Y and Z coordinates) differently in the same group (XYZ corner), the X coordinates being in absolute positions, the Z in relative, and the Y not clear.

By the way, let’s make an educational guess here, if the opening location does not fall into the wall (e.g. by specifying the two X coordinates as 5’ and 10’ respectively), an exception as follows would be thrown out.

“Can't cut instance of 60" x 120" out of Wall.”

In the coming posts, we will be addressing this issue by inserting opening into wall using a consistent coordinate system.

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