Author Topic: SymbolTable Iteration, Enumeration  (Read 12077 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
SymbolTable Iteration, Enumeration
« on: May 09, 2007, 06:29:20 AM »
Does VB.net have a foreach function or equivalent for stepping through a list. ?


I saw some VB code this afternoon that used SymbolTableEnumerator

I've done some quick tests and it seems about 40% slower than foreach.

If thats so, I'm sorry :-(


added; really, I am ! there MUST be a better way ...
though I s'pose its only a couple of milliseconds difference to itterate a decent layer list.
Command: LayerListTimer

 Timer for 1000 iterations :
 Total Time LayerList1 Enumerator <second>: 5.47726735744158
 Total Time LayerList2 foreach      <second>: 3.41111156322627

« Last Edit: May 09, 2007, 06:36:50 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #1 on: May 09, 2007, 09:33:55 AM »
Because someone will probably ask ..

Code: [Select]
// Codehimbelonga kwb@theSwamp 20070509
// For AC2008: VS2005

#region usingdeclarations

using System;
using System.Windows.Forms;

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.Colors;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;

#endregion

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

[assembly: CommandClass(typeof(kdubTestStuff.kdubTestStuff))]

namespace kdubTestStuff
{
    /// <summary>
    /// Summary for kdubTestStuff
    /// </summary>
    public class kdubTestStuff : IExtensionApplication
    {
        /// <summary>
        ///
        /// </summary>
        public void Initialize()
        {
            //Let the user know what's happening while loading your stuff 
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;

            ed.WriteMessage("\nConcept Code For AC2008, MSVS2005 :: kwb@theSwamp 20070509 ->> ...");
            ed.WriteMessage("\nType < LayerListTimer >: \n");
        }
        /// ---------
        ///
        public void Terminate()
        {
            //Nothing to see here yet, move along !
        }
        /// ---------
        /// 
        [CommandMethod("LayerListTimer")]
        public static void LayerListTimer()
        {
            QueryPerfCounter qpc = new QueryPerfCounter();
            qpc.Start();
            // Call the object and methods to JIT before the test run.
            qpc.Stop();
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            int iterations = 500;
            //
            qpc.Start();
            for (int a1 = 0; a1 < iterations; a1++)
            {
                LayerList1();
            }
            qpc.Stop();
            double timer1 = (qpc.Duration(1) * 1.0e-9);
            //
            qpc.Start();
            for (int a2 = 0; a2 < iterations; a2++)
            {
                LayerList2();
            }
            qpc.Stop();
            double timer2 = (qpc.Duration(1) * 1.0e-9);
            //
            ed.WriteMessage("\n Timer for " + iterations + " iterations : ");
            ed.WriteMessage("\n Total Time LayerList1 Enumerator <second>: " + timer1.ToString());
            ed.WriteMessage("\n Total Time LayerList2 foreach    <second>: " + timer2.ToString());

        }
        /// ---------
        /// 
        [CommandMethod("LayerList1")]
        public static void LayerList1()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {   // Get a pointer to the layer table...
                    LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead, false) as LayerTable;

                    // Iterate the table and print out all the layer names...
                    SymbolTableEnumerator ltItem = lt.GetEnumerator();
                    while (ltItem.MoveNext())
                    {
                        LayerTableRecord ltr = ltItem.Current.GetObject(OpenMode.ForRead) as LayerTableRecord;
                        // comment out writemessage for speed test
                       ed.WriteMessage("\nLayer name: {0}", ltr.Name);
                    }
                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception aex)
                {
                    ed.WriteMessage("\nError: " + aex.Message);
                    return;
                }
            }
        }   
        /// ---------
        /// 
        [CommandMethod("LayerList2")]
        public static void LayerList2()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {   // Get a pointer to the layer table...
                    LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead, false) as LayerTable;

                    // Loop the table and print out all the layer names...
                    foreach (ObjectId ltrId in lt)
                    {
                        LayerTableRecord ltr = tr.GetObject(ltrId, OpenMode.ForRead) as LayerTableRecord ;
                        // comment out writemessage for speed test
                        ed.WriteMessage("\nLayer name: {0}", ltr.Name);

                    }
                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception aex)
                {
                    ed.WriteMessage("\nError: " + aex.Message);
                    return;
                }
            }
        }
   }       
}           

Code: [Select]
// QueryPerfCounter.cs
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;

