.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Trouble with Transactio ns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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...AddNewlyCreatedDBObje
Please see some screenshots of my problem attached.
private void Button_Click(object sender, EventArgs e)
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.D ocumentManager.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.
Re: Trouble with Transactio ns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Use the TransactionManager from the Document rather than the one from the Database, and just before you start each transaction, call the TransactionManager's EnableGraphicsFlush() method.
You will also need to refactor your code so that Commit() is called on each Transaction at the point where you want the newly added object to become visible. Also call Editor.UpdateScreen() after each call to Commit(), and with that you should not need to call Editor.Regen().
You can prompt for input after the transaction is committed but it is the call to Commit() that should trigger the graphics update.
Re: Trouble with Transactio ns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Ah, thank you!
turns out the graphics flush did the trick! More info here: http://www.theswamp.org/index.php?topic=30185.0
I replaced the ed.Regen() with Tx.TransactionManager.QueueForGraphicsFlush() and it works perfectly.
Thanks
Brian
Re: Trouble with Transactio ns
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Could someone point me to some information regarding the difference and different uses of TransactionManager from the Document rather than the one from the Database? Thanks, Dale

