TheSwamp

Code Red => .NET => Topic started by: Jeff H on September 18, 2012, 03:58:27 PM

Title: LayerTable.GetUnreconciledLayers method
Post by: Jeff H on September 18, 2012, 03:58:27 PM
Has anyone used LayerTable.GetUnreconciledLayers method?
 
Of course the 'great' documentation shows to pass
 AcArray<AcDbObjectId,AcArrayMemCopyReallocator<AcDbObjectId>>* modopt(IsImplicitlyDereferenced) idArray 
with methods only used in IL.   
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: TheMaster on September 18, 2012, 06:42:00 PM
Has anyone used LayerTable.GetUnreconciledLayers method?
 
Of course the 'great' documentation shows to pass
 AcArray<AcDbObjectId,AcArrayMemCopyReallocator<AcDbObjectId>>* modopt(IsImplicitlyDereferenced) idArray 
with methods only used in IL.

AcArray<AcDbObjectId,AcArrayMemCopyReallocator<AcDbObjectId>>*
is what the managed ObjectIdCollection wraps.

But, because it was declared to take a pointer, you can't call it from verifiable managed code.

You should be able to P/Invoke the native member function directly, using something like this:

Code - C#: [Select]
  1.  
  2. public static class MyExtensions
  3. {
  4.    [DllImport("acdbxx.dll", CallingConvention=CallingConvention.ThisCall, EntryPoint=".....")]
  5.    public static extern void getUnreconciledLayers( IntPtr layerTable, IntPtr ids );
  6.  
  7.    public static void GetUnreconciledLayers( this LayerTable ltr, ObjectIdCollection ids )
  8.    {
  9.       getUnreconciledLayers( ltr.UnmanagedObject, ids.UnmanagedObject );
  10.    }
  11. }
  12.  
  13.  

Title: Re: LayerTable.GetUnreconciledLayers method
Post by: Jeff H on September 18, 2012, 07:25:21 PM
Thanks Tony!
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: BlackBox on June 05, 2013, 05:10:21 PM
I've recently been guided to this thread, but am having some difficulty implementing.

I was smart enough to swap:
Code - C#: [Select]
  1.     public static class MyExtensions
  2.     {
  3.         [DllImport("acdbxx.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = ".....")]
  4.         public static extern void getUnreconciledLayers(IntPtr layerTable, IntPtr ids);
  5.  
  6.         public static void GetUnreconciledLayers(this LayerTable ltr, ObjectIdCollection ids)
  7.         {
  8.             getUnreconciledLayers(ltr.UnmanagedObject, ids.UnmanagedObject);
  9.         }
  10.     }
  11.  

... With (for 2013):
Code - C#: [Select]
  1.         [DllImport("acdb19.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = ".....")]
  2.  

... However, I am utterly stumped on how to determine what my EntryPoint replacement should be?  :?

I cannot seem to find any documentation on this, if it's in the ObjectARX SDK, I have that just need some guidance on where to start reading.

Cheers
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: Jeff_M on June 05, 2013, 07:14:13 PM
You need to get the mangled name from the acdb18.dll using Dumpbin. See a write up Sinc did a few years ago abou the usage of P/Invoke & Dumpbin: http://www.quuxsoft.com/Programming/PInvoke.aspx

This is the mangled name you need to use for 2012:
?getUnreconciledLayers@AcDbLayerTable@@QEBA?AW4ErrorStatus@Acad@@AEAV?$AcArray@VAcDbObjectId@@V?$AcArrayMemCopyReallocator@VAcDbObjectId@@@@@@@Z

Replace the "...." for the EntryPoint with the above in quotes.
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: Jeff_M on June 05, 2013, 07:35:40 PM
Modifying Tony's sample to be more 2014'ish, I came up with this:
Code - C#: [Select]
  1. using System;
  2. using System.Runtime.InteropServices;
  3. using Autodesk.AutoCAD.ApplicationServices;
  4. using Autodesk.AutoCAD.DatabaseServices;
  5. using Autodesk.AutoCAD.Runtime;
  6.  
  7. namespace Namespace1
  8. {
  9.     public static class MyExtensions
  10.     {
  11.         [DllImport("acdb18.dll", CallingConvention = CallingConvention.ThisCall, EntryPoint = "?getUnreconciledLayers@AcDbLayerTable@@QEBA?AW4ErrorStatus@Acad@@AEAV?$AcArray@VAcDbObjectId@@V?$AcArrayMemCopyReallocator@VAcDbObjectId@@@@@@@Z")]
  12.         private static extern void getUnreconciledLayers(IntPtr layerTable, IntPtr ids);
  13.  
  14.         public static ObjectIdCollection GetUnreconciledLayers(this LayerTable ltr)
  15.         {
  16.             ObjectIdCollection ids = new ObjectIdCollection();
  17.             getUnreconciledLayers(ltr.UnmanagedObject, ids.UnmanagedObject);
  18.             return ids;
  19.         }
  20.  
  21.     }
  22.     public class Mycmds
  23.     {
  24.         [CommandMethod("TestMe")]
  25.         public void testme()
  26.         {
  27.             ObjectIdCollection ids = new ObjectIdCollection();
  28.             Document doc = Application.DocumentManager.MdiActiveDocument;
  29.             Database db = doc.Database;
  30.             using (Transaction tr = HostApplicationServices.WorkingDatabase.TransactionManager.StartTransaction())
  31.             {
  32.                 LayerTable lt = (LayerTable)db.LayerTableId.GetObject(OpenMode.ForRead);
  33.                 ids = lt.GetUnreconciledLayers();
  34.                 tr.Commit();
  35.             }
  36.             doc.Editor.WriteMessage("\nFound {0} layers", ids.Count);
  37.         }
  38.  
  39.     }
  40. }
  41.  
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: BlackBox on June 06, 2013, 12:41:48 AM
You need to get the mangled name from the acdb18.dll using Dumpbin. See a write up Sinc did a few years ago abou the usage of P/Invoke & Dumpbin: http://www.quuxsoft.com/Programming/PInvoke.aspx

This is the mangled name you need to use for 2012:
?getUnreconciledLayers@AcDbLayerTable@@QEBA?AW4ErrorStatus@Acad@@AEAV?$AcArray@VAcDbObjectId@@V?$AcArrayMemCopyReallocator@VAcDbObjectId@@@@@@@Z

Replace the "...." for the EntryPoint with the above in quotes.

Dumpbin... Never heard of it before... Thank you (and Sinc) for educating me!  :-)

Cheers
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: Kerry on June 06, 2013, 01:11:01 AM
Quote
Dumpbin... Never heard of it before...

http://www.theswamp.org/index.php?topic=41527.msg466302#msg466302
http://www.theswamp.org/index.php?topic=34278.msg395811#msg395811
http://www.theswamp.org/index.php?topic=41088.msg463022#msg463022

http://msdn.microsoft.com/en-us/library/aa446532.aspx

I thought I'd posted for 2014 as well, but I can't find it.
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: MexicanCustard on June 06, 2013, 09:16:22 AM

Dumpbin... Never heard of it before... Thank you (and Sinc) for educating me!  :-)

Cheers

I use DependencyWalker instead.  Just to give you options.
Title: Re: LayerTable.GetUnreconciledLayers method
Post by: BlackBox on June 06, 2013, 11:31:27 AM
TheSwamp is awesome... Thanks Kerry, and MexicanCustard!  :-)