Running AutoDESK VB and getting an error

Running AutoDESK VB and getting an error

RNDinov8r
Collaborator Collaborator
811 Views
7 Replies
Message 1 of 8

Running AutoDESK VB and getting an error

RNDinov8r
Collaborator
Collaborator

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.

0 Likes
812 Views
7 Replies
Replies (7)
Message 2 of 8

bradeneuropeArthur
Mentor
Mentor
Could you upload the code. I am missing something I think, but not sure.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


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:
My 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 !


 


EESignature

0 Likes
Message 3 of 8

RNDinov8r
Collaborator
Collaborator

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
0 Likes
Message 4 of 8

HermJan.Otterman
Advisor
Advisor

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..

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 5 of 8

RNDinov8r
Collaborator
Collaborator

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.

0 Likes
Message 6 of 8

bradeneuropeArthur
Mentor
Mentor

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 & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


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:
My 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 !


 


EESignature

0 Likes
Message 7 of 8

RNDinov8r
Collaborator
Collaborator

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".

0 Likes
Message 8 of 8

bradeneuropeArthur
Mentor
Mentor

for me it works perfect.

 

table.PNG

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


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:
My 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 !


 


EESignature

0 Likes