TheSwamp
Code Red => .NET => Topic started 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
[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);
}
}
-
And a few more dangerous wrappers .. new dll attached :mrgreen:
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
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
}
}
}
-
Dan,
in case I forget later,
thanks for sharing your discoveries.
be well,
Kerry
-
I added This (http://www.theswamp.org/index.php?topic=20700.msg251454#msg251454) to my AcMgdWrprs probject
sample:
[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
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);
-
added:
static array<String^>^ GetLoadedLisps(void);
example:
[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);
}
}
-
I can't compile AcMgdWrprs project successfully for AutoCAD 2010、AutoCAD 2016。Please help. :-D
-
srsly? ...that stuff is 10 years old!
-
My problem has been solved, thank you!