Excel to Inventor 2017

Excel to Inventor 2017

Anonymous
Not applicable
556 Views
3 Replies
Message 1 of 4

Excel to Inventor 2017

Anonymous
Not applicable

I would like to have Inventor read my excel spreadsheet and add custom iproperties automatically. I have this code that worked a few years ago however I am having issues with it now. My spreadsheet A1 = SearchField & A2 = 1000. I would like inventor to look at the entire row 1 and if it sees a text value to create the proper custom iproperties with the values that are in row 2. My ultimate goal would be to have a inventor dwg file (not idw) and have the title block automatically fill in based on my excel file. Any help will be greatly appreciated and I thank you in advance.

 

 

Public Sub ExcelToIdw()
Dim xlCon As New ADODB.Connection, xlRs As New ADODB.Recordset
Dim strSearchField As String
Dim xlProp(1 To 11) As String
Dim ivApp As Inventor.Application, ivDoc As Document, ivPropSet As PropertySet
Dim idwProp(1 To 11) As Property
Dim i As Integer

xlCon.Open ("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\ilogic test.xls;Extended Properties=Excel 8.0;")
xlRs.Open "Select * From [xtoidw$]", xlCon, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic, &H1
strSearchField = "SearchField = 1000"
xlRs.Find (strSearchField)


For i = 1 To 11
If i = 1 Then
    xlProp(1) = xlRs("SearchField").Value
    GoTo Skip
End If
 
 If IsNull(xlRs("Field " & i)) Then
 xlProp(i) = ""
 GoTo Skip
 End If
 
 xlProp(i) = xlRs("Field " & i).Value
Skip:
Next i


xlRs.Close
xlCon.Close

Set ivApp = ThisApplication
Set ivDoc = ivApp.ActiveDocument
Set ivPropSet = ivDoc.PropertySets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")

For i = 1 To 11
    Set idwProp(i) = ivPropSet.Item("Field " & i)
    idwProp(i).Value = xlProp(i)
Next i
ivDoc.Update
MsgBox "Drawing Updated", vbInformation, "Program Complete"

End Sub

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

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

"I have this code that worked a few years ago however I am having issues with it now. "

Not specific enough 😉

 

There are issues with Microsoft.Jet.OLEDB.4.0 concerning 32 bit vs 64 bit OS and Office version.

http://modthemachine.typepad.com/my_weblog/2013/09/using-ms-access-databases-with-inventor-2014-vba....

 

If it's only Excel files you need to interact with you might also be able to use the Excel API instead.

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 4

Anonymous
Not applicable

Adam,

 

Thank you very much for your reply, the web link you provided was very informative. I will continue to investigate the situation and see how I can get this to work. I was wondering if the code can be written to work with illogic (Inventor 2017).

 

Best Regards,

Andrew

0 Likes
Message 4 of 4

adam.nagy
Autodesk Support
Autodesk Support

Hi,

 

iLogic is using .NET, so in general whatever is available in .NET could be used from an iLogic Rule as well.

 

Cheers,

 



Adam Nagy
Autodesk Platform Services
0 Likes