Wrong direction of detection of walls using api

Wrong direction of detection of walls using api

allazaruszcheong_21
Enthusiast Enthusiast
541 Views
7 Replies
Message 1 of 8

Wrong direction of detection of walls using api

allazaruszcheong_21
Enthusiast
Enthusiast

//Checking for SouthWest Facing Walls & Windows
bool isSouthWestFacing = IsSouthWestFacing(exteriorDirection);
if (isSouthWestFacing)
{
SouthWest_Wall_Lst.Add(WE);

inserts_0 = (WE as HostObject).FindInserts(true, true, true, true);

ParaSouthWestWall = WE.LookupParameter("SouthWest");
using (Transaction trans = new Transaction(doc, "ETTV_1"))
{
trans.Start();
ParaSouthWestWall.Set(1);

foreach (ElementId emtid in inserts_0)
{
Element emt = doc.GetElement(emtid);
emt.LookupParameter("SouthWest").Set(1);
}

trans.Commit();
}


}


//Checking for SouthWest Facing Direction
bool IsSouthWestFacing(XYZ direction)
{
double angleToWest = direction.AngleTo(-XYZ.BasisX);
double angleToSouth = direction.AngleTo(-XYZ.BasisY);

return ((Math.Abs(angleToWest) > Math.PI / 😎 & (Math.Abs(angleToWest) < (Math.PI * 3 / 8))) &
((Math.Abs(angleToSouth) > Math.PI / 😎 & (Math.Abs(angleToSouth) < (Math.PI * 3 / 8)));
}

allazaruszcheong_21_0-1705384638714.pngallazaruszcheong_21_1-1705384655226.png

 



As you can see both walls are opposite side of building but it registers as same direction. Any information that you need please request.

0 Likes
542 Views
7 Replies
Replies (7)
Message 2 of 8

jeremy_tammik
Alumni
Alumni

Funnily and luckily enough, the official Revit SDK contains a sample that denonstrates this exact issue:

  

  • FindSouthFacing in the folder DirectionCalculation

  

It is discussed by The Building Coder here:

  

  

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

allazaruszcheong_21
Enthusiast
Enthusiast

What is the exact issue?  I can't find it in TBC and I can't find it here https://github.com/AMEE/revit/blob/master/samples/Revit%202012%20SDK/Samples/DirectionCalculation/CS... either

Or is it the way it finds the walls? i believe I am already using the code here https://thebuildingcoder.typepad.com/blog/2018/05/filterrule-use-and-retrieving-exterior-walls.html

 

0 Likes
Message 4 of 8

jeremy_tammik
Alumni
Alumni

Maybe you should read the entire series of posts on analysing building geometry, especially these two:

 

 

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

allazaruszcheong_21
Enthusiast
Enthusiast

allazaruszcheong_21_0-1705560798311.png

 

I really have no idea whats going on...

To me it looks like the way the direction is calculated is wrong...? but I'm not sure
Was thinking to use FindReferencesByDirection, if I can find the elements using the ray I can set its direction...? But looking in revitapidocs the 2022 ver. does not have it...

 

0 Likes
Message 6 of 8

allazaruszcheong_21
Enthusiast
Enthusiast

Still have not found a solution for this. If anyone can help it would be great thanks.

0 Likes
Message 7 of 8

jeremy_tammik
Alumni
Alumni

I think you can simply grab the LocationCurve from the wall's Location property, reverse it, and assign the reversed curve to the property instead:

  

  

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

allazaruszcheong_21
Enthusiast
Enthusiast

//Get Exterior Wall Direction
XYZ GetExteriorWallDirection(Wall wall)
{
LocationCurve locationCurve = wall.Location as LocationCurve;
XYZ exteriorDirection = XYZ.BasisZ;

if (locationCurve != null)
{
Curve curve = locationCurve.Curve;

//Write("Wall line endpoints: ", curve);

XYZ direction = XYZ.BasisX;
if (curve is Line)
{
// Obtains the tangent vector of the wall.
direction = curve.ComputeDerivatives(0, true).BasisX.Normalize();
}
else
{
// An assumption, for non-linear walls, that the "tangent vector" is the direction
// from the start of the wall to the end.
direction = (curve.GetEndPoint(1) - curve.GetEndPoint(0)).Normalize();
}
// Calculate the normal vector via cross product.
exteriorDirection = XYZ.BasisZ.CrossProduct(direction);

// Flipped walls need to reverse the calculated direction
if (wall.Flipped) exteriorDirection = -exteriorDirection;
}

return exteriorDirection;
}

Hi... Do you mean something like this?

 

0 Likes