Export - Directory Not Found Exception

Export - Directory Not Found Exception

Anonymous
Not applicable
1,284 Views
5 Replies
Message 1 of 6

Export - Directory Not Found Exception

Anonymous
Not applicable
I am trying to use the export method to export a view to dwg, but it keeps throwing a directory not found exception. Can someone please tell me what I am doing wrong? Here is my class:

Imports System.IO
Imports Autodesk.Revit

Public Class rvtExport

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Export View to 2007 DWG
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Public Shared Function exportViewDWG(ByVal rvtapp As Autodesk.Revit.Application) As String

Dim str As String = Nothing
Dim viewSet As Autodesk.Revit.Elements.ViewSet = rvtapp.Create.NewViewSet
Dim expOpt As DWGExportOptions = rvtapp.Create.NewDWGExportOptions
Dim pathName As String = rvtapp.ActiveDocument.PathName
Dim folderName As String = Path.GetDirectoryName(pathName)
Dim fileName As String = "Test"

'select view
viewSet.Insert(rvtapp.ActiveDocument.ActiveView)

'set options
expOpt.ExportingAreas = False
expOpt.FileVersion = Enums.ACADVersion.Default
expOpt.ExportOfSolids = Enums.SolidGeometry.ACIS
expOpt.MergedViews = True
expOpt.SharedCoords = False
expOpt.TargetUnit = Autodesk.Revit.Enums.ExportUnit.Inch

Try
If rvtapp.ActiveDocument.Export(folderName, fileName, viewSet, expOpt) Then
str = "Exported " & folderName & fileName & vbCr
Else
str = "Failed to export " & folderName & fileName & vbCr
End If
Catch ex As System.IO.DirectoryNotFoundException
str = "Directory not found: " & ex.Message
End Try

Return str

End Function

End Class
0 Likes
1,285 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
in your error, report to yourself the values for filename and foldername. The problem is likely the folder path does not exist. Check for errors such as missing slashes, or misspelled folders. Make sure the folder in question is 'pre created'.
jvj
0 Likes
Message 3 of 6

nmeek
Contributor
Contributor
Jamie,

I've made sure that the target folder does exist. In fact, I am using the same folder that the project is saved in. I have checked for formatting errors and missing slashes and am a complete loss. Could this be a security issue?
0 Likes
Message 4 of 6

Anonymous
Not applicable
Always, try a temp folder created on the root C drive. Also one other thought, if you have too many slashes, I'm guessing here, but if the last folder name has a final slash does is have a cow with that?
0 Likes
Message 5 of 6

nmeek
Contributor
Contributor
I hate to think of all of the time I spent on this issue, but it is working. It seems that the exception is thrown only while debugging, and not while using the actual build. Do you know if this behavior is as intended?
0 Likes
Message 6 of 6

Anonymous
Not applicable
There are several things you can turn on and off for debugging in the Visual Studio environment. It could be a 'harmless' exception that the code continues without, but the debugger is capturing it just to let you know to write more solid code. This is in a section called exceptions in the debug menu. There are countless other places you can watch visual studio behave differently during debug mode vs run mode, some can be found in your project's properties section. There's a lot to learn there and even I don't know it all.
0 Likes