Problem with MPolygon observed as ImpEntity

Problem with MPolygon observed as ImpEntity

Anonymous
Not applicable
3,319 Views
10 Replies
Message 1 of 11

Problem with MPolygon observed as ImpEntity

Anonymous
Not applicable
In one of your clients, we currently have a quite big cadastre solution that contains different applications in different platforms. One of the key components of that solution is an AutoCAD Map application, actually deployed in about 30 workstations over the client's network.

The application was developed using:

• Oracle 9.2.1 / Spatial
• NET Framework 2.0 / C# (v2.0.50727)
• AutoCAD Map 2006
• .NET ObjectARX Wrappers (ver. 2006)

Each workstation have identical software installations:

• Microsoft Windows 2000 Professional + Service Pack 4
• Autodesk DWF Viewer
• Autodesk Map 3D 2006
• Autodesk Mapguide Dynamic Authoring Toolkit Release 6.5
• Autodesk Mapguide Viewer Activex Control Release 6.5
• Autodesk LandXML Reporting 6
• Oracle 9.2.1 Client Software

Now, in a specific point of the application, it needs to validate that every one of the selected objects in the current AMap document are actually of the "MPolygon" type. If that validation is ok, the selected objects are casted as actual MPolygon objects inside the code for future usage in the code.

The problem now is that in some worksatations, when the application starts the validation, it returns that the selected objects are "ImpEntity" and not "MPolygon". The validation of course can't complete successfully, and even if I bypass the validation, the objects can't be casted as MPolygons either, rising an application error.

After the first occurrence of this situation (which happens randomly in time), the application never come back to work properly again in that workstation, that is, it always return ImpEntity as the object type when selections are MPoligons.

For testing this situation I developed a small Amap command:

-----------------------------------------------------------------

1 #region TestTipoObjeto()
2 [Autodesk.AutoCAD.Runtime.CommandMethodAttribute("TestTipoObjeto")]
3 public void TestTipoObjeto()
4 {
5 testTipoObjeto();
6 }
7 #endregion
8
9 #region testTipoObjeto()
10 public void testTipoObjeto()
11 {
12 try
13 {
14 Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
15 acDoc.LockDocument();
16 ObjectIdCollection colObjectId = SelectObjects(acDoc, true);
17 if (colObjectId.Count > 0)
18 {
19 using (AcDb.Database db = acDoc.Database)
20 {
21 using (AcDb.Transaction trans = db.TransactionManager.StartTransaction())
22 {
23 string msg = string.Empty;
24 foreach (ObjectId objectId in colObjectId)
25 {
26 Entity dbObject = trans.GetObject(objectId, AcDb.OpenMode.ForRead) as Entity;
27
28 string entityType = dbObject.GetType().Name;
29 msg += ">> ACad Type = " + entityType + "\n";
30
31 object obj = dbObject.AcadObject;
32 PropertyDescriptor pd = TypeDescriptor.GetProperties(obj)["ObjectName"];
33 string baseTipo = (string)pd.GetValue(obj);
34 msg += ">> Base Type = " + baseTipo + "\n";
35
36 try
37 {
38 AcDb.MPolygon acMPolygon = (AcDb.MPolygon)trans.GetObject(objectId, AcDb.OpenMode.ForWrite, true);
39 msg += ">> Cast OK \n";
40 }
41 catch (Exception ex)
42 {
43 msg += ">> Error: " + ex.Message.ToString() + "\n";
44 }
45
46 trans.Commit();
47 }
48 AcadEditor.WriteMessage("\nTipos de Objeto: " + msg + " \n");
49 }
50 }
51 }
52 }
53 catch (System.Exception ex)
54 {
55 AcadEditor.WriteMessage("\nError Message: " + ex.Message.ToString() + " \n");
56 AcadEditor.WriteMessage("\nError Stack: " + ex.StackTrace.ToString() + " \n");
57 }
58 }
59 #endregion

-----------------------------------------------------------------

If the application is working properly:

a) The string entityType at line 28 returns "MPolygon"
b) The string baseTipo at line 33 returns "AcDbMPolygon"
c) The cast at line 38 works well

If the application is broken:

a) The string entityType at line 28 returns "ImpEntity"
b) The string baseTipo at line 33 returns "AcDbMPolygon"
c) The cast at line 38 works well

The objects in the document can be objects that were drawn by the user in his current session, of objects that were retrieved from the Oracle Database.

Now, my current research on this issue:

