dwg export using vb.net

dwg export using vb.net

Anonymous
Not applicable
2,471 Views
1 Reply
Message 1 of 2

dwg export using vb.net

Anonymous
Not applicable

 

Hi,

 

I am trying to use the API to export the current View as a DWG file (Revit 2015 using VB.net). This program is built in Visual Studio Express to a DLL and launched from the Revit add-ins->external->external tools menu item.

 

The attached code is based on sample code with the addition of the code to export the current view. Whilst this code works for exporting a view as a DWF, when I comment out the 'export as dwf' line and try to export as DWG there is a command failure error window stating a cast exception with

'Autodesk.Revit.DB.Viewset' to 'System.Collections.Generic.ICollection[Autodesk.Revit.DB.ElementId]'

 

for the line of code:

exported = activeDoc.Export("c:\\temp\\", "test", views, dwgExportOptions)

 

but this works for dwf:

exported = activeDoc.Export("c:\\temp\\", "test", views, mydwfExportOptions)

 

 

should there be a difference? and can someone show what code needs to be added to make the dwg export work?

I am not sure if the transaction wrapper is required for exporting as dwg; it was required to make the dwf export work.

 

Thanks,

Marty

 

 

 

0 Likes
Accepted solutions (1)
2,472 Views
1 Reply
Reply (1)
Message 2 of 2

rosalesduquej
Alumni
Alumni
Accepted solution

Hi Marty,

 

At first glance, I think I know why this is giving you a problem. The export of DWG will export a selection of Views as Dwg's, meaning one of your parameters is incorrect if you are trying to use the same ones you use for DWF. If you see the Revit Help file you will notice that the views parameter is a Collection of ElementId not 1 single ViewSet. And in your code I see you are passing the current active View to be exported. I think that might not work.

 

Public Function Export ( _
	folder As String, _
	name As String, _
	views As ICollection(Of ElementId), _
	options As DWGExportOptions _
) As Boolean

in comparison to DWF export

 

Public Function Export ( _
	folder As String, _
	name As String, _
	views As ViewSet, _
	options As DWFExportOptions _
) As Boolean

 So I think taking a look at the example the Revit Help file has will give you a much clear understanding on how to implement it. 

 

Also you could try the example that is located in the Help file.

 

Public Function ExportDWG(document As Document, view As View, setupName As String) As Boolean
    Dim exported As Boolean = False
    ' Get the predefined setups and use the one with the given name.
    Dim setupNames As IList(Of String) = BaseExportOptions.GetPredefinedSetupNames(document)
    For Each name As String In setupNames
        If name.CompareTo(setupName) = 0 Then
            ' Export using the predefined options
            Dim dwgOptions As DWGExportOptions = DWGExportOptions.GetPredefinedOptions(document, name)

            ' Export the active view
            Dim views As ICollection(Of ElementId) = New List(Of ElementId)()
            views.Add(view.Id)
            ' The document has to be saved already, therefore it has a valid PathName.
            exported = document.Export(Path.GetDirectoryName(document.PathName), Path.GetFileNameWithoutExtension(document.PathName), views, dwgOptions)
            Exit For
        End If
    Next

    Return exported
End Function

Hope this helps and let me know how it goes. Happy coding.

Cheers,

 



Jaime Rosales D.
Sr. Developer Consultant
Twitter | AEC ADN DevBlog