.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to lock Custom Properties of the Drawing File?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
vasantpadhiyar71
791 Views, 3 Replies

How to lock Custom Properties of the Drawing File?

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
3 REPLIES 3
Message 2 of 4
Artvegas
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

Message 3 of 4

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).

Message 4 of 4
Hallex
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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost