• Industries
  • Products
  • Buy
  • Services & Support
  • Communities
  • Discussion Groups

    Autodesk Inventor Customization

    Reply
    Active Contributor
    Posts: 35
    Registered: ‎03-25-2010
    Accepted Solution

    (iLogic) Change excel chart loction

    1218 Views, 9 Replies
    11-29-2010 02:02 PM

    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.

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: (iLogic) Change excel chart loction

    11-30-2010 09:12 AM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Active Contributor
    Posts: 35
    Registered: ‎03-25-2010

    Re: (iLogic) Change excel chart loction

    11-30-2010 11:46 AM 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.

     

     

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: (iLogic) Change excel chart loction

    11-30-2010 01:32 PM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Active Contributor
    Posts: 35
    Registered: ‎03-25-2010

    Re: (iLogic) Change excel chart loction

    11-30-2010 04:14 PM 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.

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: (iLogic) Change excel chart loction

    11-30-2010 04:56 PM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Active Contributor
    Posts: 35
    Registered: ‎03-25-2010

    Re: (iLogic) Change excel chart loction

    12-17-2010 12:32 PM 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.

    Please use plain text.
    Employee
    Posts: 932
    Registered: ‎02-24-2009

    Re: (iLogic) Change excel chart loction

    12-17-2010 02:35 PM 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
    DLS - Mechanical Design
    Autodesk, Inc.

    Please use plain text.
    Valued Contributor
    Posts: 82
    Registered: ‎04-30-2012

    Re: (iLogic) Change excel chart loction

    04-09-2013 05:15 AM in reply to: whiteskulleton

    Hi!

     

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

     

    Thanks for your helps :smileyhappy:

    Please use plain text.
    Valued Contributor
    Posts: 82
    Registered: ‎04-30-2012

    Re: (iLogic) Change excel chart loction

    04-09-2013 05:46 AM in reply to: sergelachance

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

     

    PARAMETER LINK.JPG

    Please use plain text.