Author Topic: in second dwg created entitys are not displayed  (Read 2193 times)

0 Members and 1 Guest are viewing this topic.

MarioR

  • Newt
  • Posts: 64
in second dwg created entitys are not displayed
« on: March 06, 2020, 08:04:50 AM »
Hello,

i have following situation:

- open two drawings (dwg-A and dwg-B)
- run an command in dwg-A (to transfer information from A to B)
- on dwg-A i take entity's and calculate coordinates for dwg-B
- on dwg-B i create entity's (lines and blocks(blockreferences))
- after dwg-B-transaction commit are not displayed

Only after save and re-open dwg-B are displayed the new entity's or after use 3d-orbit.

The command use the "Session-Flag" and around the "Transaction.StartTransaction", "BlockTableRecord.AppendEntity" and "Transaction.CommitTransaction" is using DocumentLock.

What can i do to make the new entity's are "normal" displayed?

regards Mario


Maxence

  • Mosquito
  • Posts: 3
Re: in second dwg created entitys are not displayed
« Reply #1 on: March 06, 2020, 08:54:50 AM »
Are you using the transaction manager from the document (Document.TransactionManager property)? Because it's not the same that the one from the database (Database.TransactionManager property). StartTransaction() returns an Autodesk.AutoCAD.ApplicationServices.AppTransaction where there is a call to FlushGraphics() in the Commit() method.

MarioR

  • Newt
  • Posts: 64
Re: in second dwg created entitys are not displayed
« Reply #2 on: March 06, 2020, 02:35:13 PM »
Hello Maxence,

okay i test it on next monday and replay the result.

regards and wish pleasant weekend.
Mario

MarioR

  • Newt
  • Posts: 64
Re: in second dwg created entitys are not displayed
« Reply #3 on: March 10, 2020, 05:12:46 AM »
Hello,

i have test the "flushGraphics":
https://forums.autodesk.com/t5/net/redrawing-the-screen-during-execution-of-a-command-method/m-p/3742004#M32644 last Message (9)
1. it only works on activ document, my code
Code: [Select]
// acDocument is the second Document
// acTransaction is the second Transaction
try
{
    Document currentDoc = Application.DocumentManager.CurrentDocument;
    if (currentDoc != acDocument)
    {
        Application.DocumentManager.CurrentDocument = acDocument;
    }
    acDocument.TransactionManager.EnableGraphicsFlush(true);
    acDocument.TransactionManager.FlushGraphics();
    Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
    if (currentDoc != acDocument))
    {
        Application.DocumentManager.CurrentDocument = currentDoc;
    }
}
catch (Exception ex)
{
Log.LogException(ex);
}
acTransaction.Commit();

But its no change. Display the new entitys only after 3d-orbit rotate or save and open file, not after _REDRAW ...

The sam action in current database & transaction (database from command call) it all works fine. :thinking:
« Last Edit: March 10, 2020, 05:43:45 AM by MarioR »

n.yuan

  • Bull Frog
  • Posts: 348
Re: in second dwg created entitys are not displayed
« Reply #4 on: March 10, 2020, 09:48:11 AM »
I think, the problem is that you use DocumentCollection.CurrentDocument instead of the usual DocumentCollection.MdiActiveDocument.

CurrentDocument property was only introduced into .NET API late (I could not remember when, though). The Managed API document does not say anything about it, but if you look into ObjectARX document->AcApDocManager->AcApDocManager::curDocument, which is where .NET API DocumentCollection.CurrentDocument from, it says:

Quote
This function returns the document having current context. The associated function, mdiActiveDocument(), returns the MDI active document. curDocument() and mdiActiveDocument() can be different. You can call curDocument() to make a document "current" without actually activating it. After finish your AcDbDatabase operation under the temporary current document, call setCurDocument(acDocManager->mdiActiveDocument()) to reset the MDI active document as the current document.

So, using CurrentDocument could be the issue. However, you say that you has set CommandFlags.Session, it implies that your code actually switch active document. But you did not say how your code transfer data from Dwg A to Dwg B. Since Acad2015, switching active document will cancel active command, or stop custom code execution against a drawing, you need to be careful with your code when MdiActiveDocument changes. Form the brief description of your original post, it seems to me that there may not be the need to change active drawing:

With Dwg A and Dwg B open and Dwg A as active drawing, you can build a custom command to do whatever with Dwg A and get needed data and then update Dwg B without making it MdiActiveDocument; After the command finished, if user activates Dwg B, I am pretty sure the changes in Dwg B will be there/visible.

