TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: V-Man on June 12, 2009, 08:09:20 AM

Title: Area of Mpolygon
Post by: V-Man on June 12, 2009, 08:09:20 AM

How would you get in Lisp the area of a Mpolygon?
Title: Re: Area of Mpolygon
Post by: Matt__W on June 12, 2009, 08:11:39 AM
Marea??



What da funk is an Mpolygon??!?
Title: Re: Area of Mpolygon
Post by: V-Man on June 12, 2009, 08:17:51 AM
Quote
Marea??

No such command here.
Title: Re: Area of Mpolygon
Post by: m4rdy on June 12, 2009, 08:46:48 AM
http://www.theswamp.org/index.php?topic=8595.0 (http://www.theswamp.org/index.php?topic=8595.0)
http://www.theswamp.org/index.php?topic=8710.0 (http://www.theswamp.org/index.php?topic=8710.0)
http://www.theswamp.org/index.php?topic=20345.0 (http://www.theswamp.org/index.php?topic=20345.0)
Title: Re: Area of Mpolygon
Post by: VovKa on June 12, 2009, 10:24:20 AM
Matt W, this is it
Code: [Select]
'((-1 . <Entity name: 7ef79028>)
  (0 . "MPOLYGON")
  (330 . <Entity name: 7ef5fcf8>)
  (5 . "D5")
  (100 . "AcDbEntity")
  (67 . 0)
  (410 . "Model")
  (8 . "0")
  (100 . "AcDbMPolygon")
  (70 . 1)
  (10 0.0 0.0 0.0)
  (210 0.0 0.0 1.0)
  (2 . "_SOLID")
  (71 . 1)
  (91 . 1)
  (92 . 2)
  (73 . 0)
  (72 . 0)
  (93 . 4)
  (10 -40.6427 -2.83449 0.0)
  (10 0.945178 -37.9821 0.0)
  (10 40.6427 0.944829 0.0)
  (10 2.45746 37.9821 0.0)
  (76 . 1)
  (63 . 256)
  (11 141.553 98.8253 0.0)
  (99 . 0)
  (450 . 0)
  (451 . 0)
  (460 . 0.0)
  (461 . 0.0)
  (452 . 0)
  (462 . 0.0)
  (453 . 0)
  (470 . "")
 )
it's a hatched closed polyline... sort of

dvarino,
the area can be grabbed like any other area
(vla-get-Area (vlax-ename->vla-object (car (entsel))))
Title: Re: Area of Mpolygon
Post by: Matt__W on June 12, 2009, 10:27:53 AM
Matt W, this is it

it's a hatched closed polyline... sort of
In all my years.... never heard of that before.  Huh!
Title: Re: Area of Mpolygon
Post by: VovKa on June 12, 2009, 10:49:40 AM
don't worry, Matt, it's Autodesk Map custom object :)
Title: Re: Area of Mpolygon
Post by: gile on June 12, 2009, 10:59:54 AM
Hi,

MPolygons  can be imported in Vanilla from MAP if AcMPolygonObj17.dbx is loaded.

They can be created too in Vanilla with .NET or LISP using entmake.
MPolygon DXF data are similar to Hatchs ones.

Code: [Select]
(defun c:makeMPolygon (/ filename)
  (setq filename (strcat "acmpolygonobj" (substr (getvar "ACADVER") 1 2) ".dbx"))
  (or (member filename (arx))
      (arxload filename)
  )
  (entmake '((0 . "MPOLYGON")
     (100 . "AcDbEntity")
     (100 . "AcDbMPolygon")
     (70 . 1)
     (10 0.0 0.0 0.0)
     (210 0.0 0.0 1.0)
     (2 . "ANSI31")
     (71 . 0)
     (91 . 2)
     (92 . 2)
     (73 . 0)
     (72 . 0)
     (93 . 5)
     (10 62.6859 18.6225 0.0)
     (10 120.0 60.2636 0.0)
     (10 177.314 18.6225 0.0)
     (10 155.422 -48.7543 0.0)
     (10 84.5779 -48.7543 0.0)
     (92 . 2)
     (73 . 0)
     (72 . 0)
     (93 . 4)
     (10 20.0 100.0 0.0)
     (10 20.0 -100.0 0.0)
     (10 220.0 -100.0 0.0)
     (10 220.0 100.0 0.0)
     (76 . 1)
     (52 . 0.0)
     (41 . 2.0)
     (77 . 0)
     (78 . 1)
     (53 . 0.785398)
     (43 . 0.0)
     (44 . 0.0)
     (45 . -4.49013)
     (46 . 4.49013)
     (79 . 0)
     (11 0.0 0.0 0.0)
     (99 . 0)
     (450 . 0)
     (451 . 0)
     (460 . 0.0)
     (461 . 0.0)
     (452 . 0)
     (462 . 0.0)
     (453 . 0)
     (470 . "")
    )
  )
  (princ)
)

Title: Re: Area of Mpolygon
Post by: V-Man on June 12, 2009, 11:40:20 AM

Quote
dvarino,
the area can be grabbed like any other area
(vla-get-Area (vlax-ename->vla-object (car (entsel))))

Thanks for the information.


Quote
In all my years.... never heard of that before.  Huh!

Yea , me too. Very strange indeed.
Title: Re: Area of Mpolygon
Post by: gile on June 13, 2009, 10:14:28 AM
Hi,

Here's a .NET command which allows to create a MPOLYGON in Vanilla from a selection set .

NETLOAD AcadMoplygon.dll, type PL2MPG, select entities (closed lwpolylines or 2d polylines and circles), enter the hatch pattern name (or a dot for none).

Code: [Select]
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;

namespace AcadMPolygon
{
    public class MpgClass : IExtensionApplication
    {
        public void Initialize()
        {
            Autodesk.AutoCAD.Runtime.SystemObjects.DynamicLinker.LoadModule("AcMPolygonObj17.dbx", false, false);
        }

        public void Terminate()
        {
        }

        [CommandMethod("PL2MPG")]
        public void PL2MPG()
        {
            Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
            try
            {
                Database db = HostApplicationServices.WorkingDatabase;
                TypedValue[] filter = { new TypedValue(-4, "<or"),
                                           new TypedValue(0, "CIRCLE"),
                                           new TypedValue(-4, "<and"),
                                           new TypedValue(0, "LWPOLYLINE"),
                                           new TypedValue(-4, "&"),
                                           new TypedValue(70, 1),
                                           new TypedValue(-4, "and>"),
                                           new TypedValue(-4, "<and"),
                                           new TypedValue(0, "POLYLINE"),
                                           new TypedValue(-4, "&"),
                                           new TypedValue(70, 1),
                                           new TypedValue(-4, "<not"),
                                           new TypedValue(-4, "&"),
                                           new TypedValue(70, 120),
                                           new TypedValue(-4, "not>"),
                                           new TypedValue(-4, "and>"),
                                           new TypedValue(-4, "or>"),
                                       };
                SelectionFilter selFilter = new SelectionFilter(filter);
                PromptSelectionResult result = ed.GetSelection(selFilter);
                if (result.Status == PromptStatus.OK)
                {
                    ObjectId[] selSet = result.Value.GetObjectIds();
                    using (Transaction tr = db.TransactionManager.StartTransaction())
                    {
                        BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);
                        BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
                        MPolygon mPolygon = new MPolygon();
                        foreach (ObjectId objId in selSet)
                        {
                            Entity ent = (Entity)tr.GetObject(objId, OpenMode.ForWrite);
                            if (ent is Polyline)
                                mPolygon.AppendLoopFromBoundary((Polyline)ent, true, 1E-9);
                            else if (ent is Circle)
                                mPolygon.AppendLoopFromBoundary((Circle)ent, true, 1E-9);
                            else
                                mPolygon.AppendLoopFromBoundary((Polyline2d)ent, true, 1E-9);
                            ent.Erase();
                        }

                        PromptStringOptions pso = new PromptStringOptions("\nEnter the hatch pattern name or a dot (.) for none: ");
                        pso.AllowSpaces = false;
                        pso.DefaultValue = (string)Application.GetSystemVariable("HPNAME");
                        PromptResult pr = ed.GetString(pso);
                        if (pr.Status == PromptStatus.OK)
                        {
                            string pat = pr.StringResult;
                            if (pat != ".")
                            {
                                try
                                {
                                    Application.SetSystemVariable("HPNAME", pat);
                                    mPolygon.SetPattern(HatchPatternType.PreDefined, pat);
                                    mPolygon.PatternScale = (double)Application.GetSystemVariable("HPSCALE");
                                }
                                catch { }
                            }
                        }

                        mPolygon.BalanceTree();
                        mPolygon.BalanceDisplay();

                        btr.AppendEntity(mPolygon);
                        tr.AddNewlyCreatedDBObject(mPolygon, true);
                        tr.Commit();
                    }
                }
            }

            catch(Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("Error: " + ex.Message);
            }

            catch (System.Exception ex)
            {
                ed.WriteMessage("Error: " + ex.Message);
            }
        }
    }
}
Title: Re: Area of Mpolygon
Post by: gile on June 17, 2009, 11:43:33 AM
A new release of PL2MPG, source code here (http://www.theswamp.org/index.php?topic=29152.msg347035#msg347035).

EDIT: Updated attached file. Now contains VanillaMPolygon_17.dll for AutoCAD 2007 to 2012 and VanillaMPolygon_19.dll for AutoCAD 2013 and later.
Title: Re: Area of Mpolygon
Post by: vertamboz on January 27, 2015, 05:59:47 AM
A new release of PL2MPG, source code here (http://www.theswamp.org/index.php?topic=29152.msg347035#msg347035).

It is possible to use this in autocad 2013 vanilla? I tried it, but it did't work. (My skills in .net are 0)
Title: Re: Area of Mpolygon
Post by: gile on January 27, 2015, 03:13:54 PM
A new release of PL2MPG, source code here (http://www.theswamp.org/index.php?topic=29152.msg347035#msg347035).

It is possible to use this in autocad 2013 vanilla? I tried it, but it did't work. (My skills in .net are 0)

I updated the upper dowload: netload VanillaMPolygon_19.dll for AutoCAD 2013 or later.
Title: Re: Area of Mpolygon
Post by: vertamboz on January 27, 2015, 04:06:48 PM
I updated the upper dowload: netload VanillaMPolygon_19.dll for AutoCAD 2013 or later.

Thank you very much, you've been really helpful to me! And sorry for my bad english. :)
Title: Re: Area of Mpolygon
Post by: xdcad on November 22, 2023, 01:02:52 PM
(xdrx-getpropertyvalue mp "area" "length")

查面积,长度