Author Topic: Set DWF Filename  (Read 2102 times)

0 Members and 1 Guest are viewing this topic.

TJK44

  • Guest
Set DWF Filename
« on: May 28, 2013, 04:21:30 PM »
Hi,

I am trying to rename a DWF file before publishing. I am not finding what the property is to rename the file, it seems like it is just using the name of the dwg the dwf if generated from. Here is the code I am using to accomplish this.

Code - Visual Basic: [Select]
  1.         Private dwgFile, dwfFile, dsdFile, title, outputDir As String
  2.  
  3.         Public Sub New()
  4.             outputDir = DirectCast(Application.GetSystemVariable("DWGPREFIX"), String)
  5.             Dim name As String = DirectCast(Application.GetSystemVariable("DWGNAME"), String)
  6.             dwgFile = Path.Combine(outputDir, name)
  7.             title = Path.GetFileNameWithoutExtension(name)
  8.             dwfFile = Path.ChangeExtension(dwgFile, ".dwf")
  9.             dsdFile = Path.ChangeExtension(dwfFile, ".dsd")
  10.  
  11.         End Sub
  12.  
  13.         Public Sub New(outputDir As String)
  14.             Me.New()
  15.             Me.outputDir = outputDir
  16.             dwfFile = Path.GetFileNameWithoutExtension(Application.DocumentManager.MdiActiveDocument.Name) & (Directory.GetDirectories(outputDir).Length + 1).ToString() & ".dwf"
  17.         End Sub
  18.  
  19.         Public Sub Publish()
  20.             If File.Exists(dwfFile) Then
  21.                 File.Delete(dwfFile)
  22.             End If
  23.             Dim bgPlot As Short = CShort(Application.GetSystemVariable("BACKGROUNDPLOT"))
  24.             Application.SetSystemVariable("BACKGROUNDPLOT", 1)
  25.  
  26.             If Not Directory.Exists(outputDir) Then
  27.                 Directory.CreateDirectory(outputDir)
  28.             End If
  29.  
  30.             Using dsd As New DsdData()
  31.                 Using dsdEntries As New DsdEntryCollection()
  32.                     ' add the Model layout to the entry collection
  33.                    Dim dsdEntry As New DsdEntry()
  34.                     dsdEntry.DwgName = dwgFile
  35.                     dsdEntry.Layout = "Model"
  36.                     dsdEntry.Title = title
  37.                     dsdEntry.Nps = "0"
  38.                     dsdEntries.Add(dsdEntry)
  39.                     dsd.SetDsdEntryCollection(dsdEntries)
  40.                     ' set DsdData data
  41.                    dsd.Dwf3dOptions.PublishWithMaterials = True
  42.                     dsd.Dwf3dOptions.GroupByXrefHierarchy = True
  43.                     dsd.SetUnrecognizedData("PwdProtectPublishedDWF", "FALSE")
  44.                     dsd.SetUnrecognizedData("PromptForPwd", "FALSE")
  45.                     dsd.SheetType = SheetType.SingleDwf
  46.                     dsd.NoOfCopies = 1
  47.                     dsd.ProjectPath = outputDir
  48.                     dsd.IsHomogeneous = True
  49.  
  50.                     If File.Exists(dsdFile) Then
  51.                         File.Delete(dsdFile)
  52.                     End If
  53.  
  54.                     ' write the DsdData file
  55.                    dsd.WriteDsd(dsdFile)
  56.  
  57.                     ' get the Dsd File contents
  58.                    Dim str As String
  59.                     Using sr As New StreamReader(dsdFile, Encoding.[Default])
  60.                         str = sr.ReadToEnd()
  61.                     End Using
  62.                     ' edit the contents
  63.                    str = str.Replace("Has3DDWF=0", "Has3DDWF=1")
  64.                     str = str.Replace("PromptForDwfName=TRUE", "PromptForDwfName=FALSE")
  65.                     ' rewrite the Dsd file
  66.                    Using sw As New StreamWriter(dsdFile, False, Encoding.[Default])
  67.                         sw.Write(str)
  68.                     End Using
  69.  
  70.                     ' import the Dsd file new contents in the DsdData
  71.                    dsd.ReadDsd(dsdFile)
  72.  
  73.                     File.Delete(dsdFile)
  74.  
  75.                     Dim pc As PlotConfig = PlotConfigManager.SetCurrentConfig("DWF6 ePlot.pc3")
  76.  
  77.                     Application.Publisher.PublishExecute(dsd, pc)
  78.                     Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot)
  79.                 End Using
  80.             End Using
  81.         End Sub
  82.  

Thanks,

-Ted
« Last Edit: May 28, 2013, 04:33:01 PM by TJK44 »

n.yuan

  • Bull Frog
  • Posts: 348
Re: Set DWF Filename
« Reply #1 on: May 29, 2013, 04:17:03 PM »
The "DsdData" class has a property "DestinationName", which is the publishing output file name? Simply give this property a valid full pah (DWF file name with path), the multiple-DsdEntry publishing will generate a multiple-page DWF file. The same applies to PDF publishing, of course.

TJK44

  • Guest
Re: Set DWF Filename
« Reply #2 on: May 29, 2013, 05:22:46 PM »
Changing the DestinationName property does not change the name of the dwf file. Changing the ProjectPath property does output it the correct folder, just can't seem to figure out how to change the filename still.

TJK44

  • Guest
Re: Set DWF Filename
« Reply #3 on: June 03, 2013, 05:03:51 PM »
Could anyone else try changing the DestinationName property and see if it saves the DWF as that filename, so far not much luck. Thanks.