.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trouble with Transactions

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
brian.young
825 Views, 3 Replies

Trouble with Transactions

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)

 

3 REPLIES 3
Message 2 of 4

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.

Message 3 of 4

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

Message 4 of 4
Dale.Bartlett
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




______________
Yes, I'm Satoshi.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost