TheSwamp

Code Red => .NET => Topic started by: Keith Brown on February 22, 2013, 12:06:32 PM

Title: Change default name of newly created file?
Post by: Keith Brown on February 22, 2013, 12:06:32 PM
I have a couple commands that I have created that allow me to create a new drawing from a specified template using .net.  When the drawing opens up they are listed as drawing1.dwg, drawing2.dwg, etc.  Standard operating procedure.  What I was wondering was if I could change the default name on a per template basis.  For instance when i create a drawing from template x the name would be xdrawing1.dwg and if created from template y it would be ydrawing1.dwg.

Has anyone attempted something like this before?
Title: Re: Change default name of newly created file?
Post by: MexicanCustard on February 22, 2013, 01:16:43 PM
Database.OriginalFileName will give you the name of the template used for Drawing1, Drawing2 etc.  Don't know if you can change the name in the title bar without saving the drawing though.
Title: Re: Change default name of newly created file?
Post by: Keith Brown on February 22, 2013, 04:25:21 PM
I had thoughts of saving it to a temporary directory as the new name and then monitoring the save event handler to check and see if it was in the temporary directory.  If so then prompt for the user to save the drawing with a new name.

It is not that big of a deal to leave it as it is now, I was just wondering if there was anything I could do without jumping through too many hoops.  Thanks for the reply.
Title: Re: Change default name of newly created file?
Post by: Jeff H on February 22, 2013, 06:44:37 PM
DOH!!

If I understand correctly I think you mean what is displayed as the Window Text and thought that could be useful.
Without giving it much thought or testing and just to check if it worked and was obtaining the correct window I added this to bottom of a "Command Class", and half way worked.

I used a template file path that did not exist so it use default template.
Code - C#: [Select]
  1.  [CommandMethod("NewDwg")]
  2.         public void NewDwg()
  3.         {
  4.             Application.DocumentManager.Add("fhfhf.dwt", "New Title");
  5.         }
  6.     }
  7. }
  8.  
  9.  
  10. namespace Autodesk.AutoCAD.ApplicationServices
  11. {
  12.     public static class DocumentCollectionExtions
  13.     {
  14.        
  15.         public static Document Add(this DocumentCollection docs, string filePath, string titleText)
  16.         {
  17.             Document doc = docs.Add(filePath);
  18.             docs.MdiActiveDocument = doc;
  19.             SetWindowText(GetActiveWindow(), titleText);
  20.             return doc;
  21.         }
  22.  
  23.         [DllImport("user32.dll")]
  24.         static extern IntPtr GetActiveWindow();
  25.         [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
  26.         public static extern bool SetWindowText(IntPtr hwnd, String lpString);
  27.  
  28.     }
  29. }