Author Topic: SurfaceOperationCollection sorting SurfaceOperationObjects  (Read 1932 times)

0 Members and 1 Guest are viewing this topic.

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
SurfaceOperationCollection sorting SurfaceOperationObjects
« on: March 06, 2016, 04:40:42 AM »
Hello!
I have read SurfaceOperationCollection from a Surface in a Drawing. This Surface have different types(or SurfaceOperations included). All these SurfaceOperation are in right sorting in Collection before I do somthing with Surface (for example remove or create new SurfaceOperations as breakline, contours or boundaries...). After editing I want same sorting in Surface as before.
In SurfaceOperation it haves different metods as MoveUp() or MoveDown(). Have somebody worked with them in Sytax of Linq. I´m very thankfully to get some suggestions

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: SurfaceOperationCollection sorting SurfaceOperationObjects
« Reply #1 on: March 06, 2016, 04:50:23 AM »
Maybe better description:
I have to remove a boundary in a Surface, and than recreate them and set the same name as before. The position of recreated boundary is in the end of SurfacOperationCollection. But it have to come in position 2 (for example)

Code: [Select]
        public static SurfaceOperationCollection ReadSurfaceOperations(TinSurface tinsurf)
        {
            Document acadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            using (Transaction tr = acadDoc.TransactionManager.StartTransaction())
            {
                SurfaceOperationCollection SuOpColl = tinsurf.Operations;
                tr.Commit();

                return SuOpColl;
            }
        }

        public static void SortSurfaceOperations(SurfaceOperationCollection before, SurfaceOperationCollection after)
        {
            Document acadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            using (Transaction tr = acadDoc.TransactionManager.StartTransaction())
            {
                var m_Bef = from x in before.GetType().FullName
                            //where x.GetType().FullName == "Autodesk.Civil.DatabaseServices.SurfaceOperationAddBoundary"
                            select x;

                var m_Aft = from x in before.GetType().FullName
                            //where x.GetType().FullName == "Autodesk.Civil.DatabaseServices.SurfaceOperationAddBoundary"
                            select x;

                foreach(SurfaceOperation x in m_Bef)
                {
                    foreach(SurfaceOperation y in m_Aft)
                    {
                        if(x != y)
                        {
                            y.MoveUp();
                        }
                    }
                }

                tr.Commit();
            }
        }
« Last Edit: March 06, 2016, 09:05:59 AM by cadplayer »

Jeff_M

  • King Gator
  • Posts: 4096
  • C3D user & customizer
Re: SurfaceOperationCollection sorting SurfaceOperationObjects
« Reply #2 on: March 06, 2016, 01:38:37 PM »
Dirk, you cannot use Linq with the SurfaceOperationCollection as it does not have a GetEnumerator() method. Just as you cannot use foreach() with this collection. Therefor you have to use a for() loop. The following code is not tested, but should work (or be close to working, anyway).

Code - C#: [Select]
  1.         public static void SortSurfaceOperations(SurfaceOperationCollection before, SurfaceOperationCollection after)
  2.         {
  3.             Document acadDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
  4.             using (Transaction tr = acadDoc.TransactionManager.StartTransaction())
  5.             {
  6.                 bool done = false;
  7.                 for (int i = 0; i < before.Count;i++ )
  8.                 {
  9.                     var x = before[i];
  10.                     if (x.GetType() == typeof(SurfaceOperationAddBoundary))
  11.                     {
  12.                         for (int j = 0; j < after.Count; j++)
  13.                         {
  14.                             var y = after[j];
  15.                             if (y.GetType() == typeof(SurfaceOperationAddBoundary))
  16.                             {
  17.                                 while (i < j)
  18.                                 {
  19.                                     y.MoveUp();
  20.                                     j--;
  21.                                 }
  22.                                 done = true;
  23.                                 break;
  24.                             }
  25.                         }
  26.                     }
  27.                     if (done)
  28.                         break;
  29.                 }
  30.                 tr.Commit();
  31.             }
  32.         }
  33.  

cadplayer

  • Bull Frog
  • Posts: 390
  • Autocad Civil3d, OpenDCL.Runtime, LISP, .NET (C#)
Re: SurfaceOperationCollection sorting SurfaceOperationObjects
« Reply #3 on: March 07, 2016, 10:27:18 AM »
Thanks again Jeff!
You are my "friend in need"