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: 

MAPCREATEFEATUREFROMGEOMETRY

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
svucic
280 Views, 2 Replies

MAPCREATEFEATUREFROMGEOMETRY

Hi everyone.

 

Could someone please help me. 

 

I need to make a new feature from a polyline using C#.NET.

 

I'm used to autolisp programing and new to .NET.

 

So far I managed to get a ss set of polylines that I need and get the area and parcel number (mtext) inside the polyline. 

 

Now I need to make a new feature from the polyline geometry in the OBData Table (.sdf) and fill the table with the values "area" and "parcel number".

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

[assembly: CommandClass(typeof(AC1.Class1))]

namespace AC1
{
    public class Class1
    {
        [CommandMethod("PP")]

        public static void FilterSelectionSet()
        {
            // Open the doc and get the current document editor
            Document acDoc = Application.DocumentManager.MdiActiveDocument;
            Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
            Database acCurDb = acDoc.Database;

            /////////////////////// SSET 1 /////////////////////////////////
            // Create a TypedValue array to define the filter criteria
            TypedValue[] acTypValAr = new TypedValue[2];
            acTypValAr.SetValue(new TypedValue((int)DxfCode.LayerName, "0"), 0);
            acTypValAr.SetValue(new TypedValue((int)DxfCode.Start, "LWPOLYLINE"), 1);

            // Assign the filter criteria to a SelectionFilter object
            SelectionFilter acSelFtr = new SelectionFilter(acTypValAr);
            PromptSelectionResult psr = acDocEd.SelectAll(acSelFtr);
            SelectionSet acSet = psr.Value;
            //acDocEd.WriteMessage("Number of selected entities is {0}.", acSet.Count.ToString());
            //______________________________________________________________________


            //Start transaction and read ObjectId 
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
            {
                // Open the Block table for read
                BlockTable acBlkTbl;
                acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
                OpenMode.ForRead) as BlockTable;

                // Open the Block table record Model space for read
                BlockTableRecord acBlkTblRec;
                acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
                OpenMode.ForRead) as BlockTableRecord;


                ObjectId[] idcoll = acSet.GetObjectIds();
               
                foreach (ObjectId mt in idcoll)
                {
                    DBObject obj = acTrans.GetObject(mt,OpenMode.ForRead);
                    Polyline lwp = obj as Polyline;

                    double area = lwp.Area;
                    acDoc.Editor.WriteMessage("\nArea :" + area.ToString());

                    Point3dCollection pt3d = new Point3dCollection();
                    for (int nCnt = 0; nCnt < lwp.NumberOfVertices; nCnt++)
                    {
                        pt3d.Add(lwp.GetPoint3dAt(nCnt));
                    }

                    ////////////////////// SSET 2 //////////////////////////////////
                    // Create a TypedValue array to define the filter criteria
                    TypedValue[] acTypValAr1 = new TypedValue[1];
                    acTypValAr1.SetValue(new TypedValue((int)DxfCode.Start, "MText"), 0);

                    // Assign the filter criteria to a SelectionFilter object
                    SelectionFilter acSelFtr1 = new SelectionFilter(acTypValAr1);
                    PromptSelectionResult psr1 = acDocEd.SelectWindowPolygon(pt3d, acSelFtr1);
                    SelectionSet acSet1 = psr1.Value;
                    //______________________________________________________________________


                    ObjectId[] idmtxt = acSet1.GetObjectIds();
                    int mtcoll = idmtxt.Length;

                    foreach (ObjectId mtid in idmtxt)
                    {
                        DBObject obj1 = acTrans.GetObject(mtid, OpenMode.ForRead);
                        MText mtxt1 = obj1 as MText;
                        string mtext1 = mtxt1.Text;
                        acDoc.Editor.WriteMessage("\nMText:" + mtext1);
                    }

                    if (lwp != null)
                    {
                        // Use a for loop to get each vertex, one by one
                        int vn = lwp.NumberOfVertices;
                        acDoc.Editor.WriteMessage("\nNumber of vertices:" + vn.ToString());
                        for (int i = 0; i < vn; i++)
                        {
                            // Could also get the 3D point here
                            Point2d pt = lwp.GetPoint2dAt(i);
                            List<Point2d> pts = new List<Point2d> { };
                            pts.Add(pt);

                            double ptX = pt.X;
                            double ptY = pt.Y;

                            //List<double> ptss = new List<double> {};
                            //ptss.Add(pt.); 
                            //ptss.Add(pt.ToArray);


                           // acDoc.Editor.WriteMessage("\nVertex :" + string.Format("{0}", i) + pt.ToString());
                           // acDoc.Editor.WriteMessage("\nVertex X :" + ptX.ToString());
                           // acDoc.Editor.WriteMessage("\nVertex Y :" + ptY.ToString());
                        }

                    }

                }
            }
        }
    }
}
2 REPLIES 2
Message 2 of 3
hence_the_name
in reply to: svucic

Hi,

 

if you are new to .net then you are also new to Map FDO API as it is not available for Lisp.

You will find tutorials for Map FDO .net API - here is one link:

 

 

http://adndevblog.typepad.com/infrastructure/2013/02/autocad-map-3d-api-training-content-part-1.html

 

Map SDK used to come with Developer samples - one sample covers your question - have a look:

 

...\Map ObjectARX SDK 2013\Map Samples\Platform\Bridge\Bridge.csproj

 

This sample demonstrates:
-   How to convert AcDbEntity to MgGeometry, and add to layer as a feature.
-   How to convert MgGeometry to AcDbEntity, and delete the feautre from layer

 

 

Good luck, Rob

 

http://raumpatrouille3d.blogspot.ch/
Message 3 of 3
svucic
in reply to: hence_the_name

Thank you very much for your kind response. I will check the sample and tutorials.

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

Post to forums  

Autodesk Design & Make Report

”Boost