Author Topic: More managed Wrappers  (Read 3425 times)

0 Members and 1 Guest are viewing this topic.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
More managed Wrappers
« on: December 04, 2007, 01:30:49 PM »
A couple of more wrappers EntGet, EntMake, EntNext ... for practice. 
I will do emtmod next. Use at your own risk  ..reference the attached dll.. for 2007

C# sample

Code: [Select]
[CommandMethod("test1")]
    static public void test1()
    {
      Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        //EntMake
        ResultBuffer rb = new ResultBuffer();
        rb.Add(new TypedValue(0, "LINE"));
        rb.Add(new TypedValue(67, 0));
        rb.Add(new TypedValue(410, "Model"));
        rb.Add(new TypedValue(8, "0"));
        rb.Add(new TypedValue(10, new Point3d(185.539, 219.18, 0.0)));
        rb.Add(new TypedValue(11, new Point3d(327.492, 194.906, 0.0)));
        bool tst = AcMgdWrprs.Utilities.EntMake(rb);

        ObjectId id = AcMgdWrprs.Utilities.EntLast();

        ResultBuffer entrb = AcMgdWrprs.Utilities.EntGet(id);

        foreach (TypedValue e in entrb)
          ed.WriteMessage(e.ToString());
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage(ex.Message);
      }
    }
« Last Edit: December 30, 2007, 03:24:41 AM by Daniel »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: More managed Wrappers
« Reply #1 on: December 05, 2007, 12:59:03 PM »
And a few more dangerous wrappers .. new dll attached  :mrgreen:

Code: [Select]
static bool EntDel(ObjectId objectid);
static bool EntMake(ResultBuffer ^rb);
static bool EntMod(ResultBuffer ^rb);
static ObjectId EntLast();
static ObjectId EntNext(ObjectId objectid);
static bool EntUpd(ObjectId objectid);
static ResultBuffer^ EntGet(ObjectId objectid);
static double Distance(Point2d pt1, Point2d pt2);
static double Distance(Point3d pt1, Point3d pt2);
static String^ GetEnv(String ^sym);
static bool SetEnv(String ^sym , String ^var);

tests

Code: [Select]
namespace AcMgdWrprsTest
{
  public class Commands
  {
    public Commands()
    {
    }
    [CommandMethod("test1")]
    static public void test1()
    {
      Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        //EntMake
        ResultBuffer rb = new ResultBuffer();
        rb.Add(new TypedValue(0, "LINE"));
        rb.Add(new TypedValue(67, 0));
        rb.Add(new TypedValue(410, "Model"));
        rb.Add(new TypedValue(8, "0"));
        rb.Add(new TypedValue(10, new Point3d(185.539, 219.18, 0.0)));
        rb.Add(new TypedValue(11, new Point3d(327.492, 194.906, 0.0)));
        bool tst = AcMgdWrprs.Utilities.EntMake(rb);
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage(ex.Message);
      }
    }

    [CommandMethod("test2")]
    static public void test2()
    {
      Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        //get the id from test1
        ObjectId id = AcMgdWrprs.Utilities.EntLast();

        //get the entlist
        ResultBuffer entrb = AcMgdWrprs.Utilities.EntGet(id);

        //to list
        List<TypedValue> list = new List<TypedValue>(entrb.AsArray());

        //locate the endpoint in the list
        int location = findcodeLocation(list, 11);

        //remove the the endpoint
        list.RemoveAt(location);

        //insert a new endpoint
        list.Insert(location, new TypedValue(11, new Point3d(194.906, 327.492, 0.0)));

        //entmod
        AcMgdWrprs.Utilities.EntMod(new ResultBuffer(list.ToArray()));

        //ubdate
        AcMgdWrprs.Utilities.EntUpd(id);
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage(ex.Message);
      }
    }

    internal static int findcodeLocation(List<TypedValue> list, short code)
    {
      for (int i = 0; i < list.Count; i++)
      {
        if (list[i].TypeCode.Equals(code))
          return i;
      }
      return -5001;//RTERROR
    }
  }
}
« Last Edit: December 29, 2007, 11:19:59 PM by Daniel »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: More managed Wrappers
« Reply #2 on: December 05, 2007, 09:30:38 PM »
Dan,
in case I forget later,
thanks for sharing your discoveries.

be well,
Kerry
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: More managed Wrappers
« Reply #3 on: December 29, 2007, 10:47:02 PM »
I added This to my AcMgdWrprs probject

sample:
Code: [Select]
   [CommandMethod("doit")]
    static public void toit()
    {
      Editor ed = acadApp.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        ObjectIdCollection objectIds = new ObjectIdCollection();
        Database db = acadApp.DocumentManager.MdiActiveDocument.Database;
        using (Transaction tr = db.TransactionManager.StartTransaction())
        {
          LayerTable table = (LayerTable)tr.GetObject(db.LayerTableId, OpenMode.ForRead);
          foreach (ObjectId id in table)
          {
            objectIds.Add(id);
          }
        }
        AcMgdWrprs.Utilities.RegenLayers(objectIds);//<<-----------
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage(ex.Message);
      }
    }

function list

Code: [Select]
    static void RegenLayers(ObjectIdCollection ^objectIds);
    static bool EntDel(ObjectId objectid);
    static bool EntMake(ResultBuffer ^rb);
    static ObjectId EntMakeX(ResultBuffer ^rb);
    static bool EntMod(ResultBuffer ^rb);
    static ObjectId EntLast();
    static ObjectId EntNext(ObjectId objectid);
    static bool EntUpd(ObjectId objectid);
    static ResultBuffer^ EntGet(ObjectId objectid);
    static double Distance(Point2d pt1, Point2d pt2);
    static double Distance(Point3d pt1, Point3d pt2);
    static String^ GetEnv(String ^sym);
    static bool SetEnv(String ^sym , String ^var);
« Last Edit: June 14, 2008, 12:12:24 AM by Daniel »

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: More managed Wrappers
« Reply #4 on: June 14, 2008, 12:11:54 AM »
added:

Code: [Select]
static array<String^>^ GetLoadedLisps(void);

example:
Code: [Select]
   [CommandMethod("doit")]
    public static void doit()
    {
      Editor ed = AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
      try
      {
        foreach (string S in AcMgdWrprs.Utilities.GetLoadedLisps())
        {
          ed.WriteMessage("\n" + S);
        }
      }
      catch (System.Exception ex)
      {
        ed.WriteMessage("\n" + ex.Message);
        ed.WriteMessage("\n" + ex.StackTrace);
      }
    }

gswang

  • Newt
  • Posts: 117
Re: More managed Wrappers
« Reply #5 on: May 26, 2017, 10:18:46 AM »
I can't compile AcMgdWrprs project successfully for AutoCAD 2010、AutoCAD 2016。Please help. :-D

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8662
  • AKA Daniel
Re: More managed Wrappers
« Reply #6 on: May 27, 2017, 10:52:08 PM »
srsly? ...that stuff is 10 years old!

gswang

  • Newt
  • Posts: 117
Re: More managed Wrappers
« Reply #7 on: May 28, 2017, 05:57:18 AM »
My problem has been solved, thank you!