- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have this code that tries to copy custom iproperties from a drawing to another drawing. It allows the user to specify which drawing to copy the iproperties from source drawing and it is supposed to assign copied values to the target drawing. Can someone please debug this? Thanks!
Imports System.Windows.Forms
' Import necessary namespaces
' Create a file dialog box to select the source drawing
Dim oFileDialog As New OpenFileDialog()
oFileDialog.Filter = "AutoCAD Drawings (*.dwg)|*.dwg"
oFileDialog.Title = "Select Source Drawing"
' Show the dialog and get the result
If oFileDialog.ShowDialog() = DialogResult.OK Then
Dim sourceDrawingPath As String = oFileDialog.FileName
' Open the source drawing
Dim sourceDoc As Document = ThisApplication.Documents.Open(sourceDrawingPath, False)
' Get the active document (target drawing)
Dim targetDoc As Document = ThisApplication.ActiveDocument
' List of custom iProperties to copy
Dim customProperties As New List(Of String) From {"Client_1", "Client_2"}
' Loop through each custom property and copy its value
For Each propName As String In customProperties
Try
' Read the iProperty value from the source document
Dim propValue As String = iProperties.Value(sourceDoc, "Custom", propName)
' Write the iProperty value to the target document
iProperties.Value(targetDoc, "Custom", propName) = propValue
' Show the copied property value
MessageBox.Show("Copied property: " & propName & " with value: " & propValue, "Property Copied", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
MessageBox.Show("Error copying property: " & propName & ". " & ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Next
' Save the target drawing
targetDoc.Save()
' Close the source drawing
sourceDoc.Close(True)
Else
MessageBox.Show("No file selected. Please try again.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
Solved! Go to Solution.