Imports System.Windows.Forms
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheets As Sheets = oDoc.Sheets
Dim selectedSheets As New List(Of String)
' Create a form to select sheets
Dim form As New Form()
form.Text = "Select Sheets to Export"
form.Width = 500
form.Height = 600
form.FormBorderStyle = FormBorderStyle.FixedDialog
form.StartPosition = FormStartPosition.CenterScreen
' Create a panel for scrolling
Dim panel As New Panel()
panel.AutoScroll = True
panel.Dock = DockStyle.Top
panel.Height = 450
form.Controls.Add(panel)
Dim checkBoxes As New List(Of CheckBox)
Dim yPosition As Integer = 10
' Add checkboxes for each sheet
For Each oSheet As Sheet In oSheets
Dim checkBox As New CheckBox()
checkBox.Text = oSheet.Name
checkBox.AutoSize = True
checkBox.Top = yPosition
checkBox.Left = 10
checkBoxes.Add(checkBox)
panel.Controls.Add(checkBox)
yPosition += 25
Next
' Export button
Dim confirmButton As New Button()
confirmButton.Text = "Export Selected"
confirmButton.Top = yPosition + 20
confirmButton.Left = 10
confirmButton.Width = 150
form.Controls.Add(confirmButton)
' Event handler for button click
AddHandler confirmButton.Click, Sub(sender As Object, e As EventArgs)
For Each checkBox As CheckBox In checkBoxes
If checkBox.Checked Then
selectedSheets.Add(checkBox.Text)
End If
Next
form.Close()
End Sub
' Show the form
form.ShowDialog()
' Check if any sheets were selected
If selectedSheets.Count = 0 Then
MessageBox.Show("No sheets selected for export.", "Export Canceled")
Exit Sub
End If
' Ask user for save location
Dim oFileDialog As New SaveFileDialog()
oFileDialog.Filter = "DXF Files (*.dxf)|*.dxf"
oFileDialog.Title = "Select DXF Save Location"
If oFileDialog.ShowDialog() = DialogResult.OK Then
Dim savePath As String = System.IO.Path.GetDirectoryName(oFileDialog.FileName)
' Export each selected sheet
For Each sheetName In selectedSheets
Try
Dim oSheet As Sheet = oSheets.Item(sheetName)
Dim safeSheetName As String = System.Text.RegularExpressions.Regex.Replace(oSheet.Name, "[^\w\.-]", "_")
Dim fullFileName As String = System.IO.Path.Combine(savePath, safeSheetName & ".dxf")
' Export the sheet
oSheet.SaveAs(fullFileName, SaveCopyAsOptionsEnum.kDXFFormat)
MessageBox.Show("DXF Exported: " & fullFileName, "Export Complete")
Catch ex As Exception
MessageBox.Show("Error exporting DXF for sheet " & sheetName & ": " & ex.Message, "Export Failed")
End Try
Next
Else
MessageBox.Show("DXF export canceled.", "Export Canceled")
End If
I had a better working version but I went through probably 25 different versions trying to get ChatGPT to fix all the mistakes, so this is the best one I could find. It still has an error code for that "savecopyasoptionsenum" but I don't understand much of this coding jargon. So, I'm lost haha.