Hi @prashanth_s1997. I think I have something ready for you to review and/or test. Please double check the file name of the sketched symbol library file. I assume it is a .dwg, instead of an .idw, since you mentioned that your drawing files are .dwg. Also make sure the names of the sketched symbol definitions are correct. Capitalization may be important too. Anyways, this code is designed to 'update' the old sketched symbol within the old drawing files with from the sketched symbol library, which assumes that the old and new sketched symbols still have exactly the same names. If this is not the case, then the code process will need to become more detailed and complicated. This code does not yet contain much feedback for when something doesn't work, but does include a lot of error avoidance, so that the rest of the code can continue when something doesn't work. All that can be further developed later. I broke this down into 3 parts (main controlling routine, file dialog routine, and a routine for processing each file (in case multiple files were selected within the file dialog). If you have questions about the code before trying it out, feel free to ask them, because I have not tested this code myself yet, due to the custom contents.
Sub Main
'the full path & file name (with extension) of the SketchedSymbols Library drawing file
Dim sSLibDocFile As String = "C:\Users\Public\Documents\Autodesk\Inventor19\Design Data\Symbol Library.dwg"
'the DrawingDocument representing the SketchedSymbols Library
Dim oSLibDoc As DrawingDocument = Nothing
Try : oSLibDoc = ThisApplication.Documents.Open(sSLibDocFile, False) : Catch : End Try
If oSLibDoc Is Nothing Then Exit Sub
'while the file dialog is open, you can also select multiple files, instead of just 1
Dim sFileSelection As String = UseFileDialog(False, "Choose Drawings To Update")
If sFileSelection = "" Then Exit Sub
If sFileSelection.Contains("|") Then 'multiple files were selected
Dim oFiles As New List(Of String) 'initialize it
oFiles.AddRange(sFileSelection.Split("|"))
For Each sFile As String In oFiles
UpdateSketchedSymbolsFromLibrary(sFile, oSLibDoc)
Next
Else
UpdateSketchedSymbolsFromLibrary(sFileSelection, oSLibDoc)
End If
oSLibDoc.Close(True) ' True = skip saving the library file when closing it
MsgBox("Process completed.", vbInformation, "iLogic")
End Sub
Function UseFileDialog(Optional bSave As Boolean = False, Optional sTitle As String = vbNullString) As String
Dim oFDlg As Inventor.FileDialog : ThisApplication.CreateFileDialog(oFDlg)
oFDlg.DialogTitle = IIf(sTitle = "", "Select A File.", sTitle)
oFDlg.InitialDirectory = ThisApplication.DesignProjectManager.ActiveDesignProject.WorkspacePath
'oFDlg.Filter = "Autodesk Inventor Files (*.iam;*.dwg;*.idw;*.ipt) | *.iam;*.dwg;*.idw;*ipt | All files (*.*)|*.*"
oFDlg.Filter = "Autodesk Inventor Drawings (*.dwg;*.idw) | *.dwg;*.idw"
oFDlg.MultiSelectEnabled = True : oFDlg.OptionsEnabled = False
oFDlg.InsertMode = False : oFDlg.CancelError = True
Try : If bSave = True Then : oFDlg.ShowSave : Else : oFDlg.ShowOpen : End If : Catch : End Try
Return oFDlg.FileName
End Function
Sub UpdateSketchedSymbolsFromLibrary(sFileToProcess As String, oSSLibDoc As DrawingDocument)
If String.IsNullOrEmpty(sFileToProcess ) OrElse (System.IO.File.Exists(sFileToProcess ) = False) Then Exit Sub
If oSSLibDoc Is Nothing Then Exit Sub
Dim oDDoc As DrawingDocument = Nothing
Try : oDDoc = ThisApplication.Documents.Open(sFileToProcess , False) : Catch : End Try
If oDDoc Is Nothing Then Exit Sub
Dim oSSDs As SketchedSymbolDefinitions = oSSLibDoc.SketchedSymbolDefinitions
Dim oWPS_SD As SketchedSymbolDefinition = Nothing
Dim oPC_SD As SketchedSymbolDefinition = Nothing
Try : oWPS_SD = oSSDs.Item("WPS-ASME-B31.3-316L") : Catch : End Try
Try : oPC_SD = oSSDs.Item("Pipe class 1SDOP") : Catch : End Try
If oWPS_SD IsNot Nothing Then
Try : oWPS_SD.CopyTo(oDDoc, True) : Catch : End Try
End If
If oPC_SD IsNot Nothing Then
Try : oPC_SD.CopyTo(oDDoc, True) : Catch : End Try
End If
If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
If oDDoc.Dirty Then oDDoc.Save2(False)
oDDoc.Close(True)
End Sub
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS) 👍.
Edit: I fixed the sFile vs sFileToProcess variable mismatch between the definition line of the 'UpdateSketchedSymbolsFromLibrary' Sub routine, and some of the lines of code within it.
Wesley Crihfield

(Not an Autodesk Employee)