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

I was thinking about making this run automatically after open.  For that I'd want to identify if my Custom Table already exists so I don't keep pasting over the top of it.

 

I'm extremely new to ilogic so I may not even be on the right track here, but this is what I came up with.

 

 It'll recognize a named custom table if it has one, but if it doesn't have one, it'll error out.  If I run just the portion after the the if statement separately, it works.  I'm guessing it has to do with the declarations, but I'm stumped if this can be fixed?  (I made a few other changes to specify the sheet but that I don't think is the issue).  If I'm way off track, no worries, but I thought I would ask.

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
    Exit Sub
End If

Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument

Dim oSheet As Sheet
oSheet = oDDoc.Sheets(2)

Dim oRevTable As CustomTable
oRevTable = oSheet.CustomTables.Item(1)

If oRevTable.Title = ("REVISION HISTORY - LEGACY") Then
	Exit Sub	
End If


Dim oRevTbl As RevisionTable = oSheet.RevisionTables.Item(1)
Dim oTitle As String = "REVISION HISTORY - LEGACY"
Dim oPos As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(27.0815,27.145)
Dim oRowCount As Integer = oRevTbl.RevisionTableRows.Count
Dim oColCount As Integer = oRevTbl.RevisionTableColumns.Count
Dim oCellCount As Integer = oRowCount * oColCount
Dim oColTitles(oColCount - 1) As String
Dim oColWidths(oColCount - 1) As Double
Dim oRowHeights(oRowCount - 1) As Double
Dim oCellContents(oCellCount-1) As String
Dim oRow, oCol, oCell As Integer

For oRow = 1 To oRowCount
	For oCol = 1 To oColCount
		oCellContents(oCell) = oRevTbl.RevisionTableRows.Item(oRow).Item(oCol).FormattedText
		oCell = oCell+1
		oColTitles(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Title
		oColWidths(oCol - 1) = oRevTbl.RevisionTableColumns.Item(oCol).Width
	Next
	oRowHeights(oRow - 1) = oRevTbl.RevisionTableRows.Item(oRow).Height
Next

Dim oCTable As CustomTable
oCTable = oSheet.CustomTables.Add(oTitle, oPos, oColCount, oRowCount, oColTitles, oCellContents, oColWidths, oRowHeights)