/// <summary>
/// Time Managed Code Using QueryPerformanceCounter and QueryPerformanceFrequency
/// Chapter 5 — Improving Managed Code Performance
/// http://msdn2.microsoft.com/en-us/library/ms998547.aspx
///
/// From http://msdn2.microsoft.com/en-us/library/ms979201.aspx
/// </summary>

public class QueryPerfCounter
{
    [DllImport("KERNEL32")]
    private static extern bool QueryPerformanceCounter(
      out long lpPerformanceCount);

    [DllImport("Kernel32.dll")]
    private static extern bool QueryPerformanceFrequency(out long lpFrequency);

    private long start;
    private long stop;
    private long frequency;
    Decimal multiplier = new Decimal(1.0e9);

    public QueryPerfCounter()
    {
        if (QueryPerformanceFrequency(out frequency) == false)
        {
            // Frequency not supported
            throw new Win32Exception();
        }
    }

    public void Start()
    {
        QueryPerformanceCounter(out start);
    }

    public void Stop()
    {
        QueryPerformanceCounter(out stop);
    }

    public double Duration(int iterations)
    {
        return ((((double)(stop - start) * (double)multiplier) / (double)frequency) / iterations);
    }
}


edit: AcRx alias reference removed to suit EagleEyeDan
« Last Edit: May 10, 2007, 12:06:24 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #2 on: May 09, 2007, 12:11:49 PM »
Very nice! but where are all your pretty aliases, like
Code: [Select]
using AcRx = Autodesk.AutoCAD.Runtime;


It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #3 on: May 09, 2007, 12:36:02 PM »
Wow that’s a big difference. I wonder what mojo foreach has ?

TonyT

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #4 on: May 09, 2007, 01:37:09 PM »
Quote
Does VB.net have a foreach function or equivalent for stepping through a list. ?

Yes.

   For Each(var As Type in SomeEnumerableObject )
      'blah blah blah
   Next

The reason you often see VB code that uses IEnumerator
directly rather than For Each, is because the programmmer
got the code from Reflector's disassembly, which may not
know how to reverse-engineer the compiled code back to
the original source construct. That's possibly because VB's
For Each, and the C# foreach() are both compiler-provided
(and compiler specific) syntactic sugar, that compiles down
to IL code that manipulates the methods of the enumerator
directly.

I don't have any definitive conclusion that explains the
differences you see, but you might gain some insight into
what's going on, by looking at both of your functions in
Reflector, rendered as IL.

Does VB.net have a foreach function or equivalent for stepping through a list. ?

I saw some VB code this afternoon that used SymbolTableEnumerator

I've done some quick tests and it seems about 40% slower than foreach.

If thats so, I'm sorry :-(


added; really, I am ! there MUST be a better way ...
though I s'pose its only a couple of milliseconds difference to itterate a decent layer list.
Command: LayerListTimer

 Timer for 1000 iterations :
 Total Time LayerList1 Enumerator <second>: 5.47726735744158
 Total Time LayerList2 foreach      <second>: 3.41111156322627



It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #5 on: May 09, 2007, 02:09:22 PM »
Ok Somebody port me a vb.net version  :lol:

C#
Total Time LayerList1 Enumerator <second>: 3.12422333006011
 Total Time LayerList2 foreach    <second>: 2.59995641904209

Cli/pure
Total Time LayerList1 Enumerator <second>: 3.13418465195996
 Total Time LayerList2 foreach    <second>: 2.63695413802592

Cli/Safe
Total Time LayerList1 Enumerator <second>: 3.15575163882561
 Total Time LayerList2 foreach    <second>: 2.62447182532976

/cli
Total Time LayerList1 Enumerator <second>: 3.12029852956172
 Total Time LayerList2 foreach    <second>: 2.60115238109872

Nathan Taylor

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #6 on: May 09, 2007, 06:29:00 PM »
Ok Somebody port me a vb.net version  :lol:

This C# to VB.NET converter works well.

http://www.developerfusion.co.uk/utilities/convertcsharptovb.aspx

Regards - Nathan

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #7 on: May 09, 2007, 06:56:42 PM »
Dan, From Roeders ..
The QueryPerfCounter can be referenced as DLL
... Have I mentioned I really dislike using Dim ..

added: the iterations and reporting is slightly different that the posted code 'cause I reflected this from my current DLL.
The tested methods are functionally the same

Code: [Select]
Public Class kdubTestStuff
    Implements IExtensionApplication
    ' Methods
    Public Sub Initialize()
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        ed.WriteMessage(ChrW(10) & "Concept Code For AC2008, MSVS2005 :: kwb@theSwamp 20070509 ->> ...")
        ed.WriteMessage(ChrW(10) & "Type < LayerListTimer >: " & ChrW(10))
    End Sub

    <CommandMethod("LayerList1")> _
    Public Shared Sub LayerList1()
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Using tr As Transaction = db.TransactionManager.StartTransaction
            Try
                Dim ltItem As SymbolTableEnumerator = TryCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead, False),LayerTable).GetEnumerator
                Do While ltItem.MoveNext
                    Dim ltr As LayerTableRecord = TryCast(ltItem.Current.GetObject(OpenMode.ForRead),LayerTableRecord)
                    ed.WriteMessage(ChrW(10) & "Layer name: {0}", New Object() { ltr.Name })
                Loop
                tr.Commit
            Catch aex As Exception
                ed.WriteMessage((ChrW(10) & "Error: " & aex.Message))
            End Try
        End Using
    End Sub

    <CommandMethod("LayerList2")> _
    Public Shared Sub LayerList2()
        Dim db As Database = HostApplicationServices.WorkingDatabase
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Using tr As Transaction = db.TransactionManager.StartTransaction
            Try
                Dim lt As LayerTable = TryCast(tr.GetObject(db.LayerTableId, OpenMode.ForRead, False),LayerTable)
                Dim ltrId As ObjectId
                For Each ltrId In lt
                    Dim ltr As LayerTableRecord = TryCast(tr.GetObject(ltrId, OpenMode.ForRead),LayerTableRecord)
                    ed.WriteMessage(ChrW(10) & "Layer name: {0}", New Object() { ltr.Name })
                Next
                tr.Commit
            Catch aex As Exception
                ed.WriteMessage((ChrW(10) & "Error: " & aex.Message))
            End Try
        End Using
    End Sub

    <CommandMethod("LayerListTimer")> _
    Public Shared Sub LayerListTimer()
        Dim qpc As New QueryPerfCounter
        qpc.Start
        qpc.Stop
        qpc.Start
        Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
        Dim iterations As Integer = 100
        qpc.Start
        Dim a1 As Integer
        For a1 = 0 To iterations - 1
            kdubTestStuff.LayerList1
        Next a1
        qpc.Stop
        Dim timer1 As Double = (qpc.Duration(1) * 1E-09)
        qpc.Start
        Dim a2 As Integer
        For a2 = 0 To iterations - 1
            kdubTestStuff.LayerList2
        Next a2
        qpc.Stop
        Dim timer2 As Double = (qpc.Duration(1) * 1E-09)
        ed.WriteMessage((ChrW(10) & " Total Time LayerList1 Enumerator <nanosecond>: " & timer1.ToString))
        ed.WriteMessage((ChrW(10) & " Total Time LayerList2 foreach    <nanosecond>: " & timer2.ToString))
    End Sub

    Public Sub Terminate()
    End Sub



« Last Edit: May 09, 2007, 07:00:36 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #8 on: May 09, 2007, 07:46:28 PM »
........
Yes.

   For Each(var As Type in SomeEnumerableObject )
      'blah blah blah
   Next

...............

Thanks Tony. Yep, the 'For Each ...' construct dawned on me going to sleep last night.

No, guys, I'm not migrating to vbnet .. just saw the Enumerator used on some sample code and thought I'd test it.
I recalled that Glenn brought me to task for using Enumeration last year some time, and just wanted a demonstrable confirmation ...
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #9 on: May 09, 2007, 07:49:26 PM »
Kerry,

Can you change this:
Code: [Select]
LayerTableRecord ltr = ltItem.Current.GetObject(OpenMode.ForRead) as LayerTableRecord;

to this:
Code: [Select]
LayerTableRecord ltr = tr.GetObject(ltItem.Current, OpenMode.ForRead, false) as LayerTableRecord;

and see what happens please?

Cheers,
TaskMaster. :)           

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #10 on: May 09, 2007, 08:00:10 PM »
.............
and see what happens please?

Cheers,
TaskMaster. :)          
It didn't explode :-)
Command: LayerListTimer
 Timer for 1000 iterations :
 Total Time LayerList1 Enumerator  <second>: 5.60449242886492
 Total Time LayerList2 foreach     <second>: 3.58251633388723
 Total Time LayerList1a Enumerator <second>: 3.64621301722951

