- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Running AutoDESK VB and getting an error
I found a snippet of code on the Knowledge.AutoDESK.com web site. I cut and pasted it into my VB editor and it produces the table as perscribed, but I get the a "string conversion" error. Anyone know why? It seems to be hanging up on line 13. I have posted a screen shot of the error and line of code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The link to the code was above in "web site", but if that's not working, here it is:
Public Sub CreateCustomTable()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the active sheet. Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
' Set the column titles
Dim oTitles(1 To 3) As String
oTitles(1) = "Part Number"
oTitles(2) = "Quantity"
oTitles(3) = "Material"
' Set the contents of the custom table (contents are set row-wise) Dim oContents(1 To 9) As String
oContents(1) = "1"
oContents(2) = "1"
oContents(3) = "Brass"
oContents(4) = "2"
oContents(5) = "2"
oContents(6) = "Aluminium"
oContents(7) = "3"
oContents(8) = "1"
oContents(9) = "Steel"
' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(1 To 3) As Double
oColumnWidths(1) = 2.5
oColumnWidths(2) = 2.5
oColumnWidths(3) = 4
' Create the custom table Dim oCustomTable As CustomTable
Set oCustomTable = oSheet.CustomTables.Add("My Table", ThisApplication.TransientGeometry.CreatePoint2d(15, 15), _
3, 3, oTitles, oContents, oColumnWidths)
' Change the 3rd column to be left justified.
oCustomTable.Columns.Item(3).ValueHorizontalJustification = kAlignTextLeft
' Create a table format object Dim oFormat As TableFormat
Set oFormat = oSheet.CustomTables.CreateTableFormat
' Set inside line color to red.
oFormat.InsideLineColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
' Set outside line weight. oFormat.OutsideLineWeight = 0.1
' Modify the table formats
oCustomTable.OverrideFormat = oFormat
End Sub
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I don't see the link between the picture and the code you send.
but...
Cstr(Manifold_QTY) = Man_QTY looks not correct.
Cstr = convert to string....
so you try te convert the variable and try to set it with Man_QTY.
is Manifold_QTY a string or an integer?
try
Dim Manifold_QTY as string
then
Manifold_QTY = Cstr(Man_QTY)
if Man_QTY is an integer
if this does not help, send the right code..
Kudo's are also appreciated
Succes on your project, and have a nice day
Herm Jan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Okay, this is embarrassing...after going through the code, I couldn't find variables you were talking about. Turns out, the confusion was because I posted the wrong screen shot. This is what the screen shot should have been. (see attached) I apologize for the confusion.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
The following code works for me:
Public Sub CreateCustomTable()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument
' Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet
' Set the column titles
Dim oTitles(1 To 3) As String
oTitles(1) = "Part Number"
oTitles(2) = "Quantity"
oTitles(3) = "Material"
' Set the contents of the custom table (contents are set row-wise)
Dim oContents(1 To 9) As String
oContents(1) = "1"
oContents(2) = "1"
oContents(3) = "Brass"
oContents(4) = "2"
oContents(5) = "2"
oContents(6) = "Aluminium"
oContents(7) = "3"
oContents(8) = "1"
oContents(9) = "Steel"
' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(1 To 3) As Double
oColumnWidths(1) = 2.5
oColumnWidths(2) = 2.5
oColumnWidths(3) = 4
' Create the custom table
Dim oCustomTable As CustomTable
Set oCustomTable = oSheet.CustomTables.Add("My Table", ThisApplication.TransientGeometry.CreatePoint2d(15, 15), _
3, 3, oTitles, oContents, oColumnWidths)
' Change the 3rd column to be left justified.
oCustomTable.Columns.Item(3).ValueHorizontalJustification = kAlignTextLeft
' Create a table format object
Dim oFormat As TableFormat
Set oFormat = oSheet.CustomTables.CreateTableFormat
' Set inside line color to red.
oFormat.InsideLineColor = ThisApplication.TransientObjects.CreateColor(255, 0, 0)
' Set outside line weight.
oFormat.OutsideLineWeight = 0.1
' Modify the table formats
oCustomTable.OverrideFormat = oFormat
End Sub
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
So, Unless I am missing something...you didn't change the code, but when I run it, as you can see in the screen cast (see hyperlink), I get a run-time error. It creates the table, but I get an error. It only occurs when I run that macro. The other macro I can run, "Tag Labeler", in my iLogic form does not give me issues. I also have have attached an image of the "error explanation".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
for me it works perfect.
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !