Generate parts using excel

Generate parts using excel

J.VandeMerckt
Advocate Advocate
1,502 Views
5 Replies
Message 1 of 6

Generate parts using excel

J.VandeMerckt
Advocate
Advocate

Hi Everyone

 

I'm looking for a way to generate files using an excel using Ilogic I assume.
It's kinda the same as Iparts but without the links.


To start simple I was thinking about a profile and a variable Length.
The excel would have 2 Columns.
Name & Length

I want to populate the excel with multiple names and its lengths.

The Ilogic is then Imbedded to the "master part file" and looks into the Excel to generate my files.
1. It has to look into the first row and save as "Name"
2. changes the "Length" parameter to the correct value
3. save again or more ideally saves again and leaves the file open.
4. Repeat until there are no more rows.


I was hoping this would be a basic start but can't find anything on the forum.
I did find this link:
Creating simple series of large numbers of parts using excel spreadsheet and parameter list - Autode...
But they decided to use Iparts instead.

In the future I want to adapt the code to be able to change more then 1 parameter but 1 parameter is a very good start.
Can anyone send me in the right direction?

 

Br

Justin

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

jeffrey4283
Participant
Participant

You can use GoExcel  (link to help page) to pull data from a spreadsheet and generate your model from that data.

 

Message 3 of 6

Michael.Navara
Advisor
Advisor
Accepted solution

See the sample in attachment. There is profile generator for L-profiles (Inv 2024)

MichaelNavara_0-1708094256882.png

 

Code sample:

Sub Main()

    Dim part As PartDocument = ThisDoc.Document

    Dim targetDir = IO.Path.GetDirectoryName(part.FullFileName)

    Dim fileName As String = IO.Path.Combine(targetDir,"PartTable.xlsx")
    Dim sheetName As String = "Sheet1"

    GoExcel.Open(fileName, sheetName)

    Dim row As Integer = 2 'Start from second row

    Dim name As String
    Dim length As String
    Dim size As String
    Do
        name = GoExcel.CellValue("A" & row)
        If String.IsNullOrEmpty(name) Then Exit Do

        length = GoExcel.CellValue("B" & row)
        size = GoExcel.CellValue("C" & row)
        
        part.ComponentDefinition.Parameters.Item("Length").Expression = length
        part.ComponentDefinition.Parameters.Item("Size").Expression = size

        part.Update()

        Dim newPartFileName As String = IO.Path.Combine(targetDir, name & ".ipt")
        part.SaveAs(newPartFileName, True)

        row += 1
    Loop

    GoExcel.Close()

End Sub

 

Message 4 of 6

J.VandeMerckt
Advocate
Advocate
Awesome, I'll have a look asap how it works and what it does exactly.
I assume it will also run on 2023.
Thank you
0 Likes
Message 5 of 6

J.VandeMerckt
Advocate
Advocate

Hi @Michael.Navara

 

I was unable to open your file in inventor 2023.
But I recreated your part with the same parameters and paste the code in my rules.

It works. I do see you say it's a code sample.
So is the code you posted here the full code or is it missing some other code?
Just asking to be sure.

Thank you very much for helping me. I will be able to customize this code a lot and make our work much more efficient.

 

Best Regards

Justin

0 Likes
Message 6 of 6

Michael.Navara
Advisor
Advisor

It is just a working sample. That means it works, but a lot of code is omitted for readability and brevity. For example there is no error handling for any case like

  • Excel file is not found
  • Excel file has a different structure, sheet name, etc.
  • Parameters in part must exist
  • Parameter expression must be valid
  • ... and much, much more.

In my opinion this is just about 10% of the final safe and user-friendly code. But it depends on your needs.