Microsoft office 2016

Microsoft office 2016

d_stapleton
Contributor Contributor
598 Views
5 Replies
Message 1 of 6

Microsoft office 2016

d_stapleton
Contributor
Contributor

I am working with Inventor 2024 and Office 16.  I'm trying to use I logic to open an Excel .xlsx file and edit it.  I can save the file as an .xlsx but when I try to open it through Inventor, I get this error:  Unable to cast COM object of type

'Microsoft.Office.Interop. Excel.ApplicationClass' to interface type

Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueeryInterface call on the COM component for the interface with IID

'{0000208D5-0000-0000-C000-000000000046}' failed due to the following error:

Element not found. (Exception for HRESULT:0x8002802B

(TYPE_E_ELEMENTNOTFOUND)). 

 

Does anybody have a clue?  I found this code online and I can't make it work.

0 Likes
Accepted solutions (1)
599 Views
5 Replies
Replies (5)
Message 2 of 6

WCrihfield
Mentor
Mentor

Hi @d_stapleton.  The error you are getting is a fairly common one folks encounter when trying to access/use the Excel application object by code from an iLogic rule.  The iLogic 'GoExcel' Interface is very convenient for some stuff, but it usually does not mix very well with code that is also attempting to bypass its limitations by accessing stuff in the Excel API directly.  I generally recommend only using the functionality of the GoExcel tools, if you can, and if they do not meet the need, then avoid using it altogether, in favor of accessing the Excel API directly instead.  The only way I know of to get a 2-D Array of cell values from Excel using the GoExcel tools, is by using the IGoExcel.NamedRangeValue Property.  But to use that, you must have assigned a name to the range within the Excel document.  If the named range just represents 1 cell, you will get a single Object from the NamedRangeValue.  If you know ahead of time that the named range represents a continuous range of cells with multiple columns and rows, then you can declare a 2-D array of Object, without specifying the size of its dimensions, then set its value using that property.  Below is an example line of code like that.

Dim oValues(,) As Object = GoExcel.NamedRangeValue("RangeName")

Then you can use your 2-stage nested loops to step through its contents, similar to what you are already doing.

If going the Excel API route, the usual rule 'Header' lines (if wanted) are as follows:

AddReference "Microsoft.Office.Interop.Excel.dll"
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel

Using those in the header of the rule will add recognition of the Excel API objects to the Intellisense system within the iLogic rule editor window.  Sometimes that works out well for some folks, and sometimes folks prefer to do without them, and just code blind (without any Intellisense support), if they are pretty familiar with the coding conventions required.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 6

d_stapleton
Contributor
Contributor

Wesley,

 

Thanks,

Do you think it would be better just to wright a C# program outside of Inventor and then just have the iLogic call the C# program?

 

Dan Stapleton

0 Likes
Message 4 of 6

WCrihfield
Mentor
Mentor

Hi @d_stapleton.  Are you just trying to copy the exported BOM Excel file contents over into a different Excel file?  If so, then why not just copy the file itself by code instead?  There may be multiple ways to accomplish the outcome you want, but which way is best for you is probably whichever way you are most comfortable with.  I am not familiar enough with C#.net myself, so it is difficult for me to judge, but if you are good with it, you can use that if you want.  It seems like you would have to create something like an add-in or standalone exe to do it with C# though, which seems a little overkill to me.  But I am not currently experienced with creating add-ins or standalone exe's either, so I am honestly not a good judge of that either.  I have done many projects that involve working with Excel from iLogic rules though, both ways (GoExcel or Excel API).

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 5 of 6

d_stapleton
Contributor
Contributor

Wesley,

What I want to do is take the BOM from Inventor and place it in an existing .xlsx file that has the format that is needed.  Hit one button and everything from the Inventor BOM loads into the right spots on my .xlsx file.  If there is an easy way to do that from iLogic that would be great.

 

Thanks

Dan

0 Likes
Message 6 of 6

WCrihfield
Mentor
Mentor
Accepted solution

Hi @d_stapleton.  Unfortunately, there is not an 'easy' way that I know of.  The Inventor API method (https://help.autodesk.com/view/INVNTOR/2024/ENU/?guid=BOMView_Export ) does not offer much different options than the iLogic method (ICadBom.Export Method).  I think most folks just write their own long custom codes to match their specific needs, and the layout of their own BOM templates.  Exporting BOM's has been a popular topic here on this forum over the years, so you could likely find a lot of similar examples with an extensive search within this forum.  I do not do a lot of BOM exports by code, and do not use a 'template' for that task either, so I do not have a good example code prepared for that specific task myself that I could offer.

 

However, if exporting a PartsList from a drawing, which is mostly the same information, there are more options for that task, including specifying a 'template'.  You could look into going that route if you wanted.  The online help documentation link to that method is below.

PartsList.Export 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes