TheSwamp

Code Red => .NET => Topic started by: It's Alive! on December 04, 2007, 01:30:49 PM

Title: More managed Wrappers
Post by: It's Alive! 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);
      }
    }
Title: Re: More managed Wrappers
Post by: It's Alive! 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
    }
  }
}
Title: Re: More managed Wrappers
Post by: Kerry on December 05, 2007, 09:30:38 PM
Dan,
in case I forget later,
thanks for sharing your discoveries.

be well,
Kerry
Title: Re: More managed Wrappers
Post by: It's Alive! on December 29, 2007, 10:47:02 PM
I added This (http://www.theswamp.org/index.php?topic=20700.msg251454#msg251454) 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);
Title: Re: More managed Wrappers
Post by: It's Alive! 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);
      }
    }
Title: Re: More managed Wrappers
Post by: gswang on May 26, 2017, 10:18:46 AM
I can't compile AcMgdWrprs project successfully for AutoCAD 2010、AutoCAD 2016。Please help. :-D
Title: Re: More managed Wrappers
Post by: It's Alive! on May 27, 2017, 10:52:08 PM
srsly? ...that stuff is 10 years old!
Title: Re: More managed Wrappers
Post by: gswang on May 28, 2017, 05:57:18 AM
My problem has been solved, thank you!