*Expert Elite*
2,140 Posts
253 Kudos
Registered: ‎04-29-2006
Post 11 of 12

Re: Is there a way to create a 3D DWF from a drawing using VB.Net

07-17-2012 01:13 PM in reply to: ken.washburn

Oopss !...

i removed a DsdData setting I shouldn't: DsdData.DestinationName. This isn't required while DsdData.SheetType = SheetType.SingleDwf (this forces the output file name to be the same as the input dwg).


Here's a VB code which seems to work as you expect:

Imports System.IO
Imports System.Text
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.PlottingServices

Namespace Plottings
    Public Class PlotTo3dDwf
        Private dwgFile, dwfFile, dsdFile, title, outputDir As String

        Public Sub New()
            outputDir = DirectCast(Application.GetSystemVariable("DWGPREFIX"), String)
            Dim name As String = DirectCast(Application.GetSystemVariable("DWGNAME"), String)
            dwgFile = Path.Combine(outputDir, name)
            title = Path.GetFileNameWithoutExtension(name)
            dwfFile = Path.Combine(outputDir, title & "-3d.dwf") ' <- add the "-3d" suffix to the file name
            dsdFile = Path.ChangeExtension(dwfFile, ".dsd")
        End Sub

        Public Sub New(outputDir As String)
            Me.outputDir = outputDir
            dwfFile = Path.Combine(outputDir, title & "-3d.dwf")
        End Sub

        Public Sub Publish()
            Dim bgPlot As Short = CShort(Application.GetSystemVariable("BACKGROUNDPLOT"))
            Application.SetSystemVariable("BACKGROUNDPLOT", 0)
                If Not Directory.Exists(outputDir) Then
                End If

                Using dsd As New DsdData()
                    Using dsdEntries As New DsdEntryCollection()
                        ' add the Model layout to the entry collection
                        Dim dsdEntry As New DsdEntry()
                        dsdEntry.DwgName = dwgFile
                        dsdEntry.Layout = "Model"
                        dsdEntry.Title = title
                        dsdEntry.Nps = "0"

                        ' set DsdData data
                        dsd.Dwf3dOptions.PublishWithMaterials = True
                        dsd.Dwf3dOptions.GroupByXrefHierarchy = True
                        dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE")
                        dsd.SetUnrecognizedData("PromptForPwd", "FALSE")
                        dsd.SheetType = SheetType.MultiDwf
                        dsd.NoOfCopies = 1
                        dsd.ProjectPath = outputDir
                        dsd.DestinationName = dwfFile
                        dsd.IsHomogeneous = True

                        If File.Exists(dsdFile) Then
                        End If

                        ' write the DsdData file

                        ' get the Dsd File contents
                        Dim str As String
                        Using sr As New StreamReader(dsdFile, Encoding.[Default])
                            str = sr.ReadToEnd()
                        End Using
                        ' edit the contents
                        str = str.Replace("Has3DDWF=0", "Has3DDWF=1")
                        str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE")
                        ' rewrite the Dsd file
                        Using sw As New StreamWriter(dsdFile, False, Encoding.[Default])
                        End Using

                        ' import the Dsd file new contents in the DsdData


                        Dim pc As PlotConfig = PlotConfigManager.SetCurrentConfig("DWF6 ePlot.pc3")
                        Application.Publisher.PublishExecute(dsd, pc)
                    End Using
                End Using
                Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot)
            End Try
        End Sub
    End Class
End Namespace




Gilles Chanteau
25 Posts
0 Kudos
Registered: ‎06-10-2008
Post 12 of 12

Re: Is there a way to create a 3D DWF from a drawing using VB.Net

07-18-2012 07:47 AM in reply to: _gile

_gile, Thanks for the update!  I'm still having issues, but I'm thinking it is something with my drawings or system.  I ran it on four drawings yesterday and it created dwf files for two of them, but not the other two.  Of the two it created, one was blank and one was ok.  So I'll research this more on my end, but I think your code is working correctly.


Thanks again!


Post to the Community

Have questions about Autodesk products? Ask the community.

New Post