MarioR

  • Newt
  • Posts: 64
Re: in second dwg created entitys are not displayed
« Reply #5 on: March 11, 2020, 08:56:37 AM »
Hello,

i have test and found a reason. If have the destination dwg the visual style realitic works all fine, but our dwg have visual style 2d-wireframe.
On this style do not correctly refresh entitys. We work with AutoCAD 2017 (it forced by company).

here is an minimalisty code example that works:

@n.yuan (when set MdiActiveDocument brake the active command in soureDocument, set CurrentDocument works).

Code: [Select]
        [CommandMethod("MYTEST", "TEST", CommandFlags.NoMultiple | CommandFlags.Modal | CommandFlags.Session)]
        public void pTest()
        {
            try
            {
                Boolean run = true;
                Document sourceDoc = Application.DocumentManager.MdiActiveDocument;
                Editor acEditor = sourceDoc.Editor;
                if (Application.DocumentManager.Count == 2)
                {
                    Transaction destTrans = null;
                    Document destDoc = null;
                    foreach (Document doc in Application.DocumentManager)
                    {
                        if (!doc.Database.FingerprintGuid.Equals(sourceDoc.Database.FingerprintGuid))
                        {
                            destDoc = doc;
                            break;
                        }
                    }
                    if (destDoc != null)
                    {
                        PromptPointResult acPromptPointResult;
                        PromptPointOptions acPromptPointOptions;
                        acPromptPointOptions = new PromptPointOptions("Please take markerpoint");
                        acPromptPointOptions.UseBasePoint = false;
                        ObjectId pLayerId = destDoc.Database.Clayer;
                        do
                        {
                            Point3d start = Point3d.Origin;
                            acPromptPointResult = acEditor.GetPoint(acPromptPointOptions);
                            if ((acPromptPointResult.Status == PromptStatus.OK))
                            {
                                start = acPromptPointResult.Value;
                                // line start -1 m to start + 1 m
                                Point3d newStart = new Point3d(start.X - 1.0, start.Y, start.Z);
                                Point3d newEnd = new Point3d(start.X + 1.0, start.Y, start.Z);
                                using (destTrans = destDoc.Database.TransactionManager.StartTransaction())
                                {
                                    Line newline = new Line(newStart, newEnd);
                                    newline.SetDatabaseDefaults(destDoc.Database);
                                    newline.LayerId = pLayerId;
                                    newline.LinetypeId = SymbolUtilityServices.GetLinetypeByLayerId(destDoc.Database);
                                    BlockTable acBlockTable = (BlockTable)destTrans.GetObject(destDoc.Database.BlockTableId, OpenMode.ForRead, false);
                                    BlockTableRecord acBlockTableRecord = (BlockTableRecord)destTrans.GetObject(destDoc.Database.CurrentSpaceId, OpenMode.ForWrite, false);
                                    acBlockTableRecord.AppendEntity(newline);
                                    destTrans.AddNewlyCreatedDBObject(newline, true);
                                    destTrans.Commit();
                                    // Force FlushGraphics
                                    Application.DocumentManager.CurrentDocument = destDoc;
                                    destDoc.TransactionManager.EnableGraphicsFlush(true);
                                    destDoc.TransactionManager.FlushGraphics();
                                    Autodesk.AutoCAD.Internal.Utils.FlushGraphics();
                                    Application.DocumentManager.CurrentDocument = sourceDoc;
                                }
                            }
                            else
                            {
                                acEditor.WriteMessage("\n[CANCEL]\n");
                                run = false;
                            }
                        } while (run);
                    }
                    else
                        acEditor.WriteMessage("\nonly with 2 DWG's!\n");
                }
                else
                    acEditor.WriteMessage("\nonly with 2 DWG's!\n");
            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex) { Log.LogException(ex); }
            catch (System.Exception ex) { Log.LogException(ex); }
        }

How can i also refresh the 2d-wireframe?

regards Mario

MarioR

  • Newt
  • Posts: 64
Re: in second dwg created entitys are not displayed
« Reply #6 on: March 17, 2020, 12:03:38 AM »
Hello,

my workaround is follow:

1. take the old visual-style from destination (second) DWG
2. set the visualstyle from destination DWG to relaistic
3. transfer entitys
4. set the visualstyle for destination deg to old visual style

regards Mario