Overwrite files with rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi Guys,
I have the rule that generates PDF and DXF's and place them in specific folders. The PDF files are overwriting without asking, as intended and the DXF's generated in folder "06. DXF - Cut" is also overwriting without asking as intended. But when DXF files are generated into folder "02. DXF" it prompt me if i want to overwrite.
I also want the DXF files in folder "02. DXF" to be overwritten without asking.
I tried for a long time now to figure it out, but without luck ☹️
Anybody have an idea, it would very much apreciated?
Here is the code:
Dim oDoc As Document = ThisApplication.ActiveDocument
If oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Dim file_path As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName)
If Right(file_path, 10) = "03. Native" Then
Dim new_file_path As String = Left(file_path, Len(file_path) - 10)
' Create the "02. DXF" folder in the same directory as the drawing
Dim dxf_folder_path As String = System.IO.Path.Combine(new_file_path, "02. DXF")
System.IO.Directory.CreateDirectory(dxf_folder_path)
' Create the "06. DXF - Cut" folder in the same directory as the drawing
Dim dxf_folder_path_cut As String = System.IO.Path.Combine(new_file_path, "06. DXF - Cut")
System.IO.Directory.CreateDirectory(dxf_folder_path_cut)
' Create the "01. PDF" folder in the same directory as the drawing
Dim pdf_folder_path As String = System.IO.Path.Combine(new_file_path, "01. PDF")
System.IO.Directory.CreateDirectory(pdf_folder_path)
' Iterate through all sheets in the drawing
For Each drawingSheet As Sheet In oDoc.Sheets
' Loop through all drawing views on the sheet
For Each oDrawingView As DrawingView In drawingSheet.DrawingViews
If oDrawingView.ReferencedFile IsNot Nothing Then
Dim oPartDoc As PartDocument = TryCast(oDrawingView.ReferencedFile.ReferencedDocument, PartDocument)
If oPartDoc IsNot Nothing Then
Dim oSMCD As SheetMetalComponentDefinition = TryCast(oPartDoc.ComponentDefinition, SheetMetalComponentDefinition)
If oSMCD IsNot Nothing Then
If Not oSMCD.HasFlatPattern Then
oSMCD.Unfold()
oSMCD.FlatPattern.ExitEdit()
End If
Dim part_file_name As String = System.IO.Path.GetFileNameWithoutExtension(oPartDoc.FullFileName)
Dim dxf_file_path As String = System.IO.Path.Combine(dxf_folder_path_cut, part_file_name & ".dxf")
Dim sOut As String = "FLAT PATTERN DXF?AcadVersion=R12"
Try
oSMCD.DataIO.WriteDataToFile(sOut, dxf_file_path)
Catch ex As Exception
MsgBox("Error exporting DXF: " & ex.Message, vbExclamation, "DXF Export Error")
End Try
End If
End If
End If
Next
Next
' Export the entire drawing as a DXF
Dim file_name As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName)
' Generate the PDF file
Dim pdf_file_path As String = System.IO.Path.Combine(pdf_folder_path, file_name & ".pdf")
' Use your provided PDF generation code here
ThisDoc.Document.SaveAs(pdf_file_path, True)
' Generate the DXF file for the whole drawing
If dxf_folder_path <> "" Then
Dim dxf_file_path_full As String = System.IO.Path.Combine(dxf_folder_path, file_name & ".dxf")
Try
oDoc.SaveAs(dxf_file_path_full, True)
Catch ex As Exception
MsgBox("Error exporting full DXF: " & ex.Message, vbExclamation, "DXF Export Error")
End Try
End If
Else
MsgBox("Forkert filsti. Der vil ikke blive lavet PDF og DXF filer.", vbExclamation, "Lav PDF/DXF")
End If
End If