.NET

Reply
*Expert Elite*
_gile
Posts: 2,077
Registered: ‎04-29-2006
Message 11 of 12 (211 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 (198 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

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community