Building Coder (Revit Secondary Development)-create a wall on a skewed Surface

Source: Internet
Author: User

I want to create a wall on a skewed face. Is there any sample code for reference? Jeremy has a simple piece of code here. The object document is a project that contains a Conceptual Mass Family instance. The code first retrieves the faces (-1, 0, 1) in the normal direction of the conceptual block, and then creates a wall on this surface. [Csharp] void CreateFaceWall (Document doc) {FilteredElementCollector collector = new FilteredElementCollector (doc); FamilyInstance fi = collector. ofClass (typeof (FamilyInstance )). firstElement () as FamilyInstance; XYZ nnorm = new XYZ (-1, 0, 1 ). normalize (); if (fi! = Null) {Options op = new Options (); op. includeNonVisibleObjects = true; // op. detailLevel = DetailLevels. undefined; op. computeReferences = true; // Note: I personally think this class name is not very good, not like a collection class. If GeometryObjectSet is called, it will better meet the class naming conventions of Revit API. GeometryElement ge = fi. get_Geometry (op); if (ge! = Null) {foreach (GeometryObject obj in ge) {Solid solid = obj as Solid; // It is a good habit to judge whether the value is NULL after type conversion. Because Revit APIs usually place different types of objects in the same collection. // The following PlanarFace pf = f as PlanarFace; is the same. If (solid! = Null & solid. Faces. Size> 0) {foreach (Face f in solid. Faces) {PlanarFace pf = f as PlanarFace; if (pf! = Null) {XYZ fnorm = pf. Normal. Normalize (); // Note: I am often asked how to perform vector computation. In fact, Revit API already provides a direct method for most vector computing. You don't have to go over linear algebra anymore. :) if (fnorm. isAlmostEqualTo (nnorm) {string log = ""; bool done = false; foreach (WallType t in doc. wallTypes) {if (t! = Null) {ElementId id = t. id; using (Transaction trans = new Transaction (doc) {trans. start ("Add wall"); try {// Note: This is a bright spot. Note that FaceWall should be used instead of Wall to create non-vertical walls. // You can find from the API documentation that, like Wall, FaceWall is directly derived from HostObject. FaceWall fw = FaceWall. Create (doc, id, WallLocationLine. CoreExterior, f. Reference); if (fw! = Null) {TaskDialog. show ("Succeeded", "Succeeded"); done = true ;}} catch (Exception ex) {log ++ = t. name + ":" + ex. message + "\ r \ n";} trans. commit () ;}if (done) break ;}} TaskDialog. show ("Failed", log) ;}}}}} unable to access the Location Attribute Problem I tried to access the Location attribute of a FaceWall object. However, the returned values, whether LocationCurve or LocationPoint, are NULL. [Csharp] Reference r1 = doc. selection. pickObject (ObjectType. element, "Please pick a wall:"); Element e1 = doc. getElement (r1); FaceWall faceWall = e1 as FaceWall; LocationCurve theCurve = faceWall. location as LocationCurve; LocationPoint thePoint = faceWall. location as LocationPoint; Jeremy is currently a limitation of Revit. If the Location information of an element is complex and cannot be expressed by a point or line segment, the content of the Location attribute may be a complex object that cannot be accessed using the Revit API, or simply NULL. Obviously, this is the case for FaceWall location information. Therefore, you should analyze its GeometryElement attribute to obtain location information.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.