Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Offset XYZ points

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
Anonymous
1522 Views, 3 Replies

Offset XYZ points

Hi,

I have an array of XYZ point.

How to calculate offset points by some distance in outward or inward direction without creating line?

need to get all offset points

Please refer an imageUntitled.png

 

3 REPLIES 3
Message 2 of 4
jeremytammik
in reply to: Anonymous

No, of course not. 

 

Without creating the line, at least in your imagination, there is no way to determine in which direction to offset each point.

 

However, the functionality you seek is provided by the Revit API CreateViaOffset method:

 

https://apidocs.co/apps/revit/2019/6cffc624-d197-0f3b-b68c-26b9c9a0adf8.htm

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 4
Anonymous
in reply to: jeremytammik

Thanks for your prompt reply.

Got solution.

public List<XYZ> GetOffsetPoints(List<XYZ> lstPoints, double offset)
{
List<XYZ> lsttmpPoints = new List<XYZ>();
try
{
CurveLoop cl = new CurveLoop();
for (int i = 0; i < lstPoints.Count; i++)
{
XYZ startPoint = lstPoints[i];
XYZ endPoint = lstPoints[0];
if (i == lstPoints.Count - 1)
endPoint = lstPoints[0];
else
endPoint = lstPoints[i + 1];
Line line = Line.CreateBound(startPoint, endPoint);
cl.Append(line);
}
CurveLoop cl1 = new CurveLoop();
cl1 = CurveLoop.CreateViaOffset(cl, offset, new XYZ(0, 0, lstPoints[0].Z + 1));
for (int i = 0; i < cl1.Count(); i++)
{
Curve cv = cl1.ElementAt(i) as Curve;
lsttmpPoints.Add(cv.GetEndPoint(0));
}
}
catch (Exception ex)
{
lsttmpPoints = lstPoints;
}
return lsttmpPoints;
}

Message 4 of 4
jeremytammik
in reply to: Anonymous

With this solution, I assume that your points form a curve loop in the XY plane.

 

Here is a slight cleanup of your solution:

 

    /// <summary>
    /// Create a new CurveLoop from a list of points.
    /// </summary>
    public static CurveLoop CreateCurveLoop(
      List<XYZ> pts )
    {
      int n = pts.Count;
      CurveLoop curveLoop = new CurveLoop();
      for( int i = 1; i < n; ++i )
      {
        curveLoop.Append( Line.CreateBound(
          pts[i - 1], pts[i] ) );
      }
      curveLoop.Append( Line.CreateBound(
        pts[n], pts[0] ) );
      return curveLoop;
    }

    /// <summary>
    /// Offset a list of points by a distance in a 
    /// given direction in or out of the curve loop.
    /// </summary>
    public static IEnumerable<XYZ> OffsetPoints( 
      List<XYZ> pts,
      double offset,
      XYZ normal )
    {
      CurveLoop curveLoop = CreateCurveLoop( pts );

      CurveLoop curveLoop2 = CurveLoop.CreateViaOffset( 
        curveLoop, offset, normal );

      return curveLoop2.Select<Curve, XYZ>( 
          c => c.GetEndPoint( 0 ) );
    }

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report