- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello all,
I'm having an idw drawing generated from Woodwork for Inventor and it ganerates a Custom table with some material codes and descriptions for each part. I'm looking for an ilogic to go through all lists and all custom tables and find and replace specific text in all cells(material code).
I have already an ilogic to find and replace normal text or leaders, but I can't find a cell text replacement ilogic. I'm new to VBA and ilogic, I'm learning the basics, but this task is way too much for me.
Can anyone help?
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi @martin.jerabekM5BZE. Here is an iLogic rule example for finding & replacing text within either the Title, or the Cells of a CustomTable in a DrawingDocument. It is currently set up to loop through each sheet, and each CustomTable it finds on each sheet. Then after checking/processing its title, it will loop through each Row, and each Cell in each Row, checking/processing them.
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
Dim sTextToFind As String = "ToFind"
Dim sTextToReplaceIt As String = "Replacement"
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
If this solved your problem, or answered your question, please click ACCEPT SOLUTION .
Or, if this helped you, please click (LIKE or KUDOS)
.
Wesley Crihfield
(Not an Autodesk Employee)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm gonna assume you mean a Parts list when you say "list" or "Custom table"
here's my code to find the first parts list in a certain sheet, edit it, go over each cell in a certain row and edit that cell (if necessary)
happy coding!
edit: and I'm already too late, while I was typing there already was a solution posted, I love this community
sub main
call editpartslist
end sub
Sub editpartslist Dim oDrawDoc As DrawingDocument oDrawDoc = ThisDrawing.Document ' Set a reference to the first parts list on the selected sheet. Dim oPartList As PartsList Dim s As String s = "Sheetname:1" On Error GoTo sheetnotfound : oPartList = oDrawDoc.Sheets.Item(s).PartsLists.Item(1) On Error GoTo errorhandler : ' Iterate through the contents of the parts list. Dim i As Long For i = 1 To oPartList.PartsListRows.Count 'look at only the QTY column oCell = oPartList.PartsListRows.Item(i).Item("QTY") 'reset static values If oCell.Static = True Then oCell.Static = False 'do stuff in the cells v = oCell.Value If v.Contains("mm") Or v.Contains(",") oCell.Value = Ceil(Val(Replace(v, ",", "."))) Else End If Next Exit Sub 'errorhandling sheetnotfound : MessageBox.Show("sheet named " & s & " not found while editing partslist") : Exit Sub errorhandler : MessageBox.Show("error while editing partslist") : Exit Sub End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Thank you for your reply. I do actually mean a "Custom table". For a Part lists I do not normaly overwrite cell value and it is driven by iProperty. But a Custom table is generated by an addon and I don't want to refresh complete lists, as it refreshes also the model views and delete cross-section and detail views.