How do I get the curve orientation of an element using REVIT API?

How do I get the curve orientation of an element using REVIT API?

josenlee34_21
Participant Participant
1,138 Views
10 Replies
Message 1 of 11

How do I get the curve orientation of an element using REVIT API?

josenlee34_21
Participant
Participant

I have tried this code, does not seem to work... can anyone please advice on how do I go abot in finding it?

using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

public class ArcOrientation
{
public void GetArcOrientation(Document doc, ElementId arcElementId)
{
// Get the element by ID
Element element = doc.GetElement(arcElementId);

if (element is CurveElement curveElement)
{
// Get the curve from the curve element
Curve curve = curveElement.GeometryCurve;

if (curve is Arc arc)
{
// Get the orientation (rotation) of the arc
XYZ orientation = arc.Normal;

// Print or use the orientation information as needed
TaskDialog.Show("Arc Orientation", $"Arc element has orientation: {orientation}");
}
else
{
TaskDialog.Show("Arc Orientation", "Selected element is not an Arc.");
}
}
else
{
TaskDialog.Show("Arc Orientation", "Selected element is not a CurveElement.");
}
}
}

0 Likes
1,139 Views
10 Replies
Replies (10)
Message 2 of 11

ennujozlagam
Mentor
Mentor

check this if can help?

https://thebuildingcoder.typepad.com/blog/2018/03/create-2d-arc-and-filter-for-intersecting-elements...

 

post here

 

https://forums.autodesk.com/t5/revit-api-forum/bd-p/160





Remember : without the difficult times in your LIFE, you wouldn't be who you are today. Be grateful for the good and the bad. ANGER doesn't solve anything. It builds nothing, but it can destroy everything...
Please mark this response as "Accept as Solution" if it answers your question. Kudos gladly accepted.
0 Likes
Message 3 of 11

josenlee34_21
Participant
Participant

Hmm I dont think it explains how to find the orientation of the curve wall though. 

0 Likes
Message 4 of 11

jeremy_tammik
Alumni
Alumni

All curve elements are parametrised:

  

http://thebuildingcoder.typepad.com/blog/2010/01/curves.html

  

You can use the GetEndParameter method to obtain the start and end parameters:

  

https://www.revitapidocs.com/2024/0f4b2c25-35f8-4e3c-c71a-0d41fb6935ce.htm

  

Check the other Curve class members for other operations with the curve parameters:

  

https://www.revitapidocs.com/2024/92a388f3-4949-465c-b938-2906ff6bdf5b.htm

  

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

SimonaQQ
Advocate
Advocate

What does curve orientation refer to?
Arc. Normal refers to the direction of the plane where arc is located. If you are referring to this, I think there is no problem with the code.
Or what you want is something similar to Line Arc of Direction Direction?
Or is it clockwise or counterclockwise?

0 Likes
Message 6 of 11

josenlee34_21
Participant
Participant

 

 

0 Likes
Message 7 of 11

josenlee34_21
Participant
Participant

It refers to finding directions of points on the curved wall.

0 Likes
Message 8 of 11

josenlee34_21
Participant
Participant

I have added some stuff and it runs now but there is now output... Kindly advise on how to fix this problem 🙏

The updated code is below:

public class ArcOrientation : IExternalCommand
{
public Result Execute(
ExternalCommandData commandData,
ref string message,
ElementSet elements)
{
// Get the current Revit application and document
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = uiApp.ActiveUIDocument;
Document doc = uiDoc.Document;

// Prompt the user to select an element
Reference pickedRef = uiDoc.Selection.PickObject(ObjectType.Element, "Select an element");

if (pickedRef != null)
{
ElementId arcElementId = pickedRef.ElementId;

// Get the element by ID
Element element = doc.GetElement(arcElementId);

if (element is CurveElement curveElement)
{
// Get the curve from the curve element
Curve curve = curveElement.GeometryCurve;

if (curve is Arc arc)
{
// Get the orientation (rotation) of the arc
XYZ orientation = arc.Normal;

// Print or use the orientation information as needed
TaskDialog.Show("Arc Orientation", $"Arc element has orientation: {orientation}");
}
else
{
TaskDialog.Show("Arc Orientation", "Selected element is not an Arc.");
}
}
else
{
TaskDialog.Show("Arc Orientation", "Selected element is not a CurveElement.");
}
}
else
{
TaskDialog.Show("Arc Orientation", "No element selected.");
}

return Result.Succeeded;
}
}
}

0 Likes
Message 9 of 11

Mohamed_Arshad
Advisor
Advisor

HI @josenlee34_21 

 

   In above discussion you have mentioned that you need to find direction of points on the curved wall. So can you explain which point Direction need with small image or representation. So that we can help you easily.

 

 


Mohamed Arshad K
Software Developer (CAD & BIM)

0 Likes
Message 10 of 11

SimonaQQ
Advocate
Advocate

It sounds like: finding the tangent direction at a certain point on the curve.
If that is indeed the case, Curve.ComputeDerivatives, this Api returns a Transform where BasisX is the tangent direction at this point.

0 Likes
Message 11 of 11

josenlee34_21
Participant
Participant

josenlee34_21_0-1706074306935.png

josenlee34_21_1-1706074329971.png

Something like this. Any random point on the curved surface will do

 

0 Likes