Author Topic: cannot create layer through my custom panel?  (Read 2326 times)

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 12
cannot create layer through my custom panel?
« on: September 25, 2017, 10:07:12 PM »
I create a panel with one button,when I click the button,it will call a command to create a layer and linetype, but autocad always prompt me a "eLockViolation" error.

If I do not use panel,the code create layers and linetype correctly.

Code: [Select]
public class Command
    {
        static PaletteSet palette;
        static bool wasVisible;

        /// <summary>
        /// Creates the palette if it did not already exist, and shwos it.
        /// </summary>
        [CommandMethod("test" )]
        public static void CreateGridPanel()
        {
            if (palette == null)
            {
                palette = new PaletteSet("CaiGrid", "CONVPALETTE", new Guid("{929CAC46-8606-4580-A953-238B70CA76A1}"));
                palette.Style =
                    PaletteSetStyles.ShowAutoHideButton |
                    PaletteSetStyles.ShowCloseButton |
                    PaletteSetStyles.ShowPropertiesMenu;
                palette.MinimumSize = new System.Drawing.Size(410, 240);
                palette.AddVisual("CaiGrid", new GridView());

                // Automatically hides the palette while there is no active document.
                var docs = Application.DocumentManager;
                docs.DocumentBecameCurrent += (s, e) => palette.Visible = e.Document == null ? false : wasVisible;
                docs.DocumentCreated += (s, e) => palette.Visible = wasVisible;
                docs.DocumentToBeDeactivated += (s, e) => wasVisible = palette.Visible;
                docs.DocumentToBeDestroyed += (s, e) =>
                {
                    wasVisible = palette.Visible;
                    if (docs.Count == 1)
                        palette.Visible = false;
                };
            }
            palette.Visible = true;
        }
}

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2125
  • class keyThumper<T>:ILazy<T>
Re: cannot create layer through my custom panel?
« Reply #1 on: September 25, 2017, 10:47:04 PM »

Investigate
Document.LockDocument()

and google eLockViolation Autocad
https://www.google.com.au/search?q=elockviolation+AutoCad
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

netcai

  • Mosquito
  • Posts: 12
Re: cannot create layer through my custom panel?
« Reply #2 on: September 25, 2017, 10:56:21 PM »
thanks kdub,It's work now.
 I wonder if all the modeless winform or panel need to lock the document ?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: cannot create layer through my custom panel?
« Reply #3 on: September 26, 2017, 01:25:06 AM »
Hi,

From Kean Walmsley's blog:
Quote
Once again there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute().
Speaking English as a French Frog

nobody

  • Swamp Rat
  • Posts: 861
  • .net stuff
Re: cannot create layer through my custom panel?
« Reply #4 on: September 27, 2017, 02:37:23 AM »
Hi,

From Kean Walmsley's blog:
Quote
Once again there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute().

How does one "manually" lock a document anyway XD ?

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: cannot create layer through my custom panel?
« Reply #5 on: September 27, 2017, 02:50:35 AM »
How does one "manually" lock a document anyway XD ?

Code - C#: [Select]
  1.             Document doc = Application.DocumentManager.MdiActiveDocument;
  2.             if (doc != null)
  3.             {
  4.                 using (doc.LockDocument())
  5.                 {
  6.                     // you can safely use doc here
  7.                 }
  8.             }
Speaking English as a French Frog