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: 

Generate parts using excel

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
J.VandeMerckt
433 Views, 5 Replies

Generate parts using excel

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

5 REPLIES 5
Message 2 of 6
jeffrey4283
in reply to: J.VandeMerckt

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

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

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
Message 5 of 6

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

Message 6 of 6

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.

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

Post to forums  

Autodesk Design & Make Report