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

0 Members and 1 Guest are viewing this topic.

netcai

  • Mosquito
  • Posts: 10
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

  • SuperMod
  • Swamp Rat
  • Posts: 993
  • 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

Sometimes the question is more important than the answer.

netcai

  • Mosquito
  • Posts: 10
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

  • Water Moccasin
  • Posts: 2094
  • 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

FriendFromArea51

  • Swamp Rat
  • Posts: 707
  • Mars sucks!
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

  • Water Moccasin
  • Posts: 2094
  • 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