I have an embeded excel chart on my drawing called CLASS 125 Single Disc.xls. I want to switch this chart with another one known as CLASS 150 Single Disc.xls. How do I do this? I am using Autodesk Inventor 2011.
Solved! Go to Solution.
Solved by MjDeck. Go to Solution.
Is it Embedded or is it Linked? You can change the source of a Linked Excel file, but I don't know if it's possible with an Embedded.
To change the source of a linked Excel file, you can use the GoExcel.ChangeSourceOfLinked function. This is described in the iLogic help, which is available online (for Inventor 2011) at:
http://wikihelp.autodesk.com/Inventor/enu/2011/Help/User's_Guide/106iLogic/1587Functions
Look under:
Excel Data Links Functions -> GoExcel.ChangeSourceOfLinked
If the Excel file is in the same directory as the part or assembly, you can specify the replacement filename by itself (for example CLASS 150 Single Disc.xls) without including a directory name.
I read the link that you provided but I am still getting the same error whenever I do the code. I don't get what I'm suppose to put for the partialOldName in code
changeOK = GoExcel.ChangeSourceOfLinked(partialOldName, newName)
I am providing a picture.
Sorry, I missed the fact that you're working with a chart in a drawing. The iLogic function will only work with Excel files linked to parameters in parts or assemblies.
You can do this in a drawing using the API in a rule. Here's a sample rule:
Dim excelFileName As String = ThisDoc.Path
If ChartSource = "A" Then
excelFileName = excelFileName & "\ExcelChartA.xls"
Else
excelFileName = excelFileName & "\ExcelChartB.xls"
End If
Dim doc as Document = ThisDoc.Document
Dim oleDesc As ReferencedOLEFileDescriptor
For Each oleDesc In doc.ReferencedOLEFileDescriptors
If (oleDesc.OLEDocumentType <> OLEDocumentTypeEnum.kOLEDocumentLinkObject) Then Continue For
If (Not oleDesc.FullFileName.Contains(".xls") ) Then Continue For
oleDesc.FileDescriptor.ReplaceReference(excelFileName)
Next
Here ChartSource is a parameter in the drawing. You could use different logic to drive the rule.
If you have more than one Excel or other OLE link in your drawing, you might have to add other logic to make sure that you replace only the one reference that you're looking for.
I also need to know the code to change the title of the charts. The picture says "ASME CLASS 125 (Iron Body Only)" as the title.
Here's a new version that can change the title. This is better because it accesses the Excel link through the table itself, instead of looking at all the possible links in the drawing. This could still have trouble if you have more than one Excel chart in the drawing (from your screenshot it looks like you only have one). If you had more, you could add more tests to this code to narrow it down.
Dim excelFileName As String = ThisDoc.Path
Dim title As String
If ChartSource = "A" Then
excelFileName = excelFileName & "\ExcelChartA.xls"
title = "ASME CLASS 125 (Iron Body Only)"
Else
excelFileName = excelFileName & "\ExcelChartB.xls"
title = "ASME CLASS 150"
End If
Dim doc as Document = ThisDoc.Document
For Each dSheet As Sheet In doc.Sheets
For Each table As CustomTable In dSheet.CustomTables
If (table.TableSource <> TableSourceTypeEnum.kExcelTableSource) Then Continue For
Dim fileDesc As FileDescriptor = TryCast(table.ReferencedDocumentDescriptor, FileDescriptor)
If (fileDesc Is Nothing) Then Continue For
fileDesc.ReplaceReference(excelFileName)
table.Title = title
Next
Next
I did use the code that you have given me. However, it is very slow when it comes to switching out the charts. It takes about 30 seconds to do so. I have to switch the charts out a lot because I use different size classes and I also have to make many different pdf files. I was wonder if there was a way to change the code in order to make switching out the charts faster or if you could toggle the visibility of the charts or suppress them. Thank-you.
Is it faster when you switch it manually? You can do it by right-clicking on the table and choosing the Select Other... command in the menu.
If it's not much faster when you manually select a different Excel file, then there's not much we can do in iLogic to speed it up.
Hi!
And if my linking parameters come from a ipt, anybody have a code to replace de link???
Thanks for your helps 🙂
BECAUSE MY HORRIBLE ENGLISH I PUT A IMAGE OF THE LINKNG PARAMETERS WHO I WANT TO REPLACE THE LINK WITH ILOGIC