Hello Everyone,
I'm new to using Inventor and VBA, and I'm wondering if it's possible to automate the following tasks in Inventor using VBA. If so, could someone please provide guidance on the necessary steps?
Task 1: I need to insert a welding sticker into 50 Inventor drawing files to indicate welding procedures.
Task 2: I need to remove the old welding procedure sticker from 50 Inventor drawing files.
Task 3: I need to update the project name and date in the title block of 50 Inventor drawing files.
Currently, I'm manually opening each drawing to perform these tasks, and it would be incredibly helpful if someone could point me in the right direction for automation.
Solved! Go to Solution.
Hello Everyone,
I'm new to using Inventor and VBA, and I'm wondering if it's possible to automate the following tasks in Inventor using VBA. If so, could someone please provide guidance on the necessary steps?
Task 1: I need to insert a welding sticker into 50 Inventor drawing files to indicate welding procedures.
Task 2: I need to remove the old welding procedure sticker from 50 Inventor drawing files.
Task 3: I need to update the project name and date in the title block of 50 Inventor drawing files.
Currently, I'm manually opening each drawing to perform these tasks, and it would be incredibly helpful if someone could point me in the right direction for automation.
Solved! Go to Solution.
Solved by WCrihfield. Go to Solution.
Solved by romu51. Go to Solution.
For task 1, search for create and insert a sketch symbol
For Task 2, you will need the name of the sketch symbol if it was used or maybe search for text box and delete.
i can help with task 3!
iProperties.Value("Project", "Project") = "Your Project" iProperties.Value("Project", "Creation Date") = Now InventorVb.DocumentUpdate()
For task 1, search for create and insert a sketch symbol
For Task 2, you will need the name of the sketch symbol if it was used or maybe search for text box and delete.
i can help with task 3!
iProperties.Value("Project", "Project") = "Your Project" iProperties.Value("Project", "Creation Date") = Now InventorVb.DocumentUpdate()
Hi @prashanth_s1997. First of all, I would very much recommend that you start out using Inventor's iLogic, instead of Inventor's VBA, because the VBA in Inventor is on its way out. The past few releases of Autodesk Inventor no longer include the VBA editor in the normal installations, because it has become outdated, and the folks at Microsoft have not been keeping up with security updates for it anymore, which can lead to security risks. Inventor's iLogic is a built-in ApplicationAddIn that is geared towards folks with very little or no previous programming experience, and is based on the VB.NET programming language, which is pretty similar in many ways to VBA, but newer.
Next, what do you mean by 'sticker'? Do you mean a Welding Symbol (WeldSymbol)? If so, those have leaders usually need to be attached to some model geometry within a drawing view, and can have multiple nodes along their leaders, and have a user interface dialog which offers many ways to customize that symbol. That could be pretty complicated to write code to place those, and position them the way you want them, and get them customized the way you want them. For one thing, they only became available to Inventor's API (Application Programming Interface) in the 2024 release of Inventor, so if you don't have Inventor 2024, it may be impossible right now.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @prashanth_s1997. First of all, I would very much recommend that you start out using Inventor's iLogic, instead of Inventor's VBA, because the VBA in Inventor is on its way out. The past few releases of Autodesk Inventor no longer include the VBA editor in the normal installations, because it has become outdated, and the folks at Microsoft have not been keeping up with security updates for it anymore, which can lead to security risks. Inventor's iLogic is a built-in ApplicationAddIn that is geared towards folks with very little or no previous programming experience, and is based on the VB.NET programming language, which is pretty similar in many ways to VBA, but newer.
Next, what do you mean by 'sticker'? Do you mean a Welding Symbol (WeldSymbol)? If so, those have leaders usually need to be attached to some model geometry within a drawing view, and can have multiple nodes along their leaders, and have a user interface dialog which offers many ways to customize that symbol. That could be pretty complicated to write code to place those, and position them the way you want them, and get them customized the way you want them. For one thing, they only became available to Inventor's API (Application Programming Interface) in the 2024 release of Inventor, so if you don't have Inventor 2024, it may be impossible right now.
Wesley Crihfield
(Not an Autodesk Employee)
Thank you
OK. If you want a code based solution for taking care of this task, then every little detail needs to be known about the task and all the objects involved, because code needs to be very exact.
Edit: Also, are all of those 'old' drawings directly within one folder, or are they within several different folders?
If the code solution were to include a 'Browse' ability, would you prefer to pick each file individually to process, or would you prefer to pick a folder to process all the files within that folder. And if you prefer the whole folder route, then how would we be able to know which files in that folder need to be processed, and which do not? Is there something special about their file names, or maybe something special in their iProperties?
Wesley Crihfield
(Not an Autodesk Employee)
OK. If you want a code based solution for taking care of this task, then every little detail needs to be known about the task and all the objects involved, because code needs to be very exact.
Edit: Also, are all of those 'old' drawings directly within one folder, or are they within several different folders?
If the code solution were to include a 'Browse' ability, would you prefer to pick each file individually to process, or would you prefer to pick a folder to process all the files within that folder. And if you prefer the whole folder route, then how would we be able to know which files in that folder need to be processed, and which do not? Is there something special about their file names, or maybe something special in their iProperties?
Wesley Crihfield
(Not an Autodesk Employee)
Thank you so much @WCrihfield for taking your time to help me:
1. It is a user defined sketch symbol (Manage ----> Define ------> Symbol). I have to insert 2 symbols as show in the below image at the left corner of all the sheets. Both stickers have their own names and have been saved under : C:\Users\Public\Documents\Autodesk\Inventor19\Design Data\Symbol Library
2. Sticker names: WPS-ASME-B31.3-316L
Pipe class 1SD0P
3. The drawing files are in different folders inside a common project folder. I have to insert this in some of the .dwg files in the project folder. So, I would prefer to pick each file individually to process.
4. Since, I have inventor 19, is it possible to do this?
Thank you again for your help. Please tell me if there are any tutorials to learn automation in inventor?
Thank you so much @WCrihfield for taking your time to help me:
1. It is a user defined sketch symbol (Manage ----> Define ------> Symbol). I have to insert 2 symbols as show in the below image at the left corner of all the sheets. Both stickers have their own names and have been saved under : C:\Users\Public\Documents\Autodesk\Inventor19\Design Data\Symbol Library
2. Sticker names: WPS-ASME-B31.3-316L
Pipe class 1SD0P
3. The drawing files are in different folders inside a common project folder. I have to insert this in some of the .dwg files in the project folder. So, I would prefer to pick each file individually to process.
4. Since, I have inventor 19, is it possible to do this?
Thank you again for your help. Please tell me if there are any tutorials to learn automation in inventor?
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)
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)
Hi @prashanth_s1997. Here is a shorter version of that iLogic rule that attempts to do the same task, but tries to avoid the hard coded library file path, and attempts to get the library from each drawing file instead. I attached it as a text file.
Wesley Crihfield
(Not an Autodesk Employee)
Hi @prashanth_s1997. Here is a shorter version of that iLogic rule that attempts to do the same task, but tries to avoid the hard coded library file path, and attempts to get the library from each drawing file instead. I attached it as a text file.
Wesley Crihfield
(Not an Autodesk Employee)
Can't find what you're looking for? Ask the community or share your knowledge.