Failed to create a wall by modeling orientation.

Failed to create a wall by modeling orientation.

Tripler123
Advocate Advocate
410 Views
4 Replies
Message 1 of 5

Failed to create a wall by modeling orientation.

Tripler123
Advocate
Advocate

I am trying to create a wall using the Wall.Create method https://www.revitapidocs.com/2020/6c247699-c8e5-91df-67f7-470d10fa7ba3.htm. with the following code.

 

UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;

Reference reference = uiDoc.Selection.PickObject(ObjectType.Element,"Seleccione el elemento");
Element elemento = doc.GetElement(reference);

Wall wall = elemento as Wall;

                WallType wallType = ColectoresEntrada.TipoElementoMuro(doc,"Encofrado") as WallType;

ElementId levelId = elemento.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();

IList<Reference> sideReferenceFaces = HostObjectUtils.GetSideFaces(wall,ShellLayerType.Interior);

Face faceWithoutIntersection = doc.GetElement(sideReferenceFaces[0]).GetGeometryObjectFromReference(sideReferenceFaces[0]) as Face;

PlanarFace planarFace = faceWithoutIntersection as PlanarFace;
XYZ normal = planarFace.FaceNormal.Normalize();

IList<CurveLoop> curveLoopList = planarFace.GetEdgesAsCurveLoops();

//curves list
List<Curve> curves= new List<Curve>();
foreach (CurveLoop curveLoop in curveLoopList)
{
    foreach (Curve curve in curveLoop)
    {
         XYZ firstPoint = curve.GetEndPoint(0);
          XYZ endPoint = curve.GetEndPoint(1);

         Curve newCurve = Line.CreateBound(firstPoint, endPoint) as Curve;
         curves.Add(newCurve);
     }
}

using (Transaction trans = new Transaction(doc))
{
   trans.Start("Crear Muro");

   try
   {
      Wall wallCreated = Wall.Create(doc, curves, wallType.Id, levelId, true);
      trans.Commit();
    }
    catch (Exception ex )
    {
        TaskDialog.Show("Error",ex.Message);                          
        trans.RollBack();
    }
}

 

I have tried it with different ways, but I have a problem when there are windows inside my wall and the wall was drawn from right to left.

I show an image so you can see when the error happens.

 

Failed to create wall.png

 

I would appreciate a guide to know what could be the error I have.

0 Likes
411 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

If the wall is going the wrong way, you can easily reverse it like this: retrieve the location line from the Location property:

  

https://www.revitapidocs.com/2023/89438f4f-7e15-835a-0c66-d6adbc8dd00c.htm

  

The result can be cast to location curve:

  

https://www.revitapidocs.com/2023/9dd6eb99-f105-a05f-dc1b-dfde17b8768c.htm

  

Reverse the location curves underlying Line object by by switching its endpoints.

  

Assign the location curve with the reversed line back to the location property.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5

Tripler123
Advocate
Advocate

Thanks @jeremy_tammik, We will try with Reverse the location

 

The analysis of each of the cases was made and we reached the following conclusions:

 

- The creation of walls is made from curves that have only one arrangement in the counterclockwise.
- For a windowless wall modeled left to right or right to left, the ordering of the curves is counterclockwise.
- For a wall modeled from left to right (with windows or without windows), the ordering of the curves is done in a counterclockwise direction.
- For a right-to-left modeled wall with windows, the ordering of one of its curvLoops goes clockwise and the rest go counterclockwise. The error you get is starting this curvLoop in a clockwise direction

0 Likes
Message 4 of 5

Tripler123
Advocate
Advocate

Hello @jeremy_tammik ,

try changing the location line. but the problem is that it also changes the position of the doors and windows. Any Sugestion.

LocationCurve wallLocationCurve = elemento.Location as LocationCurve;

XYZ pt1 = wallLocationCurve.Curve.GetEndPoint(0);
XYZ pt2 = wallLocationCurve.Curve.GetEndPoint(1);

using (Transaction trans = new Transaction(doc))
{
    try
     {
         trans.Start("Cambiar dirección del muro");
         if (pt1.X < pt2.X)
         {
             Line newWallLine = Line.CreateBound(pt2, pt1);
             wallLocationCurve.Curve = newWallLine;

             doc.Regenerate();
            uiDoc.RefreshActiveView();
        }
           rans.Commit();
        }
       catch (Exception ex)
      {
       TaskDialog.Show("Error", ex.Message);
   }
}

 

Captura.PNG

 

 

0 Likes
Message 5 of 5

jeremy_tammik
Alumni
Alumni
  • Make a note of the door and window locations
  • Delete all the doors and windows
  • Reverse the wall location line
  • Place new doors and windows in the proper locations

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes