- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
Greatly appreciate any help. I'm creating a winforms app with a button that lets the user create a boundary from some closed areas in the drawing (via TraceBoundary), and calculates the area of the boundary.
Before calculating the area, I want to add the boundary object (a pline) to the model space via the Using Transaction...AppendEntity...AddNewlyCreatedDBObject strategy (as seen here), and have a prompt pop up to ask the user if the correct boundary was created. My problem below is that the boundary doesn't appear before the prompt. It only shows up after the entire transaction commits. Is there a way to have it appear before the prompt?
Please see some screenshots of my problem attached.
private void Button_Click(object sender, EventArgs e)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
db.LineWeightDisplay = true;
double boundedarea = 0;
bool keeplooping = true;
ObjectIdCollection ids = new ObjectIdCollection();
using (EditorUserInteraction edUserInt = ed.StartUserInteraction(this))
{
while (keeplooping)
{
PromptPointOptions ptOptions = new PromptPointOptions("\nSelect point within area ");
ptOptions.AllowNone = false;
PromptPointResult ptResult = ed.GetPoint(ptOptions);
if (ptResult.Status != PromptStatus.OK)
return;
DBObjectCollection collection = ed.TraceBoundary(ptResult.Value, true);
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
ObjectId ModelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
BlockTableRecord model = Tx.GetObject(ModelSpaceId, OpenMode.ForWrite) as BlockTableRecord;
Polyline pline = collection[0] as Polyline;
if (pline != null)
{
pline.ColorIndex = 1;
pline.LineWeight = LineWeight.LineWeight050;
ids.Add(model.AppendEntity(pline));
Tx.AddNewlyCreatedDBObject(pline, true);
boundedarea = pline.Area;
ed.Regen(); //I'd like the boundary from TraceBoundary to be red and thick at this point
//so when kwOptions is run, the user can see if they selected the correct area
PromptKeywordOptions kwOptions = new PromptKeywordOptions("\nIs this the correct area? ");
kwOptions.Keywords.Add("Yes");
kwOptions.Keywords.Add("No");
kwOptions.Keywords.Default = "Yes";
kwOptions.AllowNone = true;
PromptResult pKeyRest = ed.GetKeywords(kwOptions);
if (pKeyRest.StringResult == "Yes")
{
textBox1.Text = boundedarea.ToString();
keeplooping = false;
Tx.Commit();
}
else
Tx.Abort();
}
}
}
edUserInt.End();
}
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; (this .cs contains a lot of other methods - not all assemblies relevant here)
Solved! Go to Solution.