Create Ilogic code that auto created table of contents

Create Ilogic code that auto created table of contents

BrandonLee_Innovex
Contributor Contributor
440 Views
3 Replies
Message 1 of 4

Create Ilogic code that auto created table of contents

BrandonLee_Innovex
Contributor
Contributor

I am trying to find a code that can create a table of contents that looks the image attached, 

But not including the :1 at the end.

 

Is there anything?

0 Likes
441 Views
3 Replies
Replies (3)
Message 2 of 4

WCrihfield
Mentor
Mentor

Hi @BrandonLee_Innovex.  Here is an example iLogic rule you can try out, and alter as needed.

 

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 oASheet As Inventor.Sheet = oSheets.Item(1)
Dim oData As New List(Of String)
For Each oSheet As Inventor.Sheet In oSheets
	oData.Add(oSheet.Name.Split(":").Last)
	oData.Add(oSheet.Name.Split(":").First)
Next
Dim sTitle As String = "TABLE OF CONTENTS"
Dim Pt2d As Inventor.Point2d = ThisApplication.TransientGeometry.CreatePoint2d(0, 0)
Dim iCols As Integer = 2
Dim iRows As Integer = oSheets.Count
Dim oColTitles() As String = {"SHEET", "CONTENTS" }
Dim oContents() As String = oData.ToArray
Dim oCTable As Inventor.CustomTable
oCTable = oASheet.CustomTables.Add(sTitle, Pt2d, iCols, iRows, oColTitles, oContents)
oCTable.HeadingPlacement = HeadingPlacementEnum.kHeadingAtTop
oCTable.ShowTitle = True
oCTable.TableDirection = TableDirectionEnum.kTopDownDirection

 

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

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 4

BrandonLee_Innovex
Contributor
Contributor

That is great, is there a way to have it update once created, instead of creating a new one every time? 

0 Likes
Message 4 of 4

WCrihfield
Mentor
Mentor

I do not think there is a way to fully automate that.  There needs to be an Event available to us within Inventor's API for when you add or remove a sheet from a drawing, and a pre-defined routine code for us to be able to use that event, so that we could create our own code to monitor for that specific event, then react to it.  Right now the only regular events related to drawings that we have that for is when we retrieve dimensions from the model into our drawing, and when a drawing view gets updated due to model changes.  If it is possible, it would likely take a pretty advanced solution in the form off an Inventor ApplicationAddIn to make it happen.

The alternative would be a version of code that when you manually run it again after adding sheets, and it would try to find the same CustomTable, and change its size and its contents.  But that too would take a much larger and more complex code.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes