.NET

.NET

Reply
Contributor
23 Posts
0 Kudos
Registered: ‎05-25-2012
Post 1 of 4
Accepted Solution

How to lock Custom Properties of the Drawing File?

407 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
104 Posts
11 Kudos
Registered: ‎04-21-2011
Post 2 of 4

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*
1,088 Posts
217 Kudos
Registered: ‎04-27-2009
Post 3 of 4

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*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 4 of 4

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 interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!