First, i found the following thead in this forum:
http://discussion.autodesk.com/thread.jspa?threadID=604438
In that thread, Tony Tanzillo wrote: "ImpEntity is one of the managed wrapper types that get created, if there is no application-specific managed wrapper implemented for a given custom object type, or the managed wrappers for the custom object are not being loaded", wich seems quite logical.

So, my question is: How can I know exactly which is the managed wrapper for "MPolygon" that is apparently not loaded? And of course, how can I load it on demand? (i.e.: when the application starts)

Meanwhile, I found a temporary "workaround". On a "broken" machine, I open AMap, go to Tools -> Options -> Profiles, click on "Reset" (which unload every application inside AMap) and finally I import a profile file that was generated in a clean "not broken" machine. I quickly realized that the operation that solved the problem was reseting the actual profile, and not loading a new one, but it was necessary to restore the original applications inside AMap (like toolbars, etc).

Obviously, for our client, this isn't a solution for the problem, in any way, but it helped somehow.

In the other hand, it was difficult to reproduce the problem, as we didn't know how to make AMap behave that way. But a few days ago, I found something really strange. In my development workstation (that is not broken), if I open AMap (using the desktop icon), draw a MPolygon, and finally run my "TestTipoObjeto" command over that object, it tells me that it's actually an "MPolygon".

But if I save that document as a new .DWG, close AMap, and reopen it using doubleclicking the .DWG I just created... when I run the command over the saved polygon it return that it's an "ImpEntity" object. I'm not quite sure, but this is actually my only way to reproduce the issue in the development enviroment.

