Hi, Thanks for the reply
Thanks for the code.
I'm not sure is this C#?
I have Figured out a way around my problem.
What I did was get polyline data through user selection and then recreate that same polyline on a new drawing but setting the normal parameter of the new Polyline to (0,0,1) flat on WCS so now when I import the new DWG its flat.
Code Below:
PS this code is only working on one Polyline at the moment
public class Class1
{
[CommandMethod("DrawP", CommandFlags.UsePickSet)]
public void GetPline()
{
Editor Ced = Application.DocumentManager.MdiActiveDocument.Editor;
Database Cdb = HostApplicationServices.WorkingDatabase;
Transaction Ctr = Cdb.TransactionManager.StartTransaction();
using (Ctr)
{
// Build a filter list so that only
// polyline are selected
TypedValue[] filList = new TypedValue[1] { new TypedValue((int)DxfCode.Start, "LWPOLYLINE") };
SelectionFilter filter = new SelectionFilter(filList);
PromptSelectionOptions opts = new PromptSelectionOptions();
opts.MessageForAdding = "Select polylines: ";
PromptSelectionResult res = Ced.GetSelection(opts, filter);
// Do nothing if selection is unsuccessful
if (res.Status != PromptStatus.OK)
{
return;
}
SelectionSet selSet = res.Value;
ObjectId[] ids = selSet.GetObjectIds();
for (int i = 0; i < ids.Length; i++)
{
// Get Data from PolyLine
Polyline pl = (Polyline)Ctr.GetObject(ids[i], OpenMode.ForRead);
Database newDb = new Database(true, false);
string FileName = "C:\\temp\\wblock.dwg";
newDb.SaveAs(FileName, DwgVersion.Newest);
DrawPline(pl, FileName);
}
}
}
public static void DrawPline(Polyline polyline,string doc)
{
try
{
string dwgFlpath = doc;
using (Database db = new Database(false, true))
{
db.ReadDwgFile(dwgFlpath, FileOpenMode.OpenForReadAndAllShare, false, null);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
using (Polyline pl = new Polyline(polyline.NumberOfVertices))
{
pl.Normal = new Vector3d(0, 0, 1);
pl.Elevation = 0;
for (int j = 0; j < polyline.NumberOfVertices; j++)
{
Point2d pt = polyline.GetPoint2dAt(j);
double bul = polyline.GetBulgeAt(j);
double sWid = polyline.GetStartWidthAt(j);
double eWid = polyline.GetEndWidthAt(j);
pl.AddVertexAt(j, new Point2d(pt.X, pt.Y), bul, sWid, eWid);
}
pl.Closed = true;
btr.AppendEntity(pl);
tr.AddNewlyCreatedDBObject(pl, true);
}
tr.Commit();
}
db.SaveAs(dwgFlpath, DwgVersion.Current);
}
}
catch (System.Exception ex)
{
Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage(ex.ToString());
}
}
}