Preview:
public void Seleccionar()
        {

            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Database db = doc.Database;

            Editor ed = doc.Editor;

            PromptEntityOptions peo = new PromptEntityOptions("\nSeleccione una superficie:");

            //peo.SetRejectMessage("\nDebe ser un entidad de tipo ¡Polyline!");

            //peo.AddAllowedClass(typeof(Autodesk.AutoCAD.DatabaseServices.Polyline), false);

            PromptEntityResult per = ed.GetEntity(peo);


            if (per.Status != PromptStatus.OK)

                return;

            Transaction tr = db.TransactionManager.StartTransaction();

            Autodesk.AutoCAD.DatabaseServices.Polyline pl = new Autodesk.AutoCAD.DatabaseServices.Polyline();

            IntegerCollection ic = new IntegerCollection();

            using (tr)
            {

                DBObject obj = tr.GetObject(per.ObjectId, OpenMode.ForRead);

                ed.WriteMessage("Type : " + obj.GetType().Name);
                                
                if (obj is Autodesk.AutoCAD.DatabaseServices.Polyline)
                {
                    ed.WriteMessage(obj.GetType().Name + "Selected.");

                    Autodesk.AutoCAD.DatabaseServices.Polyline pline = tr.GetObject(per.ObjectId, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Polyline;

                    if (pline != null)
                    {
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(pline.OwnerId, OpenMode.ForWrite);

                        Point3d picked = pline.GetClosestPointTo((Point3d)per.PickedPoint, false);

                        double par = pline.GetParameterAtPoint(picked);

                        int m = (int)par;

                        Point2dCollection verts = new Point2dCollection(2);

                        SegmentType stype = pline.GetSegmentType(m);

                        if (stype == SegmentType.Line)
                        {
                            Point3d pl1 = pline.GetPoint3dAt(0);
                            Point3d pl2 = pline.GetPoint3dAt(1);

                            int vn = pline.NumberOfVertices;

                            double maxDistance = 0;
                            double minDistance = 0;

                            Point3d puntoL2 = pline.GetPoint3dAt(1);

                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("VN: " + vn);

                            for (int i = 0; i < vn; i++)

                            {
                                Point3d pt1 = pline.GetPoint3dAt(i);
                                
                                ed.WriteMessage("\n" + pt1.ToString());
                                if (i < (vn - 1))
                                {
                                    Point3d pt2 = pline.GetPoint3dAt(i + 1);
                                    ed.WriteMessage("\n" + pt2.ToString());
                                    var preDistance = pt1.DistanceTo(pt2);
                                    
                                    if (preDistance > maxDistance)
                                    {
                                        maxDistance = preDistance;
                                    }
                                    if(preDistance > 0 && preDistance < maxDistance)
                                    {
                                        minDistance = preDistance;
                                    }
                                    if (preDistance == maxDistance)
                                    {
                                        puntoL2 = pline.GetPoint3dAt(i + 1);
                                    }
                                }
                                if(i == (vn-1))
                                {
                                    puntoL2 = pline.GetPoint3dAt(0);
                                }

                            }
                            

                            Point3d puntico;

                            if (pl1.Y > pl2.Y)
                            {
                                puntico = pl1;
                            }
                            else
                            {
                                puntico = pl2;
                            }

                            var distance = maxDistance;

                            PromptIntegerOptions prn = new PromptIntegerOptions("\nDetermine el alto del muro:");
                            PromptIntegerResult startingNumberPromptResult = ed.GetInteger(prn);

                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Ancho: " + distance + " Alto:" + startingNumberPromptResult.Value);

                            Point3d puntoL1 = new Point3d(pl1.X, pl1.Y - 0.6, pl1.Z);
                            Point3d puntoLL = new Point3d(puntoL2.X, puntoL2.Y - 0.6, puntoL2.Z);

                            tr.Commit();

                            string punto1 = "punto 1." + puntoL1.X + "-" + puntoL1.Y + "-" + puntoL1.Z;
                            string punto2 = " - punto 2." + puntoL2.X + "-" + puntoL2.Y + "-" + puntoL2.Z;

                            Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(punto1 + punto2);
                            
                            InsertBlocketivo(puntoL1, "panel60x120", distance, startingNumberPromptResult.Value,minDistance, puntoL2);

                        }

                        
                    }                    

                }          

            }

        }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter