Author Topic: Area of Mpolygon  (Read 9147 times)

0 Members and 1 Guest are viewing this topic.

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Area of Mpolygon
« on: June 12, 2009, 08:09:20 AM »

How would you get in Lisp the area of a Mpolygon?
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Area of Mpolygon
« Reply #1 on: June 12, 2009, 08:11:39 AM »
Marea??



What da funk is an Mpolygon??!?
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Area of Mpolygon
« Reply #2 on: June 12, 2009, 08:17:51 AM »
Quote
Marea??

No such command here.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023


VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Area of Mpolygon
« Reply #4 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))))

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: Area of Mpolygon
« Reply #5 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!
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

VovKa

  • Water Moccasin
  • Posts: 1626
  • Ukraine
Re: Area of Mpolygon
« Reply #6 on: June 12, 2009, 10:49:40 AM »
don't worry, Matt, it's Autodesk Map custom object :)

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Area of Mpolygon
« Reply #7 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)
)

« Last Edit: June 12, 2009, 03:03:21 PM by gile »
Speaking English as a French Frog

V-Man

  • Bull Frog
  • Posts: 343
  • I exist therefore I am! Finally Retired!
Re: Area of Mpolygon
« Reply #8 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.
AutoCAD 9 - 2023, AutoCADMap 2008 - 2010, Revit 2012 - 2022, Autocad Civil 3D 2023

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Area of Mpolygon
« Reply #9 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);
            }
        }
    }
}
« Last Edit: June 13, 2009, 10:26:39 AM by gile »
Speaking English as a French Frog

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Area of Mpolygon
« Reply #10 on: June 17, 2009, 11:43:33 AM »
A new release of PL2MPG, source code here.

EDIT: Updated attached file. Now contains VanillaMPolygon_17.dll for AutoCAD 2007 to 2012 and VanillaMPolygon_19.dll for AutoCAD 2013 and later.
« Last Edit: January 27, 2015, 03:14:23 PM by gile »
Speaking English as a French Frog

vertamboz

  • Guest
Re: Area of Mpolygon
« Reply #11 on: January 27, 2015, 05:59:47 AM »
A new release of PL2MPG, source code here.

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

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Area of Mpolygon
« Reply #12 on: January 27, 2015, 03:13:54 PM »
A new release of PL2MPG, source code here.

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.
Speaking English as a French Frog

vertamboz

  • Guest
Re: Area of Mpolygon
« Reply #13 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. :)

xdcad

  • Bull Frog
  • Posts: 426
Re: Area of Mpolygon
« Reply #14 on: November 22, 2023, 01:02:52 PM »
(xdrx-getpropertyvalue mp "area" "length")

查面积,长度
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net