..... so the problem was the getter  .... not the enumerator !

added: though on checking, the code I used originally was the construct in the sample   :|
« Last Edit: May 09, 2007, 08:06:45 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Glenn R

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #11 on: May 09, 2007, 08:03:07 PM »
So they are about the same now?

I think you were mixing your open/close mechanisms (using raw open/close like ARX and transactional), but I'm not quite sure what iterator.Current.GetObject() is doing in the background...

Anyway, just an observation...carry on.

Cheers,
Glenn.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #12 on: May 09, 2007, 11:46:05 PM »
Very nice! but where are all your pretty aliases, like
Code: [Select]
using AcRx = Autodesk.AutoCAD.Runtime;
These ??
Code: [Select]
#region usingAliases

// Shortcuts to the managed classes ..
using AcAp = Autodesk.AutoCAD.ApplicationServices;   
using AcCo = Autodesk.AutoCAD.Colors;               
using AcDb = Autodesk.AutoCAD.DatabaseServices;   
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcWin = Autodesk.AutoCAD.Windows;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

#endregion
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #13 on: May 09, 2007, 11:49:54 PM »
Here's the Block Table lister if anyone's interested .. similar/same-same
Code: [Select]
        [CommandMethod("BlockList2")]
        public static void BlockList2()
        {
            Database db = HostApplicationServices.WorkingDatabase;
            Editor ed = AcadApp.DocumentManager.MdiActiveDocument.Editor;
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                try
                {   // Get a pointer to the layer table...
                    BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead, false) as BlockTable;
                   
                    foreach (ObjectId btrId in bt)
                    {   // Loop the block table and print out all the Block Reference names...
                        BlockTableRecord btr = tr.GetObject(btrId, OpenMode.ForRead) as BlockTableRecord;
                        // exclude the P' and M'Spaces and anonomous blocks
                                  //if (!(btr.Name.StartsWith("*")))
                                  //    ed.WriteMessage("\nBlock name: {0}", btr.Name);
                        if (!(btr.IsAnonymous || btr.IsLayout))
                        {                           
                            ed.WriteMessage("\nBlock name: {0}", btr.Name);
                        }                    }
                    tr.Commit();
                }
                catch (Autodesk.AutoCAD.Runtime.Exception aex)
                {
                    ed.WriteMessage("\nError: " + aex.Message);
                    return;
                }
            }
        }

EDIT: String compare of block name changed to property Test
« Last Edit: May 11, 2007, 04:46:05 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #14 on: May 09, 2007, 11:57:46 PM »
Very nice! but where are all your pretty aliases, like
Code: [Select]
using AcRx = Autodesk.AutoCAD.Runtime;
These ??
Code: [Select]
#region usingAliases

// Shortcuts to the managed classes ..
using AcAp = Autodesk.AutoCAD.ApplicationServices;   
using AcCo = Autodesk.AutoCAD.Colors;               
using AcDb = Autodesk.AutoCAD.DatabaseServices;   
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcWin = Autodesk.AutoCAD.Windows;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

#endregion


Yes the class in your fisrt post needed the AcRx one for AcRx.IExtensionApplication to compile.
I wish C++/CLI had the ability to do this aliasing.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #15 on: May 10, 2007, 12:09:19 AM »
Ta Dan !
Fixed.

Typing up Some of the C++ Managed I've seen would ruin my old wrists ... not to mention the gray wet stuff.
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #16 on: May 10, 2007, 12:30:28 AM »
Has anyone come across a quick way to count the Symbol Table entries .. other than iterating and +=

.. I feel like I'm missing something thats probably obvious ..  :|
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #17 on: May 10, 2007, 04:11:29 AM »
Has anyone come across a quick way to count the Symbol Table entries .. other than iterating and +=

.. I feel like I'm missing something thats probably obvious ..  :|

It is some sort of resbuf chain, I would say you would have to iterate through to get the count

Dan

edit: butter fingers
« Last Edit: May 10, 2007, 04:39:04 AM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #18 on: May 10, 2007, 04:17:19 AM »
Thanks Dan, no, really :-)
I feared as much !
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #19 on: May 10, 2007, 04:43:02 AM »
Thanks Dan, no, really :-)
I feared as much !

Doesn’t VB have some sort of   “Get friendly Dim count of enumerated container thingy method”?
« Last Edit: May 10, 2007, 04:46:27 AM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #20 on: May 10, 2007, 04:49:11 AM »

