Monday 20 August 2012

Managing Superseded and Revised Drawings

Currently we do not use a database system like Vault or Project Wise to manage project superseded and revised drawings. Typically we just have a superseded file in the same folder as the production drawing and transfer a copy of a drawing to that folder prior to revising it for whatever reason.
Some times however I forget to make a backup copy of the drawing to the superseded folder. To over come this I put some code together the other day to prompt the user on opening of a drawing weather or not to create a copy to the superseded folder . Here is  dump  of the code that others may find helpful. Currently I append the current date and time to the file name but am looking at prompting for a revision letter or the like.
Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports System Imports System.IO Public Class Class4 Implements Autodesk.AutoCAD.Runtime.IExtensionApplication Private docMan As DocumentCollection = Application.DocumentManager <CommandMethod("AddDocColEvent")> _ Public Sub Initialize() Implements IExtensionApplication.Initialize AddHandler docMan.DocumentCreated, AddressOf docMan_DocumentCreated DoIt() End Sub <CommandMethod("RemoveDocColEvent")> _ Public Sub RemoveDocColEvent() RemoveHandler docMan.DocumentCreated, AddressOf docMan_DocumentCreated End Sub Public Sub Terminate() Implements IExtensionApplication.Terminate End Sub Sub docMan_DocumentCreated(ByVal sender As Object, ByVal e As DocumentCollectionEventArgs) DoIt() End Sub Private Sub DoIt() 'check if the drawing has been saved yet or not Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument Dim strDWGName As String = acDoc.Name Dim obj As Object = Application.GetSystemVariable("DWGTITLED") '' Check to see if the drawing has been named If System.Convert.ToInt16(obj) = 0 Then '' If the drawing is using a default name (Drawing1, Drawing2, etc) '' then do nothing Else 'Ask the user if they want to save a supercended version of this drawing Dim Message As String Message = "Save a Superseded version of this drawing." Dim style = MsgBoxStyle.YesNoCancel Or MsgBoxStyle.DefaultButton1 Or MsgBoxStyle.Critical Dim Title As String Title = "Supercended" ' Display the message box and save the response, Yes or No. Dim response = MsgBox(Message, style, Title) Select Case response Case 6 ' Yes 'Get the current drawings path ' Specify the directories you want to manipulate. Dim path As String = DrawingPath() Dim Directory As String = Application.GetSystemVariable("DWGPREFIX") & "Superseded\" 'Ask the user if they want to add a suffix or prefix to the file name ''Dim FormToOpen As Type ''FormToOpen = GetType(Form1) ''Dim frm As Form1 = CType(Activator.CreateInstance(FormToOpen), Form1) ''Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(frm) Dim time As DateTime = DateTime.Now Dim format As String = "yy.MM.dd.HH.mm" Dim timestring As String = (time.ToString(format)) Dim path2 As String = Directory & timestring & "_" & Application.GetSystemVariable("DWGNAME") 'Check for the supercended folder in the current drawing path 'Create directory Try If (Not System.IO.Directory.Exists(Directory)) Then System.IO.Directory.CreateDirectory(Directory) End If 'Save a copy of the current drawing ' Copy the file. File.Copy(path, path2) Catch ex As System.Exception MsgBox("Error " & Err.Description & " - " & Err.Number & Convert.ToChar(10)) Return End Try Case 7 'No 'Do Nothing Case 2 'Cancel 'Do Nothing Case Else MsgBox("Response not recongised") End Select End If End Sub Public Function DrawingPath() As String Dim doc As Document = Application.DocumentManager.MdiActiveDocument Dim hs As HostApplicationServices = HostApplicationServices.Current Dim path As String = hs.FindFile(doc.Name, doc.Database, FindFileHint.[Default]) 'doc.Editor.WriteMessage(vbLf & "File was found in: " & path) Return path End Function End Class

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...