Posts: 23
Registered: ‎05-25-2012
Message 1 of 4 (385 Views)
Accepted Solution

How to lock Custom Properties of the Drawing File?

385 Views, 3 Replies
06-07-2012 05:01 AM

Hi Experts,


I have Custom Properties on Drawing File. Naturally it is non-editable. But from AutoCAD When I write Command "DWGPROPS" it can be edited. I does not want it to be edited at any time.


Is it Possible to lock it using Coding? Or CAN we disable the Command "DWGPROPS" of AUTOCAD into AutoCAD?



Distinguished Contributor
Posts: 104
Registered: ‎04-21-2011
Message 2 of 4 (366 Views)

Re: How to lock Custom Properties of the Drawing File?

06-08-2012 05:09 AM in reply to: vasantpadhiyar71

Here are some options for blocking the DWGPROPS command:


1.Use the UNDEFINE command:


Note: You might also need to make sure the user can't apply the REDEFINE command. To do this you could check the Document's CommandEnded event for the redefine command and then re-implement the undefine for DWGPROPS again.


2. Veto the command from the DocumentCollection's DocumentLockModeChanged event:



The down-side to blocking the command is that you will also block the other property tabs.


Perhaps instead you could use the Document's CommandWillStart event for the DWPROPS command to get a copy of the custom properties, and then use the Document's CommandWillEnd event to wipe any changes made by the user (i.e. copy the data back in). You could also advise your users of this implementation in a message box so they know that certain changes won't take effect.



*Expert Elite*
Posts: 987
Registered: ‎04-27-2009
Message 3 of 4 (357 Views)

Re: How to lock Custom Properties of the Drawing File?

06-08-2012 07:08 AM in reply to: vasantpadhiyar71

Besides what the other reply suggested, you may also consider to let AutoAD discard whatever user entered via command "DWGPROPS" automatically when a drawing is closed. Something like:


1. Saving the data you want to appear as drawing custom properties in a named dictionary;

2. Handle an event that fires when drawing is to be closed, such as Document.DocumentWillClose, or an event when drawing is to be saved, such as Database.BeginSave. In the event handler, you compare data in DataseSystemInfo and data in your named dictionary, if different found, you update DatabaseSystemInfo with data from your named dictionary.


This way, the drawing custom properties would always hold information of your choice, no matter what user does during an AutoCAD session (of course, with your code being loaded and running).

*Expert Elite*
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 4 (344 Views)

Re: How to lock Custom Properties of the Drawing File?

06-08-2012 10:45 AM in reply to: vasantpadhiyar71

Have you tried to clear the dwgprops by coding?

I'm not sure if this impossible,

try this sample:

        [CommandMethod("ci", CommandFlags.Session | CommandFlags.Modal)]
        public static void ClearDwgProps()
            Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;

            Editor ed = doc.Editor;

            bool yeah = false;

            Microsoft.Win32.OpenFileDialog dialog = new Microsoft.Win32.OpenFileDialog
        CheckFileExists = true,
        CheckPathExists = true,
        DefaultExt = "dwg",
        DereferenceLinks = true,
        Filter = "Drawings (*.dwg)|*.dwg|All files (*.*)|*.*",
        Title = "Select drawing file",
        FilterIndex = 1
            if (!dialog.ShowDialog().HasValue)

            string fname = dialog.FileName;


                using (DocumentLock doclock = doc.LockDocument())
                    using (Database extdb = new Database(true, false))

                        extdb.ReadDwgFile(fname, FileShare.ReadWrite, false, "");


                        extdb.SaveAs(fname, false, DwgVersion.Current, extdb.SecurityParameters);

                        yeah = true;

            catch (Autodesk.AutoCAD.Runtime.Exception ex)
                ed.WriteMessage("\n" + ex.Message + "\n" + ex.StackTrace);
                if (yeah)
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Dwgprops removed");
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Bad for you!");
        /// <summary>
        /// Clear dwgprops
        /// </summary>
        /// <param name="db"></param>
        private static void ClearSummaryInfo(Database db)

            DatabaseSummaryInfoBuilder body = new DatabaseSummaryInfoBuilder();

            DatabaseSummaryInfo suminfo = body.ToDatabaseSummaryInfo();

            db.SummaryInfo = suminfo;  




Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.