Create new TableStyle definition

Create new TableStyle definition

dave_deane
Advocate Advocate
1,455 Views
9 Replies
Message 1 of 10

Create new TableStyle definition

dave_deane
Advocate
Advocate

I am having difficulty trying to figure out how to create a new Table Style definition.

I don't want to create a table on a sheet, I want to define a new style and then assign the style to the existing table.

 

I have no problem assigning the style once it is defined in the drawing to the existing table.

 

Dim oTableStyle As Inventor.TableStyle
        oTableStyle = oDrawingDoc.StylesManager.TableStyles("BOM")


        Dim oTable As Inventor.CustomTable
        oTable = oSheet.CustomTables.Item(1)
        oTable.Style = oTableStyle

 

There doesn't seem to be a TableStyles collection with an add or create event. I stumbled upon the "TableFormat" object but that seems to only override an existing style.

 

looked at the "StylesManager" but again I am not finding a create method.

 

Any help would be appreciated. I have searched the DevBlogs and the discussion groups but have come up empty.

 

Dave

0 Likes
Accepted solutions (1)
1,456 Views
9 Replies
Replies (9)
Message 2 of 10

YuhanZhang
Autodesk
Autodesk

The TableStyle.Copy can create a duplicate style, and then you can change the new created style properties with new values.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 3 of 10

dave_deane
Advocate
Advocate

I was able create a copy of a style definition to add a new style definition but how do I get to the individual columns to format the width?

 

The ".ColumnWidth" property of TableStyle modifies all the columns. That is the one found in the "default units formatting" tab within the Inventor style and standard editor for tables. I need to get to the properties located on the "default column settings" tab for the individual columns.

 

Maybe it is not even possible, Is there access to this within the API at this point in time?

 

 

 

Dim oTableStyle As Inventor.TableStyle
        oTableStyle = oDrawingDoc.StylesManager.TableStyles("Table (ANSI)")
        oTableStyle.Copy("New Style Name Here")
        oTableStyle = oDrawingDoc.StylesManager.TableStyles("New Style Name Here")

        oTableStyle.ColumnWidth = 15

 Thanks,

Dave

0 Likes
Message 4 of 10

YuhanZhang
Autodesk
Autodesk

You can use TableStyle.AddColumn to specify a column settings like in UI the "Default Column Settings" tab.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 5 of 10

dave_deane
Advocate
Advocate

Rocky,

I am able to create the column and format the width with TableStyle.AddColumn but after I update the table on the sheet to the newly formatted style the column headers are not updating.

 

This is caused by the default "Name from Source" check mark in the Default column Settings tab.

Is there a way to uncheck the "Name from Source" after the column is created through the API? Please see screen shot of the style immediately after being created.

 

I varified this to be true by not assigning the table to the new style. Then, physically unchecking the fields and then updating the style. The table then updated as expected to the new style.

 

Thanks,

Dave

0 Likes
Message 6 of 10

YuhanZhang
Autodesk
Autodesk

Unfortunately no API for the Name from Source option exposed yet, but you can change the column title by CustomTable.Columns(Index).Title.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 7 of 10

dave_deane
Advocate
Advocate

Thank you for your feedback Rocky.

 

One more question regarding tables. When you use the "CustomTables.AddCSVTable" the table is still connected to the file. Is it possible to break the link to a source file after the table has been created?

 

In our situation the CSV file is used to populate the table and is deleted afterwards. Once the file is missing the option to edit the table is greyed out. Resulting in the end user to generate a new CSV table from our MRP system to update the table.

 

screen shot attached.

 

Thanks again,

Dave

0 Likes
Message 8 of 10

YuhanZhang
Autodesk
Autodesk

How about if you call ReferencedOLEFileDescriptors(1).Delete to delete the csv reference(or just delete it from UI 3rd Parties folder) so then when you open the document again it won't solve the file link and the table should be still editable.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes
Message 9 of 10

dave_deane
Advocate
Advocate
Accepted solution

Rocky,

Even after the link was deleted from the 3rd party folder the table was unable to be edited. Therefore, I had to abandon the CustomTables.AddCSVTable method and work with a CSV file via StreamReader.

 

So for anyone reading this if you want to create a table from another source (text file) that can be manually edited without maintaing a link to the original file, you will need to create a table with the CustomTable.Add method. I used a CSV and parsed it into a dimensional array that was used to fill oContents as shown in the help examples.

 

Dave

0 Likes
Message 10 of 10

YuhanZhang
Autodesk
Autodesk

Yeah, I see the same result if you delete the csv file from disk, and then remove it from 3rd Party folder, then you could not edit the table anyway. But another workflow seems to have different result, i.e. after you create a table linked to a csv file, remove the link from 3rd Party folder first and then delete the csv file from disk, now save your drawing document and reopen it you should be able to edit the table. Hope this eases your work.

 

To parse the csv file and create a table with the data in it should be also a workaround.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

0 Likes