TheSwamp

Code Red => .NET => Topic started by: netcai on September 25, 2017, 10:07:12 PM

Title: cannot create layer through my custom panel?
Post by: netcai 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;
        }
}
Title: Re: cannot create layer through my custom panel?
Post by: kdub_nz on September 25, 2017, 10:47:04 PM

Investigate
Document.LockDocument()

and google eLockViolation Autocad
https://www.google.com.au/search?q=elockviolation+AutoCad
Title: Re: cannot create layer through my custom panel?
Post by: netcai 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 ?
Title: Re: cannot create layer through my custom panel?
Post by: gile on September 26, 2017, 01:25:06 AM
Hi,

From Kean Walmsley's blog (http://through-the-interface.typepad.com/through_the_interface/2011/02/managing-drag-drop-from-a-palette-into-autocad-using-net.html):
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().
Title: Re: cannot create layer through my custom panel?
Post by: nobody on September 27, 2017, 02:37:23 AM
Hi,

From Kean Walmsley's blog (http://through-the-interface.typepad.com/through_the_interface/2011/02/managing-drag-drop-from-a-palette-into-autocad-using-net.html):
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 ?
Title: Re: cannot create layer through my custom panel?
Post by: gile 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.             }