Saveas doesn't change drawing name!?

Discussion in 'AutoCAD' started by willemschwarte, Jul 6, 2004.

  1. What I want to do is:

    when a user saves a new document and types a name, I want to programmaticaly rename that drawing to a number, that i retrieve from a Database...

    but, when i get the filename in the beginsave event, and save the drawing with another name, the drawing in Autocad still has the old name, when I expect it to be the numberfilename..

    here's a little code i use...

    Private Sub myAutoCadApp_BeginSave(ByVal FileName As String) Handles myAutoCadApp.BeginSave
    Dim NextNumber As Integer
    Dim NextNumberFileName As String
    Dim flnExtension As String
    Dim OldFileName As String

    ' OldFileName is the name the user entered...
    OldFileName = FileName

    ' blnProcessSub is true if a new drawing was created...
    If blnProcessSub Then


    ' MessageBox.Show(myAutoCadApp.ActiveDocument.FullName)
    ' MessageBox.Show(myAutoCadApp.ActiveDocument.Name)


    ' blnNewDrawing is true only the first time
    If blnNewDrawing Then


    ' A number
    NextNumber = 1231
    ' convert number to path and extension of FileName
    NextNumberFileName = System.IO.Path.GetDirectoryName(FileName)
    flnExtension = System.IO.Path.GetExtension(FileName)
    If Not NextNumberFileName.EndsWith(System.IO.Path.DirectorySeparatorChar) Then
    NextNumberFileName &= System.IO.Path.DirectorySeparatorChar
    End If
    ' put the number as filename...
    NextNumberFileName &= NextNumber.ToString & flnExtension
    ' Trade places...
    FileName = NextNumberFileName
    ' Set false in case it enters the sub a second time..
    blnProcessSub = False
    ' Save the new number file
    myAutoCadApp.ActiveDocument.SaveAs(FileName)
    ' Delete the original file...
    System.IO.File.Delete(OldFileName)
    End If
    ' Set newdrawing to false
    blnNewDrawing = False
    Else
    blnProcessSub = True
    End If ' Processub
    End Sub
     
    willemschwarte, Jul 6, 2004
    #1
  2. The event only retrieves the filename by value not by reference. I think what you could do using the EndSave event is close the drawing, rename the file and then reopen the drawing.

    Regards - Nathan
     
    Nathan Taylor, Jul 7, 2004
    #2
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.