.NET

Reply
Contributor
vasantpadhiyar71
Posts: 23
Registered: ‎05-25-2012
Message 1 of 4 (399 Views)
Accepted Solution

How to lock Custom Properties of the Drawing File?

399 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?

 

Thanks,

Vasant PADHIYAR

Here are some options for blocking the DWGPROPS command:

 

1.Use the UNDEFINE command:

http://through-the-interface.typepad.com/through_the_interface/2007/03/replacing_the_o.html

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:

http://through-the-interface.typepad.com/through_the_interface/2006/10/blocking_autoca.html

 

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.

 

Art

Distinguished Contributor
Artvegas
Posts: 104
Registered: ‎04-21-2011
Message 2 of 4 (380 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:

http://through-the-interface.typepad.com/through_the_interface/2007/03/replacing_the_o.html

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:

http://through-the-interface.typepad.com/through_the_interface/2006/10/blocking_autoca.html

 

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.

 

Art

*Expert Elite*
norman.yuan
Posts: 1,049
Registered: ‎04-27-2009
Message 3 of 4 (371 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*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 4 of 4 (358 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)
                return;

            string fname = dialog.FileName;

            try
            {

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

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

                        ClearSummaryInfo(extdb);

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

                        yeah = true;
                    }
                }

            }
            catch (Autodesk.AutoCAD.Runtime.Exception ex)
            {
                ed.WriteMessage("\n" + ex.Message + "\n" + ex.StackTrace);
                return;
            }
            finally
            {
                if (yeah)
                {
                    Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("Dwgprops removed");
                }
                else
                {
                    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;  

        }

 

~'J'~

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!