<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Change current iLogic searching for Excel file in Inventor Programming Forum</title>
    <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039992#M22249</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7549423"&gt;@BK-MTFNE&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give this a try.&amp;nbsp; &amp;nbsp; &amp;nbsp; ( edited on 6.20 to include header Imports line)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A href="http://inventortrenches.blogspot.com" target="_blank" rel="noopener"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Imports System.IO

sTargetFileName = "Project Information.xlsx"
sPath = IO.Path.GetDirectoryName(ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName)

Dim oAllXecelFiles As IEnumerable(Of String) = Directory.EnumerateFiles(sPath, "*.xlsx?", SearchOption.AllDirectories)

'get the first excel file that matches the target file namae
Dim oTargetExcelFile As String = oAllXecelFiles.FirstOrDefault(Function(f) f.IndexOf(sTargetFileName, StringComparison.OrdinalIgnoreCase) &amp;lt;&amp;gt; -1)

iProperties.Value("Custom", "PROJECT NUMBER") = GoExcel.CellValue(oTargetExcelFile, "Sheet1", "C8")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Jun 2023 13:06:06 GMT</pubDate>
    <dc:creator>Curtis_W</dc:creator>
    <dc:date>2023-06-20T13:06:06Z</dc:date>
    <item>
      <title>Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039591#M22246</link>
      <description>&lt;P&gt;I currently have an iLogic that searches for an Excel file and pulls information from it to place in custom properties. This iLogic was created when we used a seperate .ipj file for every project so it would search for that specific .ipj and find the associated Excel file. Now we have one .ipj for multiple projects and the excel file is in each project folder (basically we have main project folders in the same directory as the overall .ipj file). I am trying to change the search part of this iLogic to search the current folder and keep searching in subsequent parent folders until the excel file is found.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Dim IPJ As String
