Posts: 2
Registered: ‎10-25-2012
Message 1 of 4 (339 Views)
Accepted Solution

Trouble with Transactions

339 Views, 3 Replies
10-30-2012 09:20 PM

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)

                    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;
                            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.Default = "Yes";
                            kwOptions.AllowNone = true;
                            PromptResult pKeyRest = ed.GetKeywords(kwOptions);

                            if (pKeyRest.StringResult == "Yes")
                                textBox1.Text = boundedarea.ToString();
                                keeplooping = false;


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)


Valued Mentor
Posts: 370
Registered: ‎05-06-2012
Message 2 of 4 (319 Views)

Re: Trouble with Transactions

10-31-2012 04:50 AM in reply to: brian.young

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.

Posts: 2
Registered: ‎10-25-2012
Message 3 of 4 (297 Views)

Re: Trouble with Transactions

10-31-2012 09:01 AM in reply to: DiningPhilosopher

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.




Distinguished Contributor
Posts: 140
Registered: ‎01-06-2003
Message 4 of 4 (198 Views)

Re: Trouble with Transactions

12-15-2012 11:46 PM in reply to: brian.young

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

Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.