Finally, using an external Windows Application (also developed with C#) I tried to compare the running processes and dependent modules on my machine, when the app return "MPolygon" and when the app return "ImpEntity", maybe with the hope of finding the "missing managed wrapper", with no success.

So, I'm really stuck with this problem now.
Any help will be really appreciated.

Thanks in advance.
0 Likes
3,320 Views
10 Replies
Replies (10)
Message 2 of 11

Anonymous
Not applicable
Hi!!!
I have been at that point some times... Well I found the assemly, it's called AcMPolygonMGD.dll and it's located at your AutoCad folder, you need to add it as a reference to your project and voila!!!

hope this helps!!!
0 Likes
Message 3 of 11

Anonymous
Not applicable
Thanks. I searched the file in my AutoCad folder, but it isn't there. I did a file search in all hard drives and no success either.

I goggled for AcMPolygonMGD.dll and it seems that it's an AMap 2007 or 2008 file. It's possible that the assembly is called different in AMap 2006?
0 Likes
Message 4 of 11

Anonymous
Not applicable
Sorry about that I haven't noticed it, really in 2k6 I don't know, I hope someone knows here, so I'll look into another projects to see...
0 Likes
Message 5 of 11

Anonymous
Not applicable

I am having the same problem in Acad2010. I added the reference to AcMPolygonMGD.dll, I can create a MPolygon in Acad, the type MPolygon is recognized in VSS2008, but when I get the object (using transaction.GetObject) it is not of the type MPolygon but of the type ImpEntity. Casting explicitly to MPolygon fails.

Does anyone have an idea how to solve this?

0 Likes
Message 6 of 11

norman.yuan
Mentor
Mentor

There is a discussion on this topic here:

 

http://www.theswamp.org/index.php?topic=34357.0

 

This that discussion thread, "sinc" explains it well:

 

<quote>

Those are what vertical objects look like to the base Autocad managed code.  In order to cast the object to its full type, you also need to reference the managed libraries of the appropriate vertical product.  And note that not all objects are available in the managed libraries of vertical products - for example, the managed API to Civil 3D is still very incomplete.  There are a lot of things that can only be accessed via the COM interops.  That involves getting the AcadObject from your ImpDBObject and casting it as required, and requires you to reference the interops for the appropriate vertical product.

</quote>

 

In ACAD Map2006, the MPolygon class is included in Acdbmgd.dll, while since Acad Map 2007 (Acad R17 on), this class is separated from acdbmgd.dll and placed in AcMPolygonMgd.dll. Obviously, the MPolygon class is not as complete as in later version in exposing necessary interface to the outside.

 

So, your best bet would be upgrade your solution from targeting AcadMap2006 to later version. Still use Win2K? ouch! It is time to upgrade!

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 11

Anonymous
Not applicable

I am using Autocad Map 2010 on Windows Vista, Visual Studio 2008 and added the reference to the AcMPolygonMgd.dll of AutoCad Map 2010 to my project, but still the same problem occurs.

0 Likes
Message 8 of 11

norman.yuan
Mentor
Mentor

How do you get/create your MPolygon objects in AutoCAD Map? I did not use MPolygon in my work, but I draw a few MPolygon with "MPolygon" command and run the following code without issue:

 

 

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

namespace MPolygonTest
{
    public class MyCommands
    {
        [CommandMethod("MPoly")]
        public static void DoThis()
        {
            Document doc = Autodesk.AutoCAD.ApplicationServices.
                Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;

            MPolygon mpoly = PickMPolygon(doc);

            if (mpoly == null) return;

            ed.WriteMessage("\nMPolygon picked.");
        }

        private static MPolygon PickMPolygon(Document dwg)
        {
            PromptEntityOptions opt = 
                new PromptEntityOptions("\nPick an MPolygon:");
            opt.SetRejectMessage("Not an MPolygon!");
            opt.AddAllowedClass(typeof(MPolygon), true);

            PromptEntityResult res = dwg.Editor.GetEntity(opt);
            if (res.Status != PromptStatus.OK) return null;

            MPolygon pl = null;

            using (Transaction tran = 
                dwg.Database.TransactionManager.StartTransaction())
            {
                DBObject obj = tran.GetObject(res.ObjectId, OpenMode.ForRead);

                try
                {
                    pl = (MPolygon)obj;
                }
                catch
                {
                    dwg.Editor.WriteMessage(
                        "\nCasting to MPolygon failed: picked object is {0}", 
                        obj.GetType().Name);
                }

                tran.Commit();
            }

            return pl;
        }
    }
}

 

 I use Win7 (32bit) + AutoCAD Map 2009 + VS2008. In the project a reference is set to AcMPolygonMgd.dll in Acad installation folder ("Copy Local" is set to "False", of course).

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 9 of 11

O_Eckmann
Mentor
Mentor

Hi,

 

It's an old post, but i'm facing the same problem. I try to overrule Grips on mpolygon, because those defined by Autodesk are too hugly (and unusable) since 2011. I've add AcMpolygonMgd.dll (copy to false) to my project.

 

 

    public class MPolyGripOverrule : GripOverrule
    {
      public override void GetGripPoints(
        Entity entity, GripDataCollection grips,
        double curViewUnitSize, int gripSize,
        Vector3d curViewDir, GetGripPointsFlags bitFlags)
      {
        MPolygon mpoly = (MPolygon)entity;

        base.GetGripPoints(entity, grips,
          curViewUnitSize, gripSize,
          curViewDir, bitFlags);

        // Remove all grips
        grips.Clear();
      }
    }

On the GetGripPoints I try to cast my entity to MPolygon to obtain later outer and inner loop to had may own grips

But I've an error message explaining it's not possible to cast ImpEntity to MPolygon

 

If I remove the cast, I obtain an error "eNotImplementedYet" in the base.GetGripPoints(...)

 

It seems this method wasn't implemented for this vertical object. Is there an other way to manage GripPoints on such objetcs?

 

Thanks for any ideas

 

Olivier

Olivier Eckmann

EESignature

0 Likes
Message 10 of 11

O_Eckmann
Mentor
Mentor

Hi,

 

I've found some informations. In MAP 3D 2010 and 2012, entity return is ImpEntity instead of MPolygon. It seem's that information (managed) isn't exposed properly by AcMPolygonMgd.dll (version 15 for MAP 2010 and 2012, version 17 in MAP 2008).
For MAP 3D 2014, entity returned is MPolygon (like Map 2009 according to the test from Norman). version of DLL = 19
I haven't tested for other version of MAP 3D.

 

For me, base.GetGripPoints isn't necessary because I don't want the standard Grip, I want to add my own grip.
To add squared and rectangular grip I create my own class derived from GripData and override the viewportdraw. But :
- I don't know how to find the default color grip configured by user?
- I have a crash when de selecting MPolygon griped. Error seem's appear in GripStatus whith a null reference. I don't undestand why?
If somebody has any idea, thanks.

 

Olivier

Olivier Eckmann

EESignature

0 Likes
Message 11 of 11

tamara
Advocate
Advocate

I just had the same problem in AutoCADMap 3D 2020 using NET Framework 4.8 / C#. Has anybody come up with the solution in the meantime?

 

Best regards,

Tamara

0 Likes