Hi Mike:
I am working on a function to draw a box in LWPolyline in C#. Now everything looks OK but the rectangle does not show up in the drawing. Please see code below:
public static Entity DrawBox(Point2d pt, double Width, double Height, BlockTableRecord btr)
{
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
Polyline plBox;
try
{
plBox = new Polyline(4);
plBox.AddVertexAt (0, pt, 0,0,0);
plBox.AddVertexAt (1, new Point2d(pt.X+Width, pt.Y),0,0,0);
plBox.AddVertexAt (2, new Point2d(pt.X+Width,pt.Y+Height),0,0,0);
plBox.AddVertexAt (3, new Point2d(pt.X,pt.Y+Height),0,0,0);
plBox.Closed = true;
btr.AppendEntity(plBox);
trans.AddNewlyCreatedDBObject(plBox,true);
trans.Commit();
}
finally
{
trans.Dispose();
}
return plBox;
}
//// Here is the code to test it
[CommandMethod("DrawBox_TEST")]
public static void DrawBox_Test()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
Transaction trans = db.TransactionManager.StartTransaction();
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId,OpenMode.ForWrite);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace],OpenMode.ForWrite);
PromptPointOptions prPtOpts = new PromptPointOptions("Please pick a point:");
PromptPointResult prPtRes = ed.GetPoint(prPtOpts);
if (prPtRes.Status != PromptStatus.OK )
return;
Point3d pt1 = prPtRes.Value;
Point2d pt = new Point2d(pt1.X, pt1.Y);
Entity ent = AutoCADLib.DrawBox(pt,100,50,btr);
if (ent != null)
ed.WriteMessage("{0}",ent.GetType().Name);
else
ed.WriteMessage("No Box Drawed.");
}
do you what's wrong is there? Thank you.
Also, I found in AutoCAD .Net help,
"AcDbPolyline is often called a lightweight polyline because of its efficient use of memory. AcDbPolyline provides greater performance and reduced overhead compared to AcDb2dPolyline"
I kind of confused:
the LWPolyline in AutoCAD is AcDbPolyline
old style Polyline is AcDB2dPolyline. Which is correct?
Wes
Windows 10 64 bit, AutoCAD (ACA, Map) 2023