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

Amazing. Thank you, that just works excelent. I wouldn't be able to write that code. I have just added an input box to the code and it is awesome.

 

Thank you

 

Sub Main
	If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisDoc.Document
	Dim oSheets As Inventor.Sheets = oDDoc.Sheets
	'get user input
	Dim sTextToFind As String = InputBox("Enter Text To Find:", "iLogic", "XXX")
		'look for blank value
		If sTextToFind = "" Then
			Return 'exit rule
		End If
		
	Dim sTextToReplaceIt As String = InputBox("Enter Text To Replace   '" & oTXT2Find _
		& "'  with.", "iLogic", "ZZZ")
		'look for blank value
		If sTextToReplaceIt = "" Then
			Return 'exit rule
		End If

	For Each oSheet As Inventor.Sheet In oSheets
		Dim oCTables As Inventor.CustomTables = oSheet.CustomTables
		If oCTables.Count = 0 Then Continue For 'skip to next oSheet in loop
		For Each oCTable As Inventor.CustomTable In oCTables
			If oCTable.Title.Contains(sTextToFind) Then
				Try
					oCTable.Title = oCTable.Title.Replace(sTextToFind, sTextToReplaceIt)
				Catch
					Logger.Error("Error replacing text in Title of CustomTable")
				End Try
			End If
			'<<< you can traverse the data in the table by rows or by columns >>>
			Dim oRows As Inventor.Rows = oCTable.Rows
			For Each oRow As Inventor.Row In oRows
				For Each oCell As Inventor.Cell In oRow
					If oCell.Value.Contains(sTextToFind) Then
						Try
							oCell.Value = oCell.Value.Replace(sTextToFind, sTextToReplaceIt)
						Catch
							Logger.Error("Error replacing text in Cell of CustomTable")
						End Try
					End If
				Next 'oCell
			Next 'oRow
		Next 'oCTable
	Next 'oSheet
	If oDDoc.RequiresUpdate Then oDDoc.Update2(True)
	'If oDDoc.Dirty Then oDDoc.Save2(False)
End Sub

 

Tags (1)