Doesn’t VB have some sort of   “Get friendly Dim count of enumerated container thingy method”?

>>  thingy method ?

I hate those VB technical terms  :D
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Paul Richardson

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #21 on: May 10, 2007, 09:41:12 AM »
Very nice! but where are all your pretty aliases, like
Code: [Select]
using AcRx = Autodesk.AutoCAD.Runtime;
These ??
Code: [Select]
#region usingAliases

// Shortcuts to the managed classes ..
using AcAp = Autodesk.AutoCAD.ApplicationServices;   
using AcCo = Autodesk.AutoCAD.Colors;               
using AcDb = Autodesk.AutoCAD.DatabaseServices;   
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcWin = Autodesk.AutoCAD.Windows;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

#endregion
I wish C++/CLI had the ability to do this aliasing.

Me too! :(

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel

Paul Richardson

  • Guest

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8690
  • AKA Daniel
Re: SymbolTable Iteration, Enumeration
« Reply #24 on: May 10, 2007, 10:20:26 AM »
I also wanted to share with you, that sometimes, 
if you comment the #includes intellisence begins to work.. sometimes.. 

Paul Richardson

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #25 on: May 10, 2007, 10:32:44 AM »
I also wanted to share with you, that sometimes, 
if you comment the #includes intellisence begins to work.. sometimes.. 

Thanks, We'll get it. I'm going to play this weekend.

Also I tried the "Whole Tomato" but it is just overkill! Not too bad with C++ but when you open C# it's just a mess of data being suggested by intellisense - I uninstalled it...

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: SymbolTable Iteration, Enumeration
« Reply #26 on: May 11, 2007, 04:40:39 AM »
Just because it seems to make more sense to use the BlockTableRecord Properties,
I changed this in the BLOCK Lister:
Code: [Select]
                       if (!(btr.Name.StartsWith("*")))
                            ed.WriteMessage("\nBlock name: {0}", btr.Name);

to this:
Code: [Select]
                        // exclude the P' and M'Spaces and anonomous blocks
                        if (!(btr.IsAnonymous || btr.IsLayout))
                            ed.WriteMessage("\nBlock name: {0}", btr.Name);

PICCY ADDED:
« Last Edit: May 11, 2007, 04:59:06 AM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

Draftek

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #27 on: May 11, 2007, 08:15:14 AM »
Very nice! but where are all your pretty aliases, like
Code: [Select]
using AcRx = Autodesk.AutoCAD.Runtime;
These ??
Code: [Select]
#region usingAliases

// Shortcuts to the managed classes ..
using AcAp = Autodesk.AutoCAD.ApplicationServices;   
using AcCo = Autodesk.AutoCAD.Colors;               
using AcDb = Autodesk.AutoCAD.DatabaseServices;   
using AcEd = Autodesk.AutoCAD.EditorInput;
using AcGe = Autodesk.AutoCAD.Geometry;
using AcGi = Autodesk.AutoCAD.GraphicsInterface;
using AcLy = Autodesk.AutoCAD.LayerManager;
using AcPl = Autodesk.AutoCAD.PlottingServices;
using AcRx = Autodesk.AutoCAD.Runtime;
using AcWin = Autodesk.AutoCAD.Windows;

using AcadApp = Autodesk.AutoCAD.ApplicationServices.Application;

#endregion
I wish C++/CLI had the ability to do this aliasing.

Me too! :(

ooOOOOkayyy! That explains a lot.

TonyT

  • Guest
Re: SymbolTable Iteration, Enumeration
« Reply #28 on: May 12, 2007, 04:04:44 PM »

Has anyone come across a quick way to count the Symbol Table entries .. other than iterating and +=   .. I feel like I'm missing something thats probably obvious ..  :|

Given that there's no way to do it in native ARX
without iteration, I would guess not.

Interesting side note is that many VBA/ActiveX programmers
do not have the slightest idea how horribly ineffecient code
like this is:

Code: [Select]

   AcadApplication Acad = ///

   AcadBlocks blocks = Acad.ActiveDocument.Blocks;
   for(int i = 0; i < blocks.Count; i++ )
       DoSomethingWith( blocks.Item[i] );

  
The Count property of all ActiveX symbol table wrappers
must also do exactly what you'd like to avoid :), and the
Item[] indexer must also do the same thing (to find the
element at a given index position).

« Last Edit: May 12, 2007, 04:14:05 PM by TonyT »