Inventor Macro to replace text in multiple IDWs?

Inventor Macro to replace text in multiple IDWs?

andrew.galbreath
Participant Participant
88 Views
1 Reply
Message 1 of 2

Inventor Macro to replace text in multiple IDWs?

andrew.galbreath
Participant
Participant

Hello,

 

I've been trying to develop a macro that can open each file in a folder, check various text fields for a specified string, and then replace that string if it finds it. I started with a script from chatgpt, and tried debugging it, but it seems to always get caught up with defining General Tables (which is what I need the most), and I keep getting "Doesn't support this property or method" errors.

 

I attached the latest version on my code in a txt file.

 

Thanks in advance

 

-Andrew

0 Likes
89 Views
1 Reply
Reply (1)
Message 2 of 2

andrii_humeniukCUEER
Explorer
Explorer

Hi @andrew.galbreath .

ChatGPT often invents methods/properties and does not inform about it. In your case, this is exactly the situation. The sheet.Tables method does not exist in the API, instead you need to use Sheet.CustomTables. The same applies to the invTable.TitleRowCount + invTable.HeaderRowCount + invTable.DataRowCount methods, they are not in the API. Your piece of code that concerns General Table should look like this:

Dim oTable As CustomTable
For Each oTable In Sheet.CustomTables
	Dim oRow As Inventor.Row
	For Each oRow In oCTable.Rows
		Dim oCell As Inventor.Cell
		For Each oCell In oRow
			If oCell.Value.Contains(searchString) Then
				Try
					oCell.Value = oCell.Value.Replace(searchString, replaceString)
				Catch
					Logger.Error("Error replacing text in Cell of CustomTable")
				End Try
			End If
		Next
	Next
Next

Also, for better understanding, check out the following publications: link, link.

0 Likes