Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

(iLogic) Change excel chart loction

9 REPLIES 9
SOLVED
Reply
Message 1 of 10
whiteskulleton
2473 Views, 9 Replies

(iLogic) Change excel chart loction

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.

9 REPLIES 9
Message 2 of 10
MjDeck
in reply to: whiteskulleton

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.

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 3 of 10
whiteskulleton
in reply to: MjDeck

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.

 

 

Message 4 of 10
MjDeck
in reply to: whiteskulleton

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.

 


Mike Deck
Software Developer
Autodesk, Inc.

Message 5 of 10
whiteskulleton
in reply to: MjDeck

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.

Message 6 of 10
MjDeck
in reply to: whiteskulleton

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

Mike Deck
Software Developer
Autodesk, Inc.

Message 7 of 10
whiteskulleton
in reply to: MjDeck

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.

Message 8 of 10
MjDeck
in reply to: whiteskulleton

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.


Mike Deck
Software Developer
Autodesk, Inc.

Message 9 of 10

Hi!

 

And if my linking parameters come from a ipt, anybody have a code to replace de link???

 

Thanks for your helps 🙂

Message 10 of 10

BECAUSE MY HORRIBLE ENGLISH I PUT A IMAGE OF THE LINKNG PARAMETERS WHO I WANT TO REPLACE THE LINK WITH ILOGIC

 

PARAMETER LINK.JPG

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report