AutoCAD Map 3D Developer
Welcome to Autodesk’s AutoCAD Map 3D Developer Forums. Share your knowledge, ask questions, and explore popular AutoCAD Map 3D Developer topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

AppendMPolygonLoop: Error: eAmbiguousInput

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
tamara
920 Views, 3 Replies

AppendMPolygonLoop: Error: eAmbiguousInput

Hello, 

I am reading feature geomety from sdf file and converting it to ACAD geometry. 

I am having trouble to append polygon loop on a MPolygon object in many cases (function AppendMPolygonLoop()) , and i keep getting the eAmbiguousInput error, but I found nothnig on this on the net. This is my sample code:

 

 public static MPolygon ConvertFeatureToMPolygon(OSGeo.FDO.Geometry.IGeometry geometry, Style style, ref bool error)
        {
            MPolygon mPolygon = null;
            Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
            Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;

            try
            {
                mPolygon = new MPolygon();
                MPolygonLoopCollection mPolygonLoopColl = new MPolygonLoopCollection();
                MPolygonLoop mpolygonExteriorLoop = new MPolygonLoop();
                var polygonGeometry = geometry as OSGeo.FDO.Geometry.IPolygon;
                var exteriorRing = polygonGeometry.ExteriorRing;
                for (int i = 0; i < exteriorRing.Count; i++)
                {
                    var position = exteriorRing[i];
                    mpolygonExteriorLoop.Add(new BulgeVertex(new Point2d(position.X, position.Y), 0));
                }
                mPolygonLoopColl.Add(mpolygonExteriorLoop);

                int numOfInnerLoops = polygonGeometry.InteriorRingCount;
                for (int i = 0; i < numOfInnerLoops; i++)
                {
                    MPolygonLoop mPolygonInnerLoop = new MPolygonLoop();
                    var innerRing = polygonGeometry.GetInteriorRing(i);
                    for (int j = 0; j < innerRing.Count; j++)
                    {
                        var position = innerRing[j];
                        mPolygonInnerLoop.Add(new BulgeVertex(new Point2d(position.X, position.Y), 0));
                    }
                    mPolygonLoopColl.Add(mPolygonInnerLoop);
                }
                foreach (MPolygonLoop loop in mPolygonLoopColl)
                {
                    mPolygon.AppendMPolygonLoop(loop, true, 0.02);
                }

                try
                {
                    mPolygon.Layer = style.Layer.Name;
                }
                catch
                {
                    ACGHelperMethods.CreateLayer(style.Layer);
                    mPolygon.Layer = style.Layer.Name;
                }

                Pattern pattern = style.Pattern;
                if (pattern != null)
                {
                    mPolygon.SetPattern(HatchPatternType.PreDefined, pattern.Name);
                    if (pattern.Color.Index != 0)
                    {
                        mPolygon.PatternColor = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, pattern.Color.Index);

                    }
                    else
                    {
                        mPolygon.PatternColor = Autodesk.AutoCAD.Colors.Color.FromRgb((byte)pattern.Color.Red, (byte)pattern.Color.Green, (byte)pattern.Color.Blue);
                    }

                    if (pattern.Angle != 0)
                    {
                        mPolygon.PatternAngle = pattern.Angle;
                    }
                    if (pattern.Scale != 0)
                    {
                        mPolygon.PatternScale = pattern.Scale;
                    }
                    if (pattern.Space != 0)
                    {
                        mPolygon.PatternSpace = pattern.Space;
                    }
                }

                mPolygon.BalanceTree();
            }
            catch
            {
                mPolygon = null;
                error = true;
                return mPolygon;
            }
            return mPolygon;
        }
3 REPLIES 3
Message 2 of 4
fieldguy
in reply to: tamara

Are you able to create this mpolygon in Map using acad tools (command "mpolygon")?  If yes, create 1, explode it, and check if acad changed the direction on 1 of the polylines.

I would try adding the interior loop in the opposite direction.  IIRC the definition of polygons with islands is controlled by direction.  Exterior is clockwise, interior is counter-clockwise (kind of guessing here - it's been awhile). 

Message 3 of 4
tamara
in reply to: tamara

Actually, I just needed to set 

mPolygon.AppendMPolygonLoop(loop, true, 0.00);

to 

mPolygon.AppendMPolygonLoop(loop, false, 0.00);

so that crossing loops don't get excluded. Turns out that I had many features in the database with crossing loops, so that was the problem I overlooked.

 

Message 4 of 4
fieldguy
in reply to: tamara

I'm glad you were able to solve it.  I saw your post in the Map 3D forum.  IMO you will never get a response from Autodesk on Map 3D procedures.  You will have better luck in the OSGEO forums.  I believe the future of Map is there - not here.   

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report