.NET

.NET

Reply
*Expert Elite*
_gile
Posts: 2,133
Registered: ‎04-29-2006
Message 11 of 12 (232 Views)

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.New()
            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)
            Try
                If Not Directory.Exists(outputDir) Then
                    Directory.CreateDirectory(outputDir)
                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"
                        dsdEntries.Add(dsdEntry)
                        dsd.SetDsdEntryCollection(dsdEntries)

                        ' 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
                            File.Delete(dsdFile)
                        End If

                        ' write the DsdData file
                        dsd.WriteDsd(dsdFile)

                        ' 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])
                            sw.Write(str)
                        End Using

                        ' import the Dsd file new contents in the DsdData
                        dsd.ReadDsd(dsdFile)

                        File.Delete(dsdFile)

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

 

 

 

Gilles Chanteau
Contributor
ken.washburn
Posts: 25
Registered: ‎06-10-2008
Message 12 of 12 (219 Views)

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!

Ken

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.