<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Problem with Civil 3D generated toposurfaces from TIN surfaces in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8981254#M40270</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've been working on an add-in that will let you pick tin surfaces from an open Civil 3D-model and then create toposurfaces of those in Revit. The problem I have is when I pick two tin surfaces at a time, Revit creates one toposurface of the first tin surface I picked and another toposurface conisting of both tin surfaces. My goal is to create two separate toposurfaces. I can't figure out where I've messed up, can someone help me? I'll attatch a screencast and my code.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    public partial class Import_form : System.Windows.Forms.Form
    {


        public IAeccSurfaces surfs;
        public List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt; topos = new List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt;();
        private Autodesk.AutoCAD.Interop.IAcadApplication m_oAcadApp = null;
        private Autodesk.AECC.Interop.UiLand.IAeccApplication m_oAeccApp = null;
        private Autodesk.AECC.Interop.UiLand.IAeccDocument m_oAeccDoc = null;
        private IAeccDocuments m_oAeccDocs = null;
        private Autodesk.AECC.Interop.Land.IAeccDatabase m_oAeccDb = null;
        string m_sAcadProdID = "AutoCAD.Application";
        string m_sAeccAppProgId = "AeccXUiLand.AeccApplication.13.0";
        double[] triangles;
        List&amp;lt;double&amp;gt; nummer = new List&amp;lt;double&amp;gt;();


        public Import_form()
        {
            InitializeComponent();


            m_oAcadApp = (IAcadApplication)Marshal.GetActiveObject(m_sAcadProdID);


            if (m_oAcadApp != null)
            {
                m_oAeccApp = (Autodesk.AECC.Interop.UiLand.IAeccApplication)m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId);
                m_oAeccDoc = (Autodesk.AECC.Interop.UiLand.IAeccDocument)m_oAeccApp.ActiveDocument;
                m_oAeccDocs = (Autodesk.AECC.Interop.UiLand.IAeccDocuments)m_oAeccApp.Documents;
                m_oAeccDb = (Autodesk.AECC.Interop.Land.IAeccDatabase)m_oAeccApp.ActiveDocument.Database;



                comboBox1.Items.Add(m_oAeccDoc);
                comboBox1.SelectedIndex = 0;
                comboBox1.DisplayMember = "Name";
                comboBox1.SelectedItem = m_oAeccDoc;
                surfs = m_oAeccDb.Surfaces;

                foreach (IAeccTinSurface surf in surfs)
                {
                    checkedListBox1.Items.Add(surf);

                }

                ((ListBox)checkedListBox1).DisplayMember = "Name";

            }

        }

        private void Import_form_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {

            /*int antal = tjo.Count();
            MessageBox.Show(antal.ToString());*/

        }
        public static List&amp;lt;List&amp;lt;double&amp;gt;&amp;gt; splitlist(List&amp;lt;double&amp;gt; nummer, int antal = 3)
        {
            var list = new List&amp;lt;List&amp;lt;double&amp;gt;&amp;gt;();

            for (int i = 0; i &amp;lt; nummer.Count; i += antal)
            {
                list.Add(nummer.GetRange(i, Math.Min(antal, nummer.Count - i)));
            }
            return list;
        }

        private void checkedListBox1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (IAeccTinSurface valdsurface in checkedListBox1.CheckedItems)
            {
                triangles = valdsurface.OutputTriangles;
                List&amp;lt;XYZ&amp;gt; punkter = new List&amp;lt;XYZ&amp;gt;();
                List&amp;lt;XYZ&amp;gt; utpunkter = new List&amp;lt;XYZ&amp;gt;();

                double x = 0, y = 0, z = 0;
                foreach (double d in triangles)
                {
                    nummer.Add(d);
                }
                List&amp;lt;List&amp;lt;double&amp;gt;&amp;gt; uppdelning = splitlist(nummer, 3);
                foreach (List&amp;lt;double&amp;gt; uppdelat in uppdelning)
                {
                    for (int k = 0; k &amp;lt; uppdelat.Count; ++k)
                    {

                        int j = 1;

                        foreach (double d in uppdelat)
                        {

                            switch (j)
                            {
                                case 1:
                                    x = d;
                                    break;

                                case 2:
                                    y = d;
                                    break;
                                case 3:
                                    z = d;
                                    break;

                                default:
                                    break;

                            }
                            j++;
                        }
                        punkter.Add(new XYZ(x, y, z));
                    }
                }
                topos.Add(punkter);
            }
        }
    }&lt;/PRE&gt;&lt;PRE&gt; public class Civil_import : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Autodesk.Revit.Creation.Application appcrea = uiapp.Application.Create;
            Autodesk.Revit.DB.Document doc = uiapp.ActiveUIDocument.Document;
            Autodesk.Revit.DB.View currentview = uiapp.ActiveUIDocument.ActiveView;
            List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt; lists_out = new List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt;();

            Import_form f = new Import_form();

             var result = f.ShowDialog();

             if(result==DialogResult.OK)
             {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("ett");

                    foreach (List&amp;lt;XYZ&amp;gt; punkter in f.topos)
                    {
                        List&amp;lt;XYZ&amp;gt; ut = new List&amp;lt;XYZ&amp;gt;();
                        GetVertices(ut, punkter);
                        lists_out.Add(ut);
                    }
                    foreach(List&amp;lt;XYZ&amp;gt; tops in lists_out)
                    {
                        TopographySurface.Create(doc, tops);
                    }
                    t.Commit();
                }
             }
             if (result==DialogResult.Cancel)
             {
                 return Result.Cancelled;
             }

            return Result.Succeeded;
        }
        const double _eps = 1.0e-9;
        
        public static bool IsZero(double a)
        {
            return _eps &amp;gt; Math.Abs(a);
        }

        public static bool IsEqual(double a, double b)
        {
            return IsZero(b - a);
        }

        public static int Compare(double a, double b)
        {
            return IsEqual(a, b) ? 0 : (a &amp;lt; b ? -1 : 1);
        }

        public static int Compare(XYZ p, XYZ q)
        {
            int diff = Compare(p.X, q.X);
            if (0 == diff)
            {
                diff = Compare(p.Y, q.Y);
                if (0 == diff)
                {
                    diff = Compare(p.Z, q.Z);
                }
            }
            return diff;
        }
        static void GetVertices(List&amp;lt;XYZ&amp;gt; listut, List&amp;lt;XYZ&amp;gt; listin)
        {

            Dictionary&amp;lt;XYZ, int&amp;gt; a
              = new Dictionary&amp;lt;XYZ, int&amp;gt;(
                new XyzComparer());



            foreach (XYZ p in listin)
            {
                if (!a.ContainsKey(p))
                {
                    a.Add(p, 1);
                }
                else
                {
                    ++a[p];
                }
            }

            List&amp;lt;XYZ&amp;gt; keys = new List&amp;lt;XYZ&amp;gt;(a.Keys);

            keys.Sort(Compare);

            foreach (XYZ p in keys)
            {

                listut.Add(p);
            }
        }
       

    }
    public class XyzComparer : IEqualityComparer&amp;lt;XYZ&amp;gt;
    {

        public bool Equals(XYZ p, XYZ q)
        {
            return p.IsAlmostEqualTo(q);
        }

        public int GetHashCode(XYZ p)
        {
            return p.ToString().GetHashCode();
        }


    }&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Aug 2019 13:02:40 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-08-22T13:02:40Z</dc:date>
    <item>
      <title>Problem with Civil 3D generated toposurfaces from TIN surfaces</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8981254#M40270</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've been working on an add-in that will let you pick tin surfaces from an open Civil 3D-model and then create toposurfaces of those in Revit. The problem I have is when I pick two tin surfaces at a time, Revit creates one toposurface of the first tin surface I picked and another toposurface conisting of both tin surfaces. My goal is to create two separate toposurfaces. I can't figure out where I've messed up, can someone help me? I'll attatch a screencast and my code.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    public partial class Import_form : System.Windows.Forms.Form
    {


        public IAeccSurfaces surfs;
        public List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt; topos = new List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt;();
        private Autodesk.AutoCAD.Interop.IAcadApplication m_oAcadApp = null;
        private Autodesk.AECC.Interop.UiLand.IAeccApplication m_oAeccApp = null;
        private Autodesk.AECC.Interop.UiLand.IAeccDocument m_oAeccDoc = null;
        private IAeccDocuments m_oAeccDocs = null;
        private Autodesk.AECC.Interop.Land.IAeccDatabase m_oAeccDb = null;
        string m_sAcadProdID = "AutoCAD.Application";
        string m_sAeccAppProgId = "AeccXUiLand.AeccApplication.13.0";
        double[] triangles;
        List&amp;lt;double&amp;gt; nummer = new List&amp;lt;double&amp;gt;();


        public Import_form()
        {
            InitializeComponent();


            m_oAcadApp = (IAcadApplication)Marshal.GetActiveObject(m_sAcadProdID);


            if (m_oAcadApp != null)
            {
                m_oAeccApp = (Autodesk.AECC.Interop.UiLand.IAeccApplication)m_oAcadApp.GetInterfaceObject(m_sAeccAppProgId);
                m_oAeccDoc = (Autodesk.AECC.Interop.UiLand.IAeccDocument)m_oAeccApp.ActiveDocument;
                m_oAeccDocs = (Autodesk.AECC.Interop.UiLand.IAeccDocuments)m_oAeccApp.Documents;
                m_oAeccDb = (Autodesk.AECC.Interop.Land.IAeccDatabase)m_oAeccApp.ActiveDocument.Database;



                comboBox1.Items.Add(m_oAeccDoc);
                comboBox1.SelectedIndex = 0;
                comboBox1.DisplayMember = "Name";
                comboBox1.SelectedItem = m_oAeccDoc;
                surfs = m_oAeccDb.Surfaces;

                foreach (IAeccTinSurface surf in surfs)
                {
                    checkedListBox1.Items.Add(surf);

                }

                ((ListBox)checkedListBox1).DisplayMember = "Name";

            }

        }

        private void Import_form_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click_1(object sender, EventArgs e)
        {

            /*int antal = tjo.Count();
            MessageBox.Show(antal.ToString());*/

        }
        public static List&amp;lt;List&amp;lt;double&amp;gt;&amp;gt; splitlist(List&amp;lt;double&amp;gt; nummer, int antal = 3)
        {
            var list = new List&amp;lt;List&amp;lt;double&amp;gt;&amp;gt;();

            for (int i = 0; i &amp;lt; nummer.Count; i += antal)
            {
                list.Add(nummer.GetRange(i, Math.Min(antal, nummer.Count - i)));
            }
            return list;
        }

        private void checkedListBox1_Click(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            foreach (IAeccTinSurface valdsurface in checkedListBox1.CheckedItems)
            {
                triangles = valdsurface.OutputTriangles;
                List&amp;lt;XYZ&amp;gt; punkter = new List&amp;lt;XYZ&amp;gt;();
                List&amp;lt;XYZ&amp;gt; utpunkter = new List&amp;lt;XYZ&amp;gt;();

                double x = 0, y = 0, z = 0;
                foreach (double d in triangles)
                {
                    nummer.Add(d);
                }
                List&amp;lt;List&amp;lt;double&amp;gt;&amp;gt; uppdelning = splitlist(nummer, 3);
                foreach (List&amp;lt;double&amp;gt; uppdelat in uppdelning)
                {
                    for (int k = 0; k &amp;lt; uppdelat.Count; ++k)
                    {

                        int j = 1;

                        foreach (double d in uppdelat)
                        {

                            switch (j)
                            {
                                case 1:
                                    x = d;
                                    break;

                                case 2:
                                    y = d;
                                    break;
                                case 3:
                                    z = d;
                                    break;

                                default:
                                    break;

                            }
                            j++;
                        }
                        punkter.Add(new XYZ(x, y, z));
                    }
                }
                topos.Add(punkter);
            }
        }
    }&lt;/PRE&gt;&lt;PRE&gt; public class Civil_import : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiapp = commandData.Application;
            Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
            Autodesk.Revit.Creation.Application appcrea = uiapp.Application.Create;
            Autodesk.Revit.DB.Document doc = uiapp.ActiveUIDocument.Document;
            Autodesk.Revit.DB.View currentview = uiapp.ActiveUIDocument.ActiveView;
            List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt; lists_out = new List&amp;lt;List&amp;lt;XYZ&amp;gt;&amp;gt;();

            Import_form f = new Import_form();

             var result = f.ShowDialog();

             if(result==DialogResult.OK)
             {
                using (Transaction t = new Transaction(doc))
                {
                    t.Start("ett");

                    foreach (List&amp;lt;XYZ&amp;gt; punkter in f.topos)
                    {
                        List&amp;lt;XYZ&amp;gt; ut = new List&amp;lt;XYZ&amp;gt;();
                        GetVertices(ut, punkter);
                        lists_out.Add(ut);
                    }
                    foreach(List&amp;lt;XYZ&amp;gt; tops in lists_out)
                    {
                        TopographySurface.Create(doc, tops);
                    }
                    t.Commit();
                }
             }
             if (result==DialogResult.Cancel)
             {
                 return Result.Cancelled;
             }

            return Result.Succeeded;
        }
        const double _eps = 1.0e-9;
        
        public static bool IsZero(double a)
        {
            return _eps &amp;gt; Math.Abs(a);
        }

        public static bool IsEqual(double a, double b)
        {
            return IsZero(b - a);
        }

        public static int Compare(double a, double b)
        {
            return IsEqual(a, b) ? 0 : (a &amp;lt; b ? -1 : 1);
        }

        public static int Compare(XYZ p, XYZ q)
        {
            int diff = Compare(p.X, q.X);
            if (0 == diff)
            {
                diff = Compare(p.Y, q.Y);
                if (0 == diff)
                {
                    diff = Compare(p.Z, q.Z);
                }
            }
            return diff;
        }
        static void GetVertices(List&amp;lt;XYZ&amp;gt; listut, List&amp;lt;XYZ&amp;gt; listin)
        {

            Dictionary&amp;lt;XYZ, int&amp;gt; a
              = new Dictionary&amp;lt;XYZ, int&amp;gt;(
                new XyzComparer());



            foreach (XYZ p in listin)
            {
                if (!a.ContainsKey(p))
                {
                    a.Add(p, 1);
                }
                else
                {
                    ++a[p];
                }
            }

            List&amp;lt;XYZ&amp;gt; keys = new List&amp;lt;XYZ&amp;gt;(a.Keys);

            keys.Sort(Compare);

            foreach (XYZ p in keys)
            {

                listut.Add(p);
            }
        }
       

    }
    public class XyzComparer : IEqualityComparer&amp;lt;XYZ&amp;gt;
    {

        public bool Equals(XYZ p, XYZ q)
        {
            return p.IsAlmostEqualTo(q);
        }

        public int GetHashCode(XYZ p)
        {
            return p.ToString().GetHashCode();
        }


    }&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:02:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8981254#M40270</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-22T13:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Civil 3D generated toposurfaces from TIN surfaces</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8981378#M40271</link>
      <description>&lt;P&gt;It sounds to me as if your selection process is adding things to a list, and you are not clearing the list after processing it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 13:44:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8981378#M40271</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2019-08-22T13:44:55Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Civil 3D generated toposurfaces from TIN surfaces</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8983077#M40272</link>
      <description>&lt;P&gt;Thanks for the quick reply!&lt;/P&gt;&lt;P&gt;I think I have an Idea where to look.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Btw, kudos to your blog, I've learned a lot!&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 07:47:29 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8983077#M40272</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-08-23T07:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Civil 3D generated toposurfaces from TIN surfaces</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8983122#M40273</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please note that there are &lt;U&gt;&lt;STRONG&gt;two&lt;/STRONG&gt;&lt;/U&gt; methods to create a TopographySurface (Revit 2020 API).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have edges that you want to preserve, you better use&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;TopographySurface Create(
	Document document,
	IList&amp;lt;XYZ&amp;gt; points,
	IList&amp;lt;PolymeshFacet&amp;gt; facets
)&lt;/PRE&gt;&lt;P&gt;instead of&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;TopographySurface Create(
	Document document,
	IList&amp;lt;XYZ&amp;gt; points
)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Revitalizer&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 08:14:58 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/problem-with-civil-3d-generated-toposurfaces-from-tin-surfaces/m-p/8983122#M40273</guid>
      <dc:creator>Revitalizer</dc:creator>
      <dc:date>2019-08-23T08:14:58Z</dc:date>
    </item>
  </channel>
</rss>

