Connect 13 C#

I am trying to get the line string  information from a curve primitive type of line string, I am using the primitive to get the length of the line string and using other methods without any issues.

Can someone tell me what I am doing wrong?

.

Thank you

Donna

if (cPrim.GetType().Equals(CurvePrimitive.CurvePrimitiveType.LineString))
{ 
   System.Collections.Generic.IList<DPoint3d> ptList = new System.Collections.Generic.List<DPoint3d>();
   if (cPrim.TryGetLineString(ptList))
    {
        // quick check to determine if code is working
        double segmentDistance = ptList.ElementAt(0).Distance(ptList.ElementAt(1));
        System.Windows.Forms.MessageBox.Show("ptList retrieved - " + segmentDistance.ToString());
    }
}

Parents Reply Children
  • Hi Donna,

    I used IList instead of List in my declaration, I changed it to List and it works.

    It's strange, because to use IList is fine. I tried to define variable as IList and my code still works.

    I use CurvePathQuery and CurveVector in my code to get most of the information that I need.

    It's I guess the right way and it follow best practices.

    But your code still seems to me too complicated, does not using all C# features (plus nested if conditions are usually treated as dirty code). What about this (not any testing done):

    CurvePathQuery q = CurvePathQuery.GetAsCurvePathQuery(element);
    
    CurveVector vec = q?.GetCurveVector();
    
    if (null != vec && vec.IsOpenPath)
    {
        int vecCount = vec.Count;
    }

    I guess it can be simplified even more, because static method, doing casting to CurvePathQuery automatically, is available also:

    CurveVector vec = CurvePathQuery.ElementToCurveVector(element);
    
    if (null != vec && vec.IsOpenPath)
    {
        int vecCount = vec.Count;
    }

    With regards,

      Jan