Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
dxmv
228 Views, 2 Replies

The Title is not added

Hello. I need to save pdf drawing files from an assembly. Each part has a designation and name (Title). I wrote the code for automation.. Now ilogic creates files with the designation (file name). I need him to add the name separated by a space. Here's a code example -

Imports System.Windows.Forms
Imports System.IO

Sub
Main() Try ' Получаем активную сборку Dim oAssemblyDoc As AssemblyDocument oAssemblyDoc = ThisApplication.ActiveDocument Dim assemblyFileName As String = oAssemblyDoc.FullFileName ' Сохраняем список файлов сборки и их путей Dim componentFiles As New List(Of String) For Each oComponent As ComponentOccurrence In oAssemblyDoc.ComponentDefinition.Occurrences Dim partFullPath As String = oComponent.Definition.Document.FullFileName Dim partDirectory As String = System.IO.Path.GetDirectoryName(partFullPath) Dim partFileName As String = System.IO.Path.GetFileNameWithoutExtension(partFullPath) Dim idwFile As String = System.IO.Path.Combine(partDirectory, partFileName & ".idw") ' Проверяем, существует ли IDW файл If System.IO.File.Exists(idwFile) Then componentFiles.Add(idwFile) End If Next ' Закрываем сборочный файл oAssemblyDoc.Close(False) ' Открываем диалоговое окно для выбора папки Dim folderDialog As New FolderBrowserDialog folderDialog.Description = "Выберите папку для сохранения PDF файлов" If folderDialog.ShowDialog() <> DialogResult.OK Then MessageBox.Show("Папка не выбрана. Операция отменена.") ' Открываем сборочный файл снова ThisApplication.Documents.Open(assemblyFileName) Exit Sub End If Dim saveFolder As String = folderDialog.SelectedPath ' Переменная для хранения путей сохраненных файлов Dim savedFiles As String = "" ' Проходим по всем IDW файлам из списка For Each idwFile As String In componentFiles ' Открываем IDW файл Dim oDoc As Document = ThisApplication.Documents.Open(idwFile) ' Получаем путь и имя файла Dim folder As String = System.IO.Path.GetDirectoryName(oDoc.FullFileName) Dim fileName As String = System.IO.Path.GetFileNameWithoutExtension(oDoc.FullFileName) Dim title As String = "" ' Проверяем, существует ли набор свойств "Summary" Try title = iProperties.Value("Summary", "Title") Catch ex As Exception title = "NoTitle" End Try ' Формируем полное имя файла Dim fullFileName As String = System.IO.Path.Combine(saveFolder, fileName & " " & title & ".pdf") ' Применяем ваш код для сохранения PDF oDoc.SaveAs(fullFileName, True) ' Закрываем IDW файл без сохранения oDoc.Close(False) ' Добавляем путь сохраненного файла в переменную savedFiles &= fullFileName & vbCrLf Next ' Сообщаем пользователю о завершении и выводим пути сохраненных файлов If savedFiles = "" Then MessageBox.Show("Не найдено ни одного IDW файла для создания PDF.") Else MessageBox.Show("Создание PDF завершено. Файлы сохранены по следующим путям:" & vbCrLf & savedFiles) End If ' Открываем сборочный файл снова ThisApplication.Documents.Open(assemblyFileName) Catch ex As Exception MessageBox.Show("Произошла ошибка: " & ex.Message) End Try End Sub

- what am I doing wrong?