Dim IPJ_Name As String
Dim IPJ_Path As String
Dim FNamePos As Long
'set a reference to the FileLocations object.
IPJ = ThisApplication.FileLocations.FileLocationsFile
'get the location of the last backslash seperator
FNamePos = InStrRev(IPJ, "\", -1)    
'get the project file name with the file extension
IPJ_Name = Right(IPJ, Len(IPJ) - FNamePos)
'get the project name (without extension)
IPJ_ShortName = Left(IPJ_Name, Len(IPJ_Name) - 4)

iProperties.Value("Project", "Project") = IPJ_ShortName
iProperties.Value("Custom", "PROJECT NUMBER") = GoExcel.CellValue("Project Information.xlsx", "Sheet1", "C8")&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:26:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039591#M22246</guid>
      <dc:creator>BK-MTFNE</dc:creator>
      <dc:date>2023-06-16T17:26:23Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039629#M22247</link>
      <description>&lt;P&gt;What version of Inventor are you using?&amp;nbsp; I do not recognize that "ThisApplication.FileLocations.FileLocationsFile" reference you are using.&amp;nbsp; When I paste that into an iLogic rule, it has no Intellisense information for it, but it does return the full file name of my current project file.&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp; This is what we normally use now:&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;IPJ = ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:56:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039629#M22247</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-06-16T17:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039639#M22248</link>
      <description>&lt;P&gt;I'm using inventor 2023, the iLogic was written in Inventor 2021. Honestly I am working on learning to write iLogics better so this was kind of piecmealed from other iLogics.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 17:59:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039639#M22248</guid>
      <dc:creator>BK-MTFNE</dc:creator>
      <dc:date>2023-06-16T17:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039992#M22249</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7549423"&gt;@BK-MTFNE&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give this a try.&amp;nbsp; &amp;nbsp; &amp;nbsp; ( edited on 6.20 to include header Imports line)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A href="http://inventortrenches.blogspot.com" target="_blank" rel="noopener"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="general"&gt;Imports System.IO

sTargetFileName = "Project Information.xlsx"
sPath = IO.Path.GetDirectoryName(ThisApplication.DesignProjectManager.ActiveDesignProject.FullFileName)

Dim oAllXecelFiles As IEnumerable(Of String) = Directory.EnumerateFiles(sPath, "*.xlsx?", SearchOption.AllDirectories)

'get the first excel file that matches the target file namae
Dim oTargetExcelFile As String = oAllXecelFiles.FirstOrDefault(Function(f) f.IndexOf(sTargetFileName, StringComparison.OrdinalIgnoreCase) &amp;lt;&amp;gt; -1)

iProperties.Value("Custom", "PROJECT NUMBER") = GoExcel.CellValue(oTargetExcelFile, "Sheet1", "C8")&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 13:06:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12039992#M22249</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2023-06-20T13:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12040019#M22250</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;I do not recognize that "ThisApplication.FileLocations.FileLocationsFile" reference you are using.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I recognize that code&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grimacing_face:"&gt;😬&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://inventortrenches.blogspot.com/2012/07/ilogic-and-inventor-project-file.html" target="_blank" rel="noopener"&gt;http://inventortrenches.blogspot.com/2012/07/ilogic-and-inventor-project-file.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was definitely just trying to figure things out back then in 2012, and often doing things the hard way&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt;&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Not sure why I used that line to get the project file... I probably found an old Inventor API post on here and just used what I found... there were almost no iLogic examples online back then, and the API posts were often pretty cryptic.&amp;nbsp;&lt;SPAN&gt;This forum has come along way in the last decade or so!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Fri, 16 Jun 2023 21:43:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12040019#M22250</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2023-06-16T21:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046406#M22251</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/105031"&gt;@Curtis_W&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are the errors I get when I put this in as a rule...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="BKMTFNE_0-1687259142076.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1230093i148D8B8D73F1321A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BKMTFNE_0-1687259142076.png" alt="BKMTFNE_0-1687259142076.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the directory is not declared often when doing iLogic&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 11:06:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046406#M22251</guid>
      <dc:creator>BK-MTFNE</dc:creator>
      <dc:date>2023-06-20T11:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046444#M22252</link>
      <description>&lt;P&gt;If you have not included "Imports System.IO" in the 'Header' of the rule, it will want you to include "System.IO" before both Directory and SeachOption. (System.IO.Directory.EnumerateFiles()) &amp;amp; (System.IO.SearchOption.AllDirectories)&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 11:22:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046444#M22252</guid>
      <dc:creator>WCrihfield</dc:creator>
      <dc:date>2023-06-20T11:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046702#M22253</link>
      <description>&lt;P&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7549423"&gt;@BK-MTFNE&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;oops! I forgot to include the header line in my example. ( I'll update my example above in case it helps someone in the future).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Give this update a try, and post back if it is not doing what you expect.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A href="http://inventortrenches.blogspot.com" target="_blank" rel="noopener"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As&amp;nbsp;WCrihfield&amp;nbsp;mentioned you can edit the code and add an &lt;FONT color="#0000FF"&gt;&lt;STRONG&gt;&lt;A href="https://learn.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/imports-statement-net-namespace-and-type" target="_blank" rel="noopener"&gt;&lt;FONT face="arial black,avant garde"&gt;Imports&lt;/FONT&gt;&lt;/A&gt; &lt;/STRONG&gt;&lt;/FONT&gt;line to line 1 as shown:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Curtis_Waguespack_0-1687266003417.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1230140iC4BD48356992EE82/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Curtis_Waguespack_0-1687266003417.png" alt="Curtis_Waguespack_0-1687266003417.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and/or you can add &lt;STRONG&gt;&lt;FONT face="arial black,avant garde"&gt;&lt;A href="https://learn.microsoft.com/en-us/dotnet/api/system.io?view=net-7.0" target="_blank" rel="noopener"&gt;Sytem.IO&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt; in two places in line 4:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Curtis_Waguespack_1-1687266053457.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1230141iEEDECCA487ECDAC5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Curtis_Waguespack_1-1687266053457.png" alt="Curtis_Waguespack_1-1687266053457.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this helps.&lt;BR /&gt;Best of luck to you in all of your Inventor pursuits,&lt;BR /&gt;Curtis&lt;BR /&gt;&lt;A href="http://inventortrenches.blogspot.com" target="_blank" rel="noopener"&gt;http://inventortrenches.blogspot.com&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 13:17:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046702#M22253</guid>
      <dc:creator>Curtis_W</dc:creator>
      <dc:date>2023-06-20T13:17:04Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046710#M22254</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/105031"&gt;@Curtis_W&lt;/a&gt;&amp;nbsp;for the code and thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/7812054"&gt;@WCrihfield&lt;/a&gt;&amp;nbsp;for helping with that little correction to make it work right&lt;/P&gt;</description>
      <pubDate>Tue, 20 Jun 2023 13:04:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12046710#M22254</guid>
      <dc:creator>BK-MTFNE</dc:creator>
      <dc:date>2023-06-20T13:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Change current iLogic searching for Excel file</title>
      <link>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12125571#M22255</link>
      <description>&lt;P&gt;So I thought this was good to go but now that its been implimented I see that its searching through directories in the "wrong" direction. Ill do my best to show our folder structure here to help better understand&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Master Folder (holds every project folder and the main .ipj file)&lt;UL&gt;&lt;LI&gt;Project 1 folder&lt;UL&gt;&lt;LI&gt;Project Information Excel file (there is an excel file in each project folder)&lt;/LI&gt;&lt;LI&gt;Assembly folder 1&lt;UL&gt;&lt;LI&gt;all inventor items for assembly 1 (these need to reference the excel file in the main project folder)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Assembly folder 2&lt;UL&gt;&lt;LI&gt;all inventor items for assembly 2 (these need to reference the excel file in the main project folder)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;there may be some inventor files that are in this folder as well that need to reference the same excel file.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Project 2 folder&lt;UL&gt;&lt;LI&gt;Project Information Excel file (there is an excel file in each project folder)&lt;/LI&gt;&lt;LI&gt;Assembly folder 1&lt;UL&gt;&lt;LI&gt;all inventor items for assembly 1 (these need to reference the excel file in the main project folder)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Assembly folder 2&lt;UL&gt;&lt;LI&gt;all inventor items for assembly 2 (these need to reference the excel file in the main project folder)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;there may be some inventor files that are in this folder as well that need to reference the same excel file.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Project 3 folder&lt;UL&gt;&lt;LI&gt;Project Information Excel file (there is an excel file in each project folder)&lt;/LI&gt;&lt;LI&gt;Assembly folder 1&lt;UL&gt;&lt;LI&gt;all inventor items for assembly 1 (these need to reference the excel file in the main project folder)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Assembly folder 2&lt;UL&gt;&lt;LI&gt;all inventor items for assembly 2 (these need to reference the excel file in the main project folder)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;there may be some inventor files that are in this folder as well that need to reference the same excel file.&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;.ipj file&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently the iLogic above is searching in the "Master Folder" starting with the first project it finds and using that excel sheet where it actually needs to start in the current assembly folder its in and work backwards from there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically the file with the iLogic in it is like a child looking for candy (excel sheet), it first ask its parents (folder file is saved in) if they have candy. They dont have it so then it goes to the grand parents (folder that contains the folder that the child is saved in). it keeps going until someone gives it the candy (excel file) its looking for. sorry for the weird analogy but it was the best way i could think to word it&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2023 16:48:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/inventor-programming-forum/change-current-ilogic-searching-for-excel-file/m-p/12125571#M22255</guid>
      <dc:creator>BK-MTFNE</dc:creator>
      <dc:date>2023-07-25T16:48:38Z</dc:date>
    </item>
  </channel>
</rss>

