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,
Solved! Go to Solution.
Solved by Artvegas. Go to Solution.
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